Class PdfDocument
- Namespace
- CobaltPdf
- Assembly
- CobaltPdf.dll
The rendered PDF artifact. Use this to save the file or access raw binary data.
public class PdfDocument
- Inheritance
-
PdfDocument
- Inherited Members
Constructors
PdfDocument(byte[])
public PdfDocument(byte[] data)
Parameters
databyte[]
Exceptions
Properties
BinaryData
The raw PDF binary data.
public byte[] BinaryData { get; }
Property Value
- byte[]
Length
Returns the size of the PDF in bytes.
public long Length { get; }
Property Value
PageCount
Number of pages in this PDF.
public int PageCount { get; }
Property Value
Methods
ExtractPage(int)
Extracts a single page (0-based) into a new PdfDocument, preserving its fonts, images and vector content.
public PdfDocument ExtractPage(int pageIndex)
Parameters
pageIndexint
Returns
ExtractPages(IEnumerable<int>)
Extracts an arbitrary set of pages (0-based; may be non-contiguous and in any order) into a new document.
public PdfDocument ExtractPages(IEnumerable<int> pageIndices)
Parameters
pageIndicesIEnumerable<int>
Returns
ExtractPages(int, int)
Extracts an inclusive range of pages (0-based) into a new document.
public PdfDocument ExtractPages(int startIndex, int endIndex)
Parameters
Returns
FromBytes(byte[])
Wraps existing PDF bytes for page operations.
public static PdfDocument FromBytes(byte[] data)
Parameters
databyte[]
Returns
FromFile(string)
Loads an existing PDF from disk (e.g. to split a file you didn't render).
public static PdfDocument FromFile(string path)
Parameters
pathstring
Returns
GetStream()
Returns a stream of the PDF data for email attachments or web responses.
public Stream GetStream()
Returns
Merge(params PdfDocument[])
Merges multiple PDFs into one, in order (the inverse of splitting).
public static PdfDocument Merge(params PdfDocument[] documents)
Parameters
documentsPdfDocument[]
Returns
SaveAs(string)
Saves the PDF document to the specified file path and returns this instance for chaining.
public PdfDocument SaveAs(string path)
Parameters
pathstringThe file path to write the PDF to.
Returns
- PdfDocument
This PdfDocument instance, allowing fluent chaining.
Examples
var pdf = await renderer
.WithLandscape()
.RenderUrlAsPdfAsync("https://example.com")
.SaveAs("output.pdf");
SaveAsAsync(string)
Asynchronously saves the PDF document to the specified file path and returns this instance for chaining.
public Task<PdfDocument> SaveAsAsync(string path)
Parameters
pathstringThe file path to write the PDF to.
Returns
- Task<PdfDocument>
A task that resolves to this PdfDocument instance, allowing fluent chaining.
Examples
var pdf = await (await renderer
.WithLandscape()
.RenderUrlAsPdfAsync("https://example.com"))
.SaveAsAsync("output.pdf");
SplitIntoPages()
Splits this PDF into one single-page PdfDocument per page.
public IReadOnlyList<PdfDocument> SplitIntoPages()