Quick Start

Brief

The article describes how to quickly create your first PDF document.

Details

To create a new document:

  1. Add the PDFFlow library to your project.

  2. Create a new document builder using the method DocumentBuilder.New.

  3. Add a section or several sections to the document.

  4. Add content to each section:

  5. Create a table of content for the document.

  6. Call the DocumentBuilder.Build(fileName) method or the DocumentBuilder.Build(outputStream) method to generate the document.



See also
For more information, see Creating Document and the other articles.



Examples

Example 1. Create a new PDF document Hide

    Color colorDarkBlue = Color.FromRgba(0, 125.0/255.0, 181.0/255.0);
    Color colorLightBlue = Color.FromRgba(0, 175.0/255.0, 245.0/255.0);
 
    // Create a document builder:
 
    DocumentBuilder builder = DocumentBuilder.New();
 
    // Create a section builder and customize the section:
 
    var sectionBuilder =
        builder
            .AddSection()
                // Customize settings:
                .SetMargins(horizontal: 30, vertical: 10)
                .SetSize(PaperSize.A4)
                .SetOrientation(PageOrientation.Landscape)
                .SetNumerationStyle(NumerationStyle.Arabic);
 
    // Add a TOC item:
 
    sectionBuilder
        .AddParagraph("Adding Paragraph")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Create a paragraph builder to customize a paragraph and add content to it:
 
    sectionBuilder
        .AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. ")
            .SetBackColor(colorLightBlue)
            .SetFirstLineIndent(20)
            .SetJustifyAlignment(true)
            .SetFont(Fonts.Courier(16)).SetFontColor(colorDarkBlue).SetBold()
            .SetBorderStroke(Stroke.Dotted).SetBorderWidth(3).SetBorderColor(colorDarkBlue)
            .AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit")
                .SetBackColor(colorDarkBlue)
                .SetFontColor(Color.White)
                .SetStrikethrough(Stroke.Solid, Color.Gray)
        .ToParagraph()
            .AddText(". Lorem ipsum dolor sit amet, consectetur adipiscing elit");
 
    // Add a TOC item:
 
    sectionBuilder
        .AddParagraph("Using Tabulation")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Add a tabulation:
 
    sectionBuilder
        .AddParagraph()
            .AddTabSymbol()
            .AddTextToParagraph("RIGHT300")
            .AddTabulation(300, TabulationType.Right)
    .ToSection()
        .AddParagraph()
            .AddTabSymbol()
            .AddTextToParagraph("LEFT300")
            .AddTabulation(300, TabulationType.Left)
    .ToSection()
        .AddParagraph()
            .AddTabSymbol()
            .AddTextToParagraph("CENTER300")
            .AddTabulation(300, TabulationType.Center);
 
    // Add a TOC item:
 
    sectionBuilder
        .AddParagraph("Adding Image")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Add an image:
 
    string image1 = "C:\path\to\logo.png";
 
    sectionBuilder
        .AddImage(image1)
            .SetScale(ScalingMode.UserDefined)
            .SetWidth(300);
 
    // Add a TOC item:
 
    sectionBuilder
        .AddParagraph("Adding Inline Image")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Add an inline image:
 
    string imageSmile = "C:\path\to\map_pin.png";
    sectionBuilder
       .AddParagraph("Inline ")
       .SetAlignment(HorizontalAlignment.Right)
       .AddInlineImageToParagraph(imageSmile, 35, 30, ScalingMode.UserDefined)
       .AddText(" image");
 
 
    // Add a TOC item:
    sectionBuilder
        .AddParagraph("Adding Table")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Add a table:
 
    TableBuilder table = sectionBuilder.AddTable()
        .AddColumnPercentToTable("Name", 25f)
        .AddColumnPercentToTable("Description", 50f)
        .AddColumnPercentToTable("Date", 25)
        .SetAltRowStyleBackColor(colorLightBlue)
        .SetHeaderRowColor(colorDarkBlue);
    table
        .AddRow()
           .AddCellToRow("Keanu Reeves")
           .AddCellToRow("Canadian actor. Born in Beirut and raised in Toronto.")
           .AddCellToRow("2 September, 1964");
    table
        .AddRow()
            .AddCellToRow("John Roe")
            .AddCell("INFORMATION IS UNAVAILABLE!", colSpan: 2)
            .SetHorizontalAlignment(HorizontalAlignment.Center);
    table
        .AddRow()
            .AddCell("Daneliya Tuleshova")
        .ToRow()
           .AddCellToRow("Kazakh singer.")
           .AddCellToRow("18 July, 2006");
 
    // Add a TOC item:
    sectionBuilder
        .AddParagraph("Adding MultiLevel list")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Add a multilevel list:
 
    FontBuilder font = Fonts.Times(14f);
    float leftIndent = 20f;
 
    sectionBuilder
        .AddParagraph("Level = 0. Item 1.")
            .SetAlignment(HorizontalAlignment.Left)
            .SetFont(font)
            .SetFontSize(16)
            .SetListBulleted(ListBullet.Bullet, 0, leftIndent);
    sectionBuilder
        .AddParagraph("Level = 1. Item 1.")
        .SetFont(font)
        .SetListNumbered(NumerationStyle.Arabic, 1, leftIndent);
    sectionBuilder
        .AddParagraph("Level = 2. Item 1.")
        .SetFont(font)
        .SetFontSize(10)
        .SetListNumbered(NumerationStyle.UpperLatin, 2, leftIndent);
    sectionBuilder
        .AddParagraph("Level = 2. Item 2.")
        .SetFont(font)
        .SetFontSize(10)
        .SetListNumbered(NumerationStyle.UpperLatin, 2, leftIndent);
    sectionBuilder
        .AddParagraph("Level = 1. Item 2.")
        .SetAlignment(HorizontalAlignment.Left)
        .SetFont(font)
        .SetListNumbered(NumerationStyle.Arabic, 1, leftIndent);
    sectionBuilder
        .AddParagraph("Level = 0. Item 2.")
        .SetAlignment(HorizontalAlignment.Left)
        .SetFont(font)
        .SetFontSize(16)
        .SetListBulleted(ListBullet.Bullet, 0, leftIndent);
 
    // Add a TOC item:
    sectionBuilder
        .AddParagraph("Adding Line")
            .SetMarginTop(15)
            .SetFontColor(Color.Gray)
            .SetAlignment(HorizontalAlignment.Center)
            .SetOutline();
 
    // Add a line:
 
    sectionBuilder
        .AddLine(XUnit.FromPercent(30))
        .SetWidth(3f)
        .SetColor(colorDarkBlue)
        .SetStroke(Stroke.Dashed)
        .SetAlignment(HorizontalAlignment.Center)
    .ToSection()
        .AddLine()
        .SetWidth(6f)
        .SetColor(colorLightBlue)
        .SetStroke(Stroke.Solid)
        .SetMarginTop(15f);
 
    // Add a footer with a right-aligned page number:
 
    RepeatingAreaBuilder footer = sectionBuilder.AddFooterToBothPages(40f);
    footer
        .AddParagraph()
        .SetAlignment(HorizontalAlignment.Right)
        .AddPageNumber(customText: "Page #");
 
    // Add a TOC:
 
    builder
        .AddOutline("TABLE OF CONTENT")
            .SetSpacingUnderline(Stroke.Dotted, colorDarkBlue);
 
    // Build a document:
 
    builder.Build("QuickStart.pdf");
 
 
    The above code will generate the following:
 
    
     
 
    See the document

back