Class PDF
Used to create PDF objects that represent PDF documents.
public sealed class PDF
- Inheritance
-
PDF
- Inherited Members
Constructors
PDF()
The default constructor - use when reading PDF files.
public PDF()
PDF(Stream)
Creates a PDF document that is written to the stream.
public PDF(Stream os)
Parameters
osStream
PDF(Stream, Compliance)
Creates a PDF document with the specified compliance level.
public PDF(Stream os, Compliance compliance)
Parameters
osStreamthe associated output stream.
complianceCompliancemust be: Compliance.PDF_UA_1, Compliance.PDF_A_1A to Compliance.PDF_A_3B, or Compliance.PDF_A_3A_UA_1, which is both PDF/A-3a and PDF/UA-1
Methods
AddAssociatedFile(EmbeddedFile)
Adds a file that the document carries with it: a reader shows it beside the document, and a program that reads the document finds it by its name. This is how a document of PDF/A-3 carries the data behind what it shows, such as the XML of an invoice.
The file names what it holds, how it relates to the document and what it is, so it has to be made with the constructor of EmbeddedFile that takes them.
public PDF AddAssociatedFile(EmbeddedFile file)
Parameters
fileEmbeddedFileThe embedded file.
Returns
this PDF object.
AddMetadata(string)
Adds a description to the metadata of the document: the rdf:Description element of a standard that asks for properties of its own, such as the invoice standards that say which of the files the document carries is the invoice. The text is written into the metadata as it is given, so it has to be XML, and the document has to be of PDF/A or PDF/UA, which are the documents that carry metadata.
public PDF AddMetadata(string rdfDescription)
Parameters
rdfDescriptionstringThe rdf:Description element.
Returns
this PDF object.
AddObjects(List<PDFobj>)
Adds objects read from an existing PDF to this document. The objects keep their numbers and are written as they are, so they are added before any font, image or page of this document, and an encrypted PDF cannot take them. Their page tree is the page tree of this document, so it can have no pages of its own, before or after them, and it cannot be a PDF/UA or PDF/A document, as the pages were not made for its compliance.
public void AddObjects(List<PDFobj> objects)
Parameters
AddPage(Page)
Adds the page to this document.
public void AddPage(Page page)
Parameters
pagePage
AddPages(List<Page>)
Adds the pages to this document.
public void AddPages(List<Page> pages)
Parameters
AddResourceObjects(List<PDFobj>)
Adds the fonts, images and graphics states used by the pages to this document. The objects keep their numbers and are written as they are, so they are added before any font, image or page of this document, and an encrypted PDF cannot take them.
public void AddResourceObjects(List<PDFobj> objects)
Parameters
Complete()
Completes the construction of the PDF and writes it to the output stream. The output stream is then automatically closed.
public void Complete()
GetCompliance()
Returns the PDF document compliance.
public Compliance GetCompliance()
Returns
GetPageObjects(List<PDFobj>)
Returns the page objects, each holding the entries it inherits from the page tree: /Resources, /MediaBox, /CropBox and /Rotate, which a PDF can write once on a node above the pages rather than on every page. A page that has an entry of its own keeps it, and the entries are added to the page the first time it is returned, so that GetPageSize and GetResourcesObject read what the page is.
public List<PDFobj> GetPageObjects(List<PDFobj> objects)
Parameters
Returns
Merge(List<PDFobj>)
Adds all the pages of a document that was read with Read after the pages of this document, in their order. A PDF can merge several documents and draw pages of its own before, between and after them.
public void Merge(List<PDFobj> objects)
Parameters
Remarks
The merged pages keep their content, resources, annotations and links. The parts of the read document that belong to the whole document are left out: its bookmarks, form fields, tagging, named destinations and optional content settings. The objects that the pages use are written at once, so the list of objects is not needed after the call. A PDF/UA or PDF/A document cannot merge pages, which were not made for its compliance, and Merge cannot be used with AddObjects.
Merge(List<PDFobj>, params int[])
Adds the listed pages of a document that was read with Read after the pages of this document, in the order they are listed. A document is split by merging each part of it into a PDF of its own: the objects that Read returned can be merged into any number of PDFs.
public void Merge(List<PDFobj> objects, params int[] pageNumbers)
Parameters
objectsList<PDFobj>the objects of the document, as Read returns them.
pageNumbersint[]the numbers of the pages, counted from 1.
Remarks
The pages are merged as Merge(objects) merges all of them, and a link to a page that is not merged leads nowhere. A page number that the document does not have, or one that is listed twice, is refused.
Read(Stream)
Reads the objects of an existing PDF from the stream. An encrypted PDF is decrypted when it opens without a password.
public List<PDFobj> Read(Stream inputStream)
Parameters
inputStreamStream
Returns
Read(Stream, string)
Reads the objects of an existing PDF from the stream, which holds a PDF that is encrypted with the standard security handler. The PDF is decrypted with the password, which is its user or its owner password.
public List<PDFobj> Read(Stream inputStream, string password)
Parameters
Returns
Exceptions
- Exception
If the password is not correct.
SetAuthor(string)
Set the "Author" document property of the PDF file.
public PDF SetAuthor(string author)
Parameters
authorstringThe author of this document.
Returns
this PDF object.
SetCompliance(Compliance)
Sets the PDF/UA or PDF/A compliance of this document, before any font, image or page is added.
public PDF SetCompliance(Compliance compliance)
Parameters
complianceCompliance
Returns
SetCreator(string)
Sets the creator in the document metadata.
public PDF SetCreator(string creator)
Parameters
creatorstring
Returns
SetEncryption(Encryption)
Sets the encryption applied to this document, before any font, image or page is added.
public PDF SetEncryption(Encryption encryption)
Parameters
encryptionEncryption
Returns
SetKeywords(string)
Sets the keywords in the document metadata.
public PDF SetKeywords(string keywords)
Parameters
keywordsstring
Returns
SetLanguage(string)
Set the "Language" document property of the PDF file.
public PDF SetLanguage(string language)
Parameters
languagestringThe language of this document.
Returns
this PDF object.
SetPageLayout(PageLayout)
Sets the page layout used when the document is opened. See PageLayout.
public PDF SetPageLayout(PageLayout pageLayout)
Parameters
pageLayoutPageLayout
Returns
SetPageMode(PageMode)
Sets the page mode used when the document is opened. See PageMode.
public PDF SetPageMode(PageMode pageMode)
Parameters
pageModePageMode
Returns
SetSubject(string)
Set the "Subject" document property of the PDF file.
public PDF SetSubject(string subject)
Parameters
subjectstringThe subject of this document.
Returns
this PDF object.
SetTitle(string)
Set the "Title" document property of the PDF file. An empty title is not written.
public PDF SetTitle(string title)
Parameters
titlestringThe title of this document.
Returns
this PDF object.