Table of Contents

Class PdfDocumentBuilder

Namespace
UglyToad.PdfPig.Writer
Assembly
UglyToad.PdfPig.dll

Provides methods to construct new PDF documents.

public class PdfDocumentBuilder : IDisposable
Inheritance
PdfDocumentBuilder
Implements
Inherited Members

Constructors

PdfDocumentBuilder()

Creates a document builder keeping resources in memory.

public PdfDocumentBuilder()

PdfDocumentBuilder(decimal)

Creates a document builder keeping resources in memory.

public PdfDocumentBuilder(decimal version)

Parameters

version decimal

Pdf version to use in header.

PdfDocumentBuilder(Stream, bool, PdfWriterType, decimal, ITokenWriter)

Creates a document builder using the supplied stream.

public PdfDocumentBuilder(Stream stream, bool disposeStream = false, PdfWriterType type = PdfWriterType.Default, decimal version = 1.7, ITokenWriter tokenWriter = null)

Parameters

stream Stream

Steam to write pdf to.

disposeStream bool

If stream should be disposed when builder is.

type PdfWriterType

Type of pdf stream writer to use

version decimal

Pdf version to use in header.

tokenWriter ITokenWriter

Token writer to use

Properties

ArchiveStandard

The standard of PDF/A compliance of the generated document. Defaults to None.

public PdfAStandard ArchiveStandard { get; set; }

Property Value

PdfAStandard

Bookmarks

The bookmark nodes to include in the document outline dictionary.

public Bookmarks Bookmarks { get; set; }

Property Value

Bookmarks

DocumentInformation

The values of the fields to include in the document information dictionary.

public PdfDocumentBuilder.DocumentInformationBuilder DocumentInformation { get; set; }

Property Value

PdfDocumentBuilder.DocumentInformationBuilder

IncludeDocumentInformation

Whether to include the document information dictionary in the produced document.

public bool IncludeDocumentInformation { get; set; }

Property Value

bool

Pages

The current page builders in the document and the corresponding 1 indexed page numbers. Use AddPage(double, double) or AddPage(PageSize, bool) to add a new page.

public IReadOnlyDictionary<int, PdfPageBuilder> Pages { get; }

Property Value

IReadOnlyDictionary<int, PdfPageBuilder>

Methods

AddPage(double, double)

Add a new page with the specified size, this page will be included in the output when Build() is called.

public PdfPageBuilder AddPage(double width, double height)

Parameters

width double

The width of the page in points.

height double

The height of the page in points.

Returns

PdfPageBuilder

A builder for editing the new page.

AddPage(PageSize, bool)

Add a new page with the specified size, this page will be included in the output when Build() is called.

public PdfPageBuilder AddPage(PageSize size, bool isPortrait = true)

Parameters

size PageSize

The size of the page to add.

isPortrait bool

Whether the page is in portait or landscape orientation.

Returns

PdfPageBuilder

A builder for editing the new page.

AddPage(PdfDocument, int)

Add a new page with the specified size, this page will be included in the output when Build() is called.

public PdfPageBuilder AddPage(PdfDocument document, int pageNumber)

Parameters

document PdfDocument

Source document.

pageNumber int

Page to copy.

Returns

PdfPageBuilder

A builder for editing the page.

AddPage(PdfDocument, int, Func<PdfAction, PdfAction>)

Add a new page with the specified size, this page will be included in the output when Build() is called.

public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, Func<PdfAction, PdfAction> copyLink)

Parameters

document PdfDocument

Source document.

pageNumber int

Page to copy.

copyLink Func<PdfAction, PdfAction>

If set, links are copied based on the result of the delegate.

Returns

PdfPageBuilder

A builder for editing the page.

AddStandard14Font(Standard14Font)

Adds one of the Standard 14 fonts which are included by default in PDF programs so that pages in this document can use it. These Standard 14 fonts are old and possibly obsolete.

public PdfDocumentBuilder.AddedFont AddStandard14Font(Standard14Font type)

Parameters

type Standard14Font

The type of the Standard 14 font to use.

Returns

PdfDocumentBuilder.AddedFont

An identifier which can be passed to AddText(string, decimal, PdfPoint, AddedFont).

AddTrueTypeFont(IReadOnlyList<byte>)

Adds a TrueType font to the builder so that pages in this document can use it.

public PdfDocumentBuilder.AddedFont AddTrueTypeFont(IReadOnlyList<byte> fontFileBytes)

Parameters

fontFileBytes IReadOnlyList<byte>

The bytes of a TrueType font.

Returns

PdfDocumentBuilder.AddedFont

An identifier which can be passed to AddText(string, decimal, PdfPoint, AddedFont).

Build()

Builds a PDF document from the current content of this builder and its pages.

public byte[] Build()

Returns

byte[]

The bytes of the resulting PDF document.

CanUseTrueTypeFont(IReadOnlyList<byte>, out IReadOnlyList<string>)

Determines whether the bytes of the TrueType font file provided can be used in a PDF document.

public bool CanUseTrueTypeFont(IReadOnlyList<byte> fontFileBytes, out IReadOnlyList<string> reasons)

Parameters

fontFileBytes IReadOnlyList<byte>

The bytes of a TrueType font file.

reasons IReadOnlyList<string>

Any reason messages explaining why the file can't be used, if applicable.

Returns

bool

true if the file can be used, false otherwise.

Dispose()

Disposes underlying stream if set to do so.

public void Dispose()