0% found this document useful (0 votes)
200 views2 pages

HTML 2 PDF

This method converts an HTML document from a specified URL to a PDF document. It creates a PdfConverter object, sets various conversion options like page size and compression, then calls GetPdfBytesFromUrl to perform the conversion. The resulting PDF bytes are sent to the browser for the user to download or view inline.

Uploaded by

Sudha Maya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views2 pages

HTML 2 PDF

This method converts an HTML document from a specified URL to a PDF document. It creates a PdfConverter object, sets various conversion options like page size and compression, then calls GetPdfBytesFromUrl to perform the conversion. The resulting PDF bytes are sent to the browser for the user to download or view inline.

Uploaded by

Sudha Maya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// <summary>

/// Convert the HTML code from the specified URL to a PDF document
and send the document to the browser
/// </summary>
private void ConvertURLToPDF()
{
string urlToConvert = [Link]();
// Create the PDF converter. Optionally the HTML viewer width can
be specified as parameter
// The default HTML viewer width is 1024 pixels.
PdfConverter pdfConverter = new PdfConverter();
// set the license key - required
[Link] = "ORIJGQoKGQkZCxcJGQoIFwgLFwAAAAA=";
// set the converter options - optional
[Link] = PdfPageSize.A4;
[Link] = PdfCompressionLeve
[Link];
[Link] = PdfPageOrientation.
Portrait;

// set if header and footer are shown in the PDF - optional - default
is false
[Link] = [Link];
[Link] = [Link];
// set if the HTML content is resized if necessary to fit the PDF
page width - default is true
[Link] = [Link];
// set the embedded fonts option - optional - default is false
[Link] = [Link];
// set the live HTTP links option - optional - default is true
[Link] = [Link];
// set if the JavaScript is enabled during conversion to a PDF - default
is true
[Link] = [Link];
// set if the images in PDF are compressed with JPEG to reduce the
PDF document size - default is true
[Link] = cbJpegCompressi
[Link];
// enable auto-generated bookmarks for a specified list of HTML selector
s
(e.g. H1 and H2)
if ([Link])
{
[Link] = new string[]
{ "H1", "H2" };
}
// add HTML header
if ([Link])
AddHeader(pdfConverter);
// add HTML footer
if ([Link])
AddFooter(pdfConverter);
// Performs the conversion and get the pdf document bytes that can
// be saved to a file or sent as a browser response
byte[] pdfBytes = [Link](urlToConvert);
// send the PDF document as a response to the browser for download
[Link] response = [Link]
se;
[Link]();
[Link]("Content-Type", "application/pdf");
if ([Link])
[Link]("Content-Disposition", [Link]("attachment;
filename=[Link]; size={0}",
[Link]()));
else
[Link]("Content-Disposition", [Link]("inline; fil
ename=[Link]; size={0}",
[Link]()));
[Link](pdfBytes);
// Note: it is important to end the response, otherwise the [Link]
// web page will render its content to PDF document stream
[Link]();
}

You might also like