本文整理汇总了C#中iTextSharp.text.Document类的典型用法代码示例。如果您正苦于以下问题:C# Document类的具体用法?C# Document怎么用?C# Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于iTextSharp.text命名空间,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunBugSamples
virtual public void RunBugSamples() {
bool success = true;
foreach (String str in list) {
try {
Console.WriteLine(str);
Document doc = new Document();
PdfWriter writer = null;
try {
writer = PdfWriter.GetInstance(doc, new FileStream(TARGET + "/bugs/" + str
+ ".pdf", FileMode.Create));
}
catch (DocumentException e) {
Console.WriteLine(e);
}
doc.Open();
XMLWorkerHelper helper = XMLWorkerHelper.GetInstance();
helper.ParseXHtml(writer, doc, File.OpenText(RESOURCES + "/bugs/" + str));
doc.Close();
}
catch (Exception e) {
Console.WriteLine(e);
Console.WriteLine(e);
success = false;
}
}
if (!success) {
Assert.Fail();
}
}
示例2: OnEndPage
/**
* Adds the header and the footer.
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
*/
public override void OnEndPage(PdfWriter writer, Document document)
{
Rectangle rect = writer.GetBoxSize("art");
switch (writer.PageNumber % 2)
{
case 0:
ColumnText.ShowTextAligned(writer.DirectContent,
Element.ALIGN_RIGHT,
header[0],
rect.Right, rect.Top, 0
);
break;
case 1:
ColumnText.ShowTextAligned(
writer.DirectContent,
Element.ALIGN_LEFT,
header[1],
rect.Left, rect.Top, 0
);
break;
}
ColumnText.ShowTextAligned(
writer.DirectContent,
Element.ALIGN_CENTER,
new Phrase(String.Format("page {0}", pagenumber)),
(rect.Left + rect.Right) / 2,
rect.Bottom - 18, 0
);
}
示例3: TryCreatePdf
public bool TryCreatePdf(string nameBank)
{
try
{
using (FileStream file = new FileStream(String.Format(path,nameBank), FileMode.Create))
{
Document document = new Document(PageSize.A7);
PdfWriter writer = PdfWriter.GetInstance(document, file);
/// Create metadate pdf file
document.AddAuthor("");
document.AddLanguage("pl");
document.AddSubject("Payment transaction");
document.AddTitle("Transaction");
/// Create text in pdf file
document.Open();
document.Add(new Paragraph(_przelew+"\n"));
document.Add(new Paragraph(String.Format("Bank {0}: zaprasza\n",nameBank)));
document.Add(new Paragraph(DateTime.Now.ToString()));
document.Close();
writer.Close();
file.Close();
return true;
}
}
catch (SystemException ex)
{
return false;
}
}
示例4: Print
public void Print(Document document)
{
var table = PDFHelper.CreateTable(document, ReportData.DataTables[0].Columns.Count);
table.HeaderRows = 3;
table.SetWidths(new float[] { 3f, 3f, 4f, 2f });
var cell = PDFHelper.GetCell("Параметры устройств" + Environment.NewLine + "на " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"), PDFStyle.HeaderFont, Element.ALIGN_CENTER, PDFStyle.HeaderBackground);
cell.Colspan = 4;
table.AddCell(cell);
cell = PDFHelper.GetCell("Устройство", PDFStyle.TextFont, Element.ALIGN_CENTER, PDFStyle.HeaderBackground);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Colspan = 2;
table.AddCell(cell);
cell = PDFHelper.GetCell("Зона", PDFStyle.TextFont, Element.ALIGN_CENTER, PDFStyle.HeaderBackground);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Rowspan = 2;
table.AddCell(cell);
cell = PDFHelper.GetCell("Запыленность", PDFStyle.TextFont, Element.ALIGN_CENTER, PDFStyle.HeaderBackground);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Rowspan = 2;
table.AddCell(cell);
cell = PDFHelper.GetCell("Тип", PDFStyle.TextFont, Element.ALIGN_CENTER, PDFStyle.HeaderBackground);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell);
cell = PDFHelper.GetCell("Адрес", PDFStyle.TextFont, Element.ALIGN_CENTER, PDFStyle.HeaderBackground);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell);
PDFHelper.PrintTable(table, ReportData.DataTables[0]);
document.Add(table);
}
示例5: OnChapter
/**
* Initialize one of the headers, based on the chapter title;
* reset the page number.
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onChapter(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document, float,
* com.itextpdf.text.Paragraph)
*/
public override void OnChapter(
PdfWriter writer, Document document,
float paragraphPosition, Paragraph title)
{
header[1] = new Phrase(title.Content);
pagenumber = 1;
}
示例6: PdfCopy
/**
* Constructor
* @param document
* @param os outputstream
*/
public PdfCopy(Document document, Stream os)
: base(new PdfDocument(), os)
{
document.AddDocListener(pdf);
pdf.AddWriter(this);
indirectMap = new Dictionary<PdfReader,Dictionary<RefKey,IndirectReferences>>();
}
示例7: ASPXToPDF
public void ASPXToPDF(HtmlTable objhtml1, HtmlTable objhtml2)
{
string fileName = "AsignacionFolios.pdf";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Clear();
StringWriter sw1 = new StringWriter();
HtmlTextWriter hw1 = new HtmlTextWriter(sw1);
objhtml1.RenderControl(hw1);
StringWriter sw2 = new StringWriter();
HtmlTextWriter hw2 = new HtmlTextWriter(sw2);
objhtml2.RenderControl(hw2);
StringReader sr1 = new StringReader(sw1.ToString());
StringReader sr2 = new StringReader(sw2.ToString());
Document pdfDoc = new Document(PageSize.A2, 5f, 5f, 5f, 5f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr1);
pdfDoc.NewPage();
htmlparser.Parse(sr2);
pdfDoc.Close();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Write(pdfDoc);
HttpContext.Current.Response.End();
}
示例8: MakePdf
protected override void MakePdf(string outPdf) {
Document doc = new Document(PageSize.A4.Rotate());
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create));
doc.SetMargins(45, 45, 0, 100);
doc.Open();
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"main.css")));
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"widget082.css")));
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc =
new HtmlPipelineContext(
new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts")));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
hpc.SetImageProvider(new SampleTestImageProvider());
hpc.SetPageSize(doc.PageSize);
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter));
IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8"));
p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8"));
doc.Close();
}
示例9: Convert
public int Convert(string from, string to)
{
_logger.DebugFormat("Text转换为Pdf, {0},到:{1}", from, to);
try
{
var content = File.ReadAllText(@from, Encoding.Default);
Document document = new Document();
BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf);
PdfWriter.GetInstance(document, new FileStream(@to, FileMode.Create));
document.Open();
document.Add(new Paragraph(content, font));
document.Close();
return ErrorMessages.Success;
}
catch(Exception ex)
{
throw new ConverterException(ErrorMessages.TextToPdfFailed, ex);
}
}
示例10: VerticalPositionTest0
public void VerticalPositionTest0() {
String file = "vertical_position.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
document.Open();
writer.PageEvent = new CustomPageEvent();
PdfPTable table = new PdfPTable(2);
for (int i = 0; i < 100; i++) {
table.AddCell("Hello " + i);
table.AddCell("World " + i);
}
document.Add(table);
document.NewPage();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++) {
sb.Append("some more text ");
}
document.Add(new Paragraph(sb.ToString()));
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例11: Go
public void Go()
{
var outputFile = Helpers.IO.GetClassOutputPath(this);
var parsedHtml = RemoveImage(HTML);
Console.WriteLine(parsedHtml);
using (var xmlSnippet = new StringReader(parsedHtml))
{
using (FileStream stream = new FileStream(
outputFile,
FileMode.Create,
FileAccess.Write))
{
using (var document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(
document, stream
);
document.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(
writer, document, xmlSnippet
);
}
}
}
}
示例12: generatePDFButton_Click
protected void generatePDFButton_Click(object sender, EventArgs e)
{
PdfPTable pdfPTable = new PdfPTable(CreatedStudentInformationGridView.HeaderRow.Cells.Count);
foreach (TableCell headerCell in CreatedStudentInformationGridView.HeaderRow.Cells)
{
PdfPCell pfdPCell = new PdfPCell(new Phrase(headerCell.Text));
//pfdPCell.BackgroundColor = new BaseColor(newCenterGridView.HeaderStyle.ForeColor);
pdfPTable.AddCell(pfdPCell);
}
foreach (GridViewRow gridViewRow in CreatedStudentInformationGridView.Rows)
{
foreach (TableCell tableCell in gridViewRow.Cells)
{
PdfPCell pfdPCell = new PdfPCell(new Phrase(tableCell.Text));
//pfdPCell.BackgroundColor = new BaseColor(newCenterGridView.HeaderStyle.ForeColor);
pdfPTable.AddCell(pfdPCell);
}
}
Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
pdfDocument.Open();
pdfDocument.Add(pdfPTable);
pdfDocument.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=NewCenter.pdf");
Response.Write(pdfDocument);
Response.Flush();
Response.End();
}
示例13: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// Use old example to create PDF
MovieTemplates mt = new MovieTemplates();
byte[] pdf = Utility.PdfBytes(mt);
using (ZipFile zip = new ZipFile())
{
using (MemoryStream ms = new MemoryStream())
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
PdfPTable table = new PdfPTable(2);
PdfReader reader = new PdfReader(pdf);
int n = reader.NumberOfPages;
PdfImportedPage page;
for (int i = 1; i <= n; i++)
{
page = writer.GetImportedPage(reader, i);
table.AddCell(Image.GetInstance(page));
}
document.Add(table);
}
zip.AddEntry(RESULT, ms.ToArray());
}
zip.AddEntry(Utility.ResultFileName(mt.ToString() + ".pdf"), pdf);
zip.Save(stream);
}
}
示例14: GenerateReport
/// <summary>
/// Save a pdf file in "../../test.pdf".
/// </summary>
/// <param name="deals">Expect Collection of objects that have Name, Address, ProductName and formula.</param>
public void GenerateReport(IEnumerable<PdfReportModel> deals)
{
FileStream fileStream = new FileStream(ReportsPath, FileMode.Create, FileAccess.Write, FileShare.None);
Rectangle pageSize = new Rectangle(PageSize.A4);
Document reportDocument = new Document(pageSize);
PdfWriter pdfWriter = PdfWriter.GetInstance(reportDocument, fileStream);
var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 17);
reportDocument.Open();
PdfPTable reportTable = new PdfPTable(6);
reportTable.HorizontalAlignment = Element.ALIGN_LEFT;
PdfPCell headerCell = new PdfPCell(new Phrase("Produced products information", boldFont));
headerCell.Colspan = 6;
headerCell.HorizontalAlignment = 0;
reportTable.AddCell(headerCell);
this.PutHeadCells(reportTable);
foreach (var deal in deals)
{
reportTable.AddCell(deal.ProductName);
reportTable.AddCell(deal.Quantity);
reportTable.AddCell(deal.PricePerUnit);
reportTable.AddCell(deal.Formula);
reportTable.AddCell(deal.Address);
reportTable.AddCell(deal.Total);
}
reportDocument.Add(reportTable);
reportDocument.Close();
}
示例15: GeneratePDFReport
// to generate the report call the GeneratePDFReport static method.
// The pdf file will be generated in the SupermarketChain.ConsoleClient folder
// TODO measures are missing
// TODO code refactoring to limitr repeated chunks
public static void GeneratePDFReport()
{
Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 40, 35);
string filePath = @"..\..\..\..\Reports\salesReports.pdf";
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(5);
Font verdana = FontFactory.GetFont("Verdana", 16, Font.BOLD);
Font verdana2 = FontFactory.GetFont("Verdana", 12, Font.BOLD);
PdfPCell header = new PdfPCell(new Phrase("Aggregated Sales Report", verdana));
header.Colspan = 5;
header.HorizontalAlignment = 1;
table.AddCell(header);
double totalSales = PourReportData(table);
PdfPCell totalSum = new PdfPCell(new Phrase("Grand total:"));
totalSum.Colspan = 4;
totalSum.HorizontalAlignment = 2;
totalSum.BackgroundColor = new BaseColor(161, 212, 224);
table.AddCell(totalSum);
PdfPCell totalSumNumber = new PdfPCell(new Phrase(String.Format("{0:0.00}", totalSales), verdana));
totalSumNumber.BackgroundColor = new BaseColor(161, 212, 224);
table.AddCell(totalSumNumber);
doc.Add(table);
doc.Close();
DirectoryInfo directoryInfo = new DirectoryInfo(filePath);
Console.WriteLine("Pdf report generated.");
Console.WriteLine("File: {0}", directoryInfo.FullName);
}