November 28, 2011

Conversion of url to PDF

#region

{

Convert URLtoPDFpublic static void ConvertURLToPDF(string Url, string downloadName)string urlToConvert = Url;// Create the PDF converter. Optionally you can specify the virtual browser // width as parameter. 1024 pixels is default, 0 means autodetect
PdfConverter pdfConverter = new PdfConverter();// set the license key - requiredpdfConverter.LicenseKey =
ConfigurationManager.AppSettings["LicenseKey"].ToString();// set the converter options - optionalpdfConverter.PdfDocumentOptions.PdfPageSize =
pdfConverter.PdfDocumentOptions.PdfCompressionLevel =
pdfConverter.PdfDocumentOptions.PdfPageOrientation =
 
PdfPageSize.A4;PdfCompressionLevel.Normal;PDFPageOrientation.Portrait;// set if header and footer are shown in the PDF - optional - default is false pdfConverter.PdfDocumentOptions.ShowHeader =
pdfConverter.PdfDocumentOptions.ShowFooter =
false;false;// set to generate a pdf with selectable text or a pdf with embedded image - optional - default is truepdfConverter.PdfDocumentOptions.GenerateSelectablePdf =
pdfConverter.ScriptsEnabled =
true;true;// set if the ActiveX controls (like Flash player) are enabled during conversion // to a PDF with selectable text - optional - default is falsepdfConverter.ActiveXEnabled =
 
true;// set PDF security options - optionalpdfConverter.PdfSecurityOptions.CanPrint =
true;//pdfConverter.PdfSecurityOptions.CanEditContent = true;//pdfConverter.PdfSecurityOptions.UserPassword = "";//set PDF document description - optionalpdfConverter.PdfDocumentInfo.AuthorName =
"Winnovative HTML to PDF Converter";// Performs the conversion and get the pdf document bytes that you can further // save to a file or send as a browser response

byte[] pdfBytes = pdfConverter.GetPdfBytesFromUrl(urlToConvert);// send the PDF document as a response to the browser for downloadSystem.Web.
response.Clear();
response.AddHeader(
response.AddHeader(

response.Flush();
response.BinaryWrite(pdfBytes);
response.Flush();
response.End();
}
HttpResponse response = System.Web.HttpContext.Current.Response;"Content-Type", "binary/octet-stream");"Content-Disposition","attachment; filename=" + downloadName + ".pdf; size=" + pdfBytes.Length.ToString());#endregion

No comments:

Post a Comment