如何将Asp.Net页面导出到Pdf [英] How to export Asp.Net page to Pdf
本文介绍了如何将Asp.Net页面导出到Pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将Asp.Net页面导出为PDF,但是我不知道该怎么做.请帮助我
I want to export Asp.Net Page to PDF but I don''t know how i do this Please help me
推荐答案
我有这么多链接当我放置在Google搜索中时的主题行
^ ]
I got this many links with your subject line when i place in the google search
How to export Asp.Net page to Pdf[^]
我使用Winnovative.WnvHtmlConvert;
您可以找到它并下载wnvhtmlconvert.dll.
请参考dll.
它不是免费的,但具有带有许可证的演示版.从以下网站获取它:http://www.winnovative-software.com/[^]
使用以下功能:
I use the Winnovative.WnvHtmlConvert;
You can find it and download the wnvhtmlconvert.dll.
Make reference to the dll.
It is not free but it has demo version with a license. Get it from the site: http://www.winnovative-software.com/[^]
Use the following function:
/// <summary>
/// Convert the HTML code from the specified URL to a PDF document and send the
/// document as an attachment to the browser
/// </summary>
private void ConvertURLToPDF()
{
// 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 - required
pdfConverter.LicenseKey = "you license here";
// set the converter options - optional
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
// set if header and footer are shown in the PDF - optional - default is false
pdfConverter.PdfDocumentOptions.ShowHeader = false;
pdfConverter.PdfDocumentOptions.ShowFooter = false;
// set to generate a pdf with selectable text or a pdf with embedded image - optional - default is true
pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
// set if the HTML content is resized if necessary to fit the PDF page width - optional - default is true
pdfConverter.PdfDocumentOptions.FitWidth = true;
//
// set the embedded fonts option - optional - default is false
pdfConverter.PdfDocumentOptions.EmbedFonts = false;
// set the live HTTP links option - optional - default is true
pdfConverter.PdfDocumentOptions.LiveUrlsEnabled = true;
if (true) //(radioConvertToSelectablePDF.Checked)
{
// set if the JavaScript is enabled during conversion to a PDF with selectable text
// - optional - default is false
pdfConverter.ScriptsEnabled = false;
// set if the ActiveX controls (like Flash player) are enabled during conversion
// to a PDF with selectable text - optional - default is false
pdfConverter.ActiveXEnabled = false;
}
else
{
// set if the JavaScript is enabled during conversion to a PDF with embedded image
// - optional - default is true
pdfConverter.ScriptsEnabledInImage = true;
// set if the ActiveX controls (like Flash player) are enabled during conversion
// to a PDF with embedded image - optional - default is true
pdfConverter.ActiveXEnabledInImage = true;
}
// set if the images in PDF are compressed with JPEG to reduce the PDF document size - optional - default is true
pdfConverter.PdfDocumentOptions.JpegCompressionEnabled = true;
// enable auto-generated bookmarks for a specified list of tags (e.g. H1 and H2)
if (false)
{
pdfConverter.PdfBookmarkOptions.TagNames = new string[] { "H1", "H2" };
}
// set PDF security options - optional
//pdfConverter.PdfSecurityOptions.CanPrint = true;
//pdfConverter.PdfSecurityOptions.CanEditContent = true;
//pdfConverter.PdfSecurityOptions.UserPassword = "";
//set PDF document description - optional
//pdfConverter.PdfDocumentInfo.AuthorName = "Winnovative HTML to PDF Converter";
//// add HTML header
//if (cbAddHeader.Checked)
// AddHeader(pdfConverter);
//// add HTML footer
//if (cbAddFooter.Checked)
// AddFooter(pdfConverter);
// 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 download
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition",
"attachment; filename=ConversionResult.pdf; size=" + pdfBytes.Length.ToString());
response.Flush();
response.BinaryWrite(pdfBytes);
response.Flush();
response.End();
}
祝你好运.
Good luck.
这篇关于如何将Asp.Net页面导出到Pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文