C# 通过将HTML内容传递给方法来创建PDF
通过将HTML内容传递给方法来创建PDF。C# 通过将HTML内容传递给方法来创建PDF,c#,C#,通过将HTML内容传递给方法来创建PDF。 我想做的是c#。有我可以使用的实用程序吗?试试wkhtmtopdf。这是迄今为止我找到的最好的工具 对于.NET,您可以使用这个小型库轻松调用wkhtmtopdf命令行实用程序 链接: 可以将HTML转换为PDF。它是用C#编写的,可以作为库从任何.NET平台使用 如果您符合条件,将免费提供整套产品 注意:我为Syncfusion工作。HiQPdf软件提供了一个可用于免费生成中小型PDF文档的工具。对于大型PDF或高级功能,您可以随时升级到专业版 我
我想做的是c#。有我可以使用的实用程序吗?试试wkhtmtopdf。这是迄今为止我找到的最好的工具 对于.NET,您可以使用这个小型库轻松调用wkhtmtopdf命令行实用程序 链接: 可以将HTML转换为PDF。它是用C#编写的,可以作为库从任何.NET平台使用 如果您符合条件,将免费提供整套产品 注意:我为Syncfusion工作。HiQPdf软件提供了一个可用于免费生成中小型PDF文档的工具。对于大型PDF或高级功能,您可以随时升级到专业版 我是HiQPdf支持代表。该页的相关代码复制如下:
protected void buttonConvertToPdf_Click(object sender, EventArgs e)
{
// create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// set browser width
htmlToPdfConverter.BrowserWidth = int.Parse(textBoxBrowserWidth.Text);
// set browser height if specified, otherwise use the default
if (textBoxBrowserHeight.Text.Length > 0)
htmlToPdfConverter.BrowserHeight = int.Parse(textBoxBrowserHeight.Text);
// set HTML Load timeout
htmlToPdfConverter.HtmlLoadedTimeout = int.Parse(textBoxLoadHtmlTimeout.Text);
// set PDF page size and orientation
htmlToPdfConverter.Document.PageSize = GetSelectedPageSize();
htmlToPdfConverter.Document.PageOrientation = GetSelectedPageOrientation();
// set PDF page margins
htmlToPdfConverter.Document.Margins = new PdfMargins(0);
// set a wait time before starting the conversion
htmlToPdfConverter.WaitBeforeConvert = int.Parse(textBoxWaitTime.Text);
// convert HTML to PDF
byte[] pdfBuffer = null;
if (radioButtonConvertUrl.Checked)
{
// convert URL to a PDF memory buffer
string url = textBoxUrl.Text;
pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
}
else
{
// convert HTML code
string htmlCode = textBoxHtmlCode.Text;
string baseUrl = textBoxBaseUrl.Text;
// convert HTML code to a PDF memory buffer
pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlCode, baseUrl);
}
// inform the browser about the binary data format
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
// let the browser know how to open the PDF document, attachment or inline, and the file name
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0}; filename=HtmlToPdf.pdf; size={1}",
checkBoxOpenInline.Checked ? "inline" : "attachment", pdfBuffer.Length.ToString()));
// write the PDF buffer to HTTP response
HttpContext.Current.Response.BinaryWrite(pdfBuffer);
// call End() method of HTTP response to stop ASP.NET page processing
HttpContext.Current.Response.End();
}
我在谷歌上搜索了“c#create pdf from html”,找到了一些很好的起点。这个网站开始充斥着通过搜索网页可以回答的所有问题。原因是在提问之前不要用谷歌搜索。我先收集信息,不过你可以改进你的问题和答案。