Skip to main content

PDF Document Output

Version: 6.0

Document Output

DynamicPDF Generator for .NET can output PDF documents to a file, web form, byte array or any System.IO.Stream object that supports writing. The Draw and DrawToWeb methods of the Document class handle all document output. These methods are overloaded and give many options for the output of the PDF document.

Output to an ASPX page (WebForm)​

From the On_Load event of the WebForm the Document's DrawToWeb method can be called and passed in a download file name.

// Outputs the PDF document to the page object.
document.DrawToWeb( "MyDocument.pdf" );
' Outputs the PDF document to the page object.
MyDocument.DrawToWeb( "MyDocument.pdf" )

By using the DrawToWeb method and passing in a True boolean value, this will force the document to be manually saved to the end user's machine instead of being viewed in the browser.

// Outputs the PDF document to the page object.
document.DrawToWeb( "MyDocument.pdf", true );
' Outputs the PDF document to the page object.
MyDocument.DrawToWeb( "MyDocument.pdf", True )

Output to a file​

Specify the file path and name for the file in the Document's Draw method.

// Outputs the PDF document to a file.
document.Draw( @"C:\\MyDocument.pdf" );
' Outputs the PDF document to a file.
MyDocument.Draw( "C:\\MyDocument.pdf" )

Output to a System.IO.Stream object​

Specify the Stream object to receive the output in the Document's Draw method.

// Outputs the PDF document to a stream.
document.Draw( stream );
' Outputs the PDF document to a stream.
MyDocument.Draw( MyStream )

Output to a byte array​

When calling the Draw method with no parameters, it will return the PDF data as a byte array. This is useful when storing the PDF in a database or returning it from a Web Service.

// Outputs the PDF document to a byte array.
byte[] data;
data = document.Draw();
' Outputs the PDF document to a byte array.
Dim MyData as Byte()
MyData = MyDocument.Draw()