private static PDFFlowContent BuildSubscript(PDFAnsiTrueTypeFont font) { PDFAnsiTrueTypeFont fontSubscript = new PDFAnsiTrueTypeFont(font, 18); PDFAnsiTrueTypeFont fontRegular = new PDFAnsiTrueTypeFont(font, 12); PDFFormattedContent content = new PDFFormattedContent(); PDFFlowTextContent flowText = new PDFFlowTextContent(content); flowText.OuterMargins = new PDFFlowContentMargins(0, 0, 36, 0); PDFFormattedTextBlock titleBlock = new PDFFormattedTextBlock("Subscript text", fontRegular); content.Paragraphs.Add(new PDFFormattedParagraph(titleBlock)); content.Paragraphs.Add(new PDFFormattedParagraph(" ")); PDFFormattedTextBlock block1 = new PDFFormattedTextBlock("Y = X", font); block1.Subscript.Add(new PDFFormattedTextBlock("1", fontSubscript)); PDFFormattedTextBlock block2 = new PDFFormattedTextBlock(" + X", font); block2.Subscript.Add(new PDFFormattedTextBlock("2", fontSubscript)); PDFFormattedTextBlock block3 = new PDFFormattedTextBlock(" + X", font); block3.Subscript.Add(new PDFFormattedTextBlock("3", fontSubscript)); PDFFormattedTextBlock blockn = new PDFFormattedTextBlock(" + ... + X", font); blockn.Subscript.Add(new PDFFormattedTextBlock("n", fontSubscript)); PDFFormattedParagraph paragraph = new PDFFormattedParagraph(block1, block2, block3, blockn); paragraph.HorizontalAlign = PDFStringHorizontalAlign.Center; content.Paragraphs.Add(paragraph); return(flowText); }
private static PDFFlowContent BuildSuperscript(PDFAnsiTrueTypeFont font) { PDFAnsiTrueTypeFont fontSuperscript = new PDFAnsiTrueTypeFont(font, 18); PDFAnsiTrueTypeFont fontRegular = new PDFAnsiTrueTypeFont(font, 12); PDFFormattedContent content = new PDFFormattedContent(); PDFFlowTextContent flowText = new PDFFlowTextContent(content); PDFFormattedTextBlock titleBlock = new PDFFormattedTextBlock("Superscript text", fontRegular); content.Paragraphs.Add(new PDFFormattedParagraph(titleBlock)); content.Paragraphs.Add(new PDFFormattedParagraph(" ")); PDFFormattedTextBlock xBlock = new PDFFormattedTextBlock("X", font); xBlock.Superscript.Add(new PDFFormattedTextBlock("2", fontSuperscript)); PDFFormattedTextBlock yBlock = new PDFFormattedTextBlock(" + Y", font); yBlock.Superscript.Add(new PDFFormattedTextBlock("2", fontSuperscript)); PDFFormattedTextBlock zBlock = new PDFFormattedTextBlock(" = Z", font); zBlock.Superscript.Add(new PDFFormattedTextBlock("2", fontSuperscript)); PDFFormattedParagraph paragraph = new PDFFormattedParagraph(xBlock, yBlock, zBlock); paragraph.HorizontalAlign = PDFStringHorizontalAlign.Center; content.Paragraphs.Add(paragraph); return(flowText); }
private static PDFFlowContent BuildEndSection(PDFAnsiTrueTypeFont verdana) { PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(verdana); headerFont.Size = 20; PDFAnsiTrueTypeFont contentFont = new PDFAnsiTrueTypeFont(verdana); contentFont.Size = 12; PDFFormattedContent endInfo = new PDFFormattedContent(); endInfo.Paragraphs.Add(new PDFFormattedTextBlock(" ", headerFont)); endInfo.Paragraphs.Add(new PDFFormattedTextBlock("PAID IN FULL by credit card.", headerFont)); endInfo.Paragraphs.Add(new PDFFormattedTextBlock(" ", headerFont)); PDFFormattedTextBlock text1 = new PDFFormattedTextBlock("If you have any queries regarding this Invoice, please contact ", contentFont); PDFFormattedTextBlock email = new PDFFormattedTextBlock("*****@*****.**", contentFont); PDFFormattedTextBlock text2 = new PDFFormattedTextBlock(" quoting the Invoice Number above.", contentFont); email.TextColor = new PDFBrush(PDFRgbColor.Blue); email.Action = new PDFUriAction("mailto:[email protected]"); endInfo.Paragraphs.Add(text1, email, text2); PDFFlowTextContent endInfoText = new PDFFlowTextContent(endInfo); return(endInfoText); }
private static PDFFlowContent BuildBuyerSection(PDFAnsiTrueTypeFont verdana, PDFAnsiTrueTypeFont verdanaBold) { PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(verdana); headerFont.Size = 20; PDFAnsiTrueTypeFont labelFont = new PDFAnsiTrueTypeFont(verdanaBold); labelFont.Size = 12; PDFAnsiTrueTypeFont contentFont = new PDFAnsiTrueTypeFont(verdana); contentFont.Size = 12; PDFFormattedContent buyerInfo = new PDFFormattedContent(); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock(" ", headerFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock("Invoice to:", headerFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock(" ", headerFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock("Contoso LLC", contentFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock("1000 Summer Road", contentFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock("London", contentFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock("1A2 3B4", contentFont)); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock("United Kingdom", contentFont)); buyerInfo.Paragraphs.Add(" "); PDFFormattedTextBlock labelVAT = new PDFFormattedTextBlock("Your VAT/Tax number: ", labelFont); PDFFormattedTextBlock vat = new PDFFormattedTextBlock("GB1234567890", contentFont); buyerInfo.Paragraphs.Add(labelVAT, vat); buyerInfo.Paragraphs.Add(new PDFFormattedTextBlock(" ", headerFont)); PDFFlowTextContent buyerInfoText = new PDFFlowTextContent(buyerInfo); return(buyerInfoText); }
private static PDFFlowContent BuildSellerSection(PDFAnsiTrueTypeFont verdana, PDFAnsiTrueTypeFont verdanaBold) { PDFAnsiTrueTypeFont labelFont = new PDFAnsiTrueTypeFont(verdanaBold); labelFont.Size = 12; PDFAnsiTrueTypeFont contentFont = new PDFAnsiTrueTypeFont(verdana); contentFont.Size = 12; PDFFormattedContent sellerInfo = new PDFFormattedContent(); sellerInfo.Paragraphs.Add(new PDFFormattedTextBlock("DemoCompany LLC", contentFont)); sellerInfo.Paragraphs.Add(new PDFFormattedTextBlock("3000 Alandala Road", contentFont)); sellerInfo.Paragraphs.Add(new PDFFormattedTextBlock("Beverly Hills", contentFont)); sellerInfo.Paragraphs.Add(new PDFFormattedTextBlock("CA 90210", contentFont)); sellerInfo.Paragraphs.Add(new PDFFormattedTextBlock("United States", contentFont)); sellerInfo.Paragraphs.Add(" "); PDFFormattedTextBlock labelPhone = new PDFFormattedTextBlock("Phone: ", labelFont); PDFFormattedTextBlock phone = new PDFFormattedTextBlock("+1-555-123-4567", contentFont); sellerInfo.Paragraphs.Add(labelPhone, phone); PDFFormattedTextBlock labelFax = new PDFFormattedTextBlock("Fax: ", labelFont); PDFFormattedTextBlock fax = new PDFFormattedTextBlock("+1-555-456-7890", contentFont); sellerInfo.Paragraphs.Add(labelFax, fax); PDFFormattedTextBlock labelEmail = new PDFFormattedTextBlock("Email: ", labelFont); PDFFormattedTextBlock email = new PDFFormattedTextBlock("*****@*****.**", contentFont); email.TextColor = new PDFBrush(PDFRgbColor.Blue); email.Action = new PDFUriAction("mailto:[email protected]"); sellerInfo.Paragraphs.Add(labelEmail, email); PDFFormattedTextBlock labelWeb = new PDFFormattedTextBlock("Web: ", labelFont); PDFFormattedTextBlock web = new PDFFormattedTextBlock("www.o2sol.com", contentFont); web.TextColor = new PDFBrush(PDFRgbColor.Blue); web.Action = new PDFUriAction("http://www.o2sol.com"); sellerInfo.Paragraphs.Add(labelWeb, web); for (int i = 0; i < sellerInfo.Paragraphs.Count; i++) { sellerInfo.Paragraphs[i].HorizontalAlign = PDFStringHorizontalAlign.Right; } PDFFlowTextContent sellerInfoText = new PDFFlowTextContent(sellerInfo); return(sellerInfoText); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PDFStandardFont heading1Font = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 16); PDFStandardFont heading2Font = new PDFStandardFont(heading1Font); heading2Font.Size = 14; PDFStandardFont heading3Font = new PDFStandardFont(heading1Font); heading3Font.Size = 12; PDFFlowDocument doc = new PDFFlowDocument(); // Add an intro page to the document. PDFFormattedContent fc = new PDFFormattedContent("DEMO DOCUMENT\r\nwith automatically generated\r\nTable of Contents"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = new PDFStandardFont(heading1Font); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font.Size = 24; fc.Paragraphs[0].HorizontalAlign = PDFStringHorizontalAlign.Center; PDFFlowTextContent ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); doc.StartNewPage(); // Enable/disable the autonumbering of document headings bool autoNumber = true; // Setup the flow document content. // Heading content objects are used for the generation of table of contents. fc = new PDFFormattedContent("Chapter One"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading1Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; PDFFlowHeadingContent fhc = new PDFFlowHeadingContent(fc); fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); PDFFormattedParagraph fp = new PDFFormattedParagraph(text1); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Section One"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading2Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 2; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text2); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module One"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text3); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Two"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text4); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Section Two"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading2Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 2; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text5); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Three"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text6); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Four"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text7); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Chapter Two"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading1Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text8); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Section Three"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading2Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 2; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text9); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Five"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text10); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Six"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text1); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Section Four"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading2Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 2; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text2); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Seven"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text3); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); fc = new PDFFormattedContent("Module Eight"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = heading3Font; fc.Paragraphs[0].SpacingBefore = fc.Paragraphs[0].SpacingAfter = 12; fhc = new PDFFlowHeadingContent(fc); fhc.Level = 3; fhc.AutoNumber = autoNumber; doc.AddContent(fhc); fc = new PDFFormattedContent(); fp = new PDFFormattedParagraph(text4); fp.HorizontalAlign = PDFStringHorizontalAlign.Justified; fp.FirstLineIndent = 18; fc.Paragraphs.Add(fp); ftc = new PDFFlowTextContent(fc); doc.AddContent(ftc); // Setup the document's table of contents. PDFFlowDocumentTOCSettings tocSettings = new PDFFlowDocumentTOCSettings(); // Generate the table of contents as document outline. tocSettings.GenerateDocumentOutline = true; // Generate the table of contents as a separate page in the document. tocSettings.GenerateContentsPage = true; tocSettings.ContentsTextFont = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10); tocSettings.ContentsTextColor = new PDFBrush(PDFRgbColor.Black); // Insert the TOC page at position 1 (after the first page of the document). tocSettings.ContentsPagePosition = 1; // Visually connect the TOC entries with the page numbers using dots tocSettings.ContentsEntryFiller = '.'; // Create a title for the TOC fc = new PDFFormattedContent("TABLE OF CONTENTS"); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font = new PDFStandardFont(heading1Font); (fc.Paragraphs[0].Blocks[0] as PDFFormattedTextBlock).Font.Size = 24; fc.Paragraphs[0].HorizontalAlign = PDFStringHorizontalAlign.Center; fc.Paragraphs[0].SpacingAfter = 24; tocSettings.ContentsTitle = new PDFFlowTextContent(fc); // Indent the entries in the TOC if (autoNumber) { tocSettings.ContentsHeadingIndent = 10; } doc.GenerateTableOfContents(tocSettings); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(doc, "tableofcontents.pdf") }; return(output); }