Document Output

DynamicPDF Core Suite for .NET can output PDF documents to a file, byte array, or any System.IO.Stream object that supports writing. A Document class's Draw method have many options for customizing a PDF document's output.

Output to a file

Use the Document element's Draw method to save a PDF to a file path. Specify the file path and name.

// Outputs the PDF document to a file.
String pdfFilePath = "./documents/my-saved-pdf-document.pdf"
document.Draw( pdfFilePath );  
' Outputs the PDF document to a file.
MyDocument.Draw( pdfFilePath )

Output to a System.IO.Stream object

Specify the Stream object to receive the output from Document. The Document.Draw method also supports streaming a byte array as a stream.

// Outputs the PDF document to a stream.
document.Draw( stream );  
' Outputs the PDF document to a byte array.
Dim MyData As Byte()
MyData = MyDocument.Draw()

Output to Byte Array

Use the Draw method without any parameters to save the PDF to a Byte Array.

// Outputs the PDF document to a byte array.
byte[] pdfData = document.Draw();
' Outputs the PDF document to a byte array.
Dim MyPdfData As Byte()
MyPdfData = MyDocument.Draw()

Output to an ASPX page (WebForm)

Draw to Browser

Use the following code to output the pdf to the end-user's browser.

// Outputs the PDF document to the page object.
byte[] pdfData = document.Draw();
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdfData);
' Outputs the PDF document to the page object.
Dim MyPdfData As Byte() = MyDocument.Draw()
Response.ContentType = "application/pdf"
Response.BinaryWrite(MyPdfData)

Draw to File System

Use the following code for the pdf to be saved to the end user's machine rather than displayed in an user's browser

// Outputs the PDF document to the page object.
byte[] pdfData = document.Draw();
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdfData);
Response.AddHeader("Content-Disposition", "attachment;filename=\"FileName.pdf\"");
' Outputs the PDF document to the page object.
Dim MyPdfData As Byte() = MyDocument.Draw()
Response.ContentType = "application/pdf"
Response.BinaryWrite(MyPdfData)
Response.AddHeader("Content-Disposition", "attachment;filename=""FileName.pdf")

In this topic