The article describes how to create a PDF document.
You can create a PDF document, add one or more sections to the document and configure them, and build the document using methods of the
DocumentBuilder
class.
Note that to create documents using the PDFFlow library, you should use a number of namespaces in your project.
The directive "using
Gehtsoft.PDFFlow.Builder;
" is the main directive that allows you to call DocumentBuilder
and other builders and their methods to add sections and content to a document. This directive is required for all applications. The other directives are additional.
The directive "using
Gehtsoft.PDFFlow.Models.Enumerations;
" allows you to use the standard enumerations to set method parameters.
The directive "using
Gehtsoft.PDFFlow.Models.Shared;
" allows you to use common data structures and classes.
The directive "using
Gehtsoft.PDFFlow.Utils;
" allows you to use methods for quick creation of most used fonts.
The directive "using
Gehtsoft.PDFFlow.UserUtils;
" allows you to use methods of helper classes for creation of styles based on default styles, defining the appropriate page size, and changing the numbering style.
To create a PDF document:
Create a document builder using the DocumentBuilder.New()
method.
Add sections to the document.
You can create several sections in one document.
Each section may contain several pages, they will be generated automatically depending on the content.
You can add various content to a section, including paragraphs, images,
tables, lines and repeating areas.
For a full list of available content items, see the article Adding Section.
A document can also include a table of content with items from multiple sections. For details about creating a table of content, see the Creating Table of Content article.
Generate a PDF document using the DocumentBuilder.Build(fileName)
or
DocumentBuilder.Build(outputStream)
method.
If you do not specify formatting settings for your document or its elements, they will have their values defined by the default style.
You can create a style and apply it to an entire document and set the style for all paragraphs, images, lines, lists, tables in the document
using the corresponding methods of DocumentBuilder
. Styles can be also set for document elements on a section level,
for paragraph elements on a paragraph level, and for particular content elements.
For more on working with styles, see the article Formatting and Styles.
See also
Examples
Example 1. Create a document (variant 1) Hide
//Create a document builder:
DocumentBuilder.New()
//Add a section and section content:
.AddSection()
.AddParagraph("Hello World!")
//Build a file:
.ToDocument().Build("Result.pdf");
The above code will generate the following:
See the document
Example 2. Create a document (variant 2) Show
Example 3. Create a document with writing results to a stream (variant 1) Hide
//Set the stream:
var myStream = new FileStream("Result.pdf", FileMode.Create);
//Create a document builder:
DocumentBuilder.New()
//Add a section and section content:
.AddSection()
.AddParagraph("Hello World!")
//Build a file:
.ToDocument().Build(myStream);
myStream.Close();
The above code will generate the following:
See the document
Example 4. Create a document with writing results to a stream (variant 2) Show