通过将HTML内容传递给方法来创建PDF。 我想这样做是c#。有没有我可以使用的工具?通过将HTML内容传递给方法来创建PDF
-4
A
回答
1
尝试wkhtmtopdf。这是迄今为止我发现的最好的工具。
对于.NET,您可以使用这个小型库来轻松调用wkhtmtopdf命令行实用程序。
链接:
0
Essential PDF可以HTML转换为PDF。它是用C#编写的,可以作为一个库在任何.NET平台上使用。如果您有资格,community license提供免费的整套产品。
注意:我为Syncfusion工作。
0
HiQPdf Software提供了一个free HTML to PDF Converter for .NET,您可以使用它免费制作小型和中型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();
}
相关问题
- 1. 如何通过将类名传递给方法来创建子类UIViewController?
- 2. 将值传递给方法参数来创建一个CGRect
- 3. 500将内部服务器通过jquery.post传递给wcf方法
- 4. 将内容传递给deleteasync
- 5. 将方法传递给我在Ruby中创建的方法
- 6. 无法将editView内容传递给一个方法?
- 7. 通过Python和Jinja将表内容从SQL传递到HTML
- 8. 将值传递给内部类方法?
- 9. 将通用类型传递给方法
- 10. iOS - 从HTML内容创建多页PDF
- 11. Joomla 3.0+从HTML内容创建PDF
- 12. 传递方法的RSpec内创建
- 13. 通过代码将参数传递给html通过代码
- 14. 将FileUpload内容传递给[WebMethod]的正确方法?
- 15. 将内部递归方法的值传递给外部方法
- 16. HTML to PDF与通过PHP以编程方式创建PDF
- 17. 将httpservletrequest传递给方法
- 18. 将ArrayList传递给方法?
- 19. 将CharArray传递给方法
- 20. 将int []传递给方法
- 21. 将Stringstream传递给方法
- 22. 将块传递给方法
- 23. 通过URI将值传递给函数(而不是GET方法)
- 24. 通过PHP-PhantomJS将脚本传递给PhantomJS的正确方法?
- 25. 通过JNI将float [] []传递给C++的最简单方法
- 26. iPhone:将值传递给通过@selector()调用的方法
- 27. 通过提交方法将多个Javascript值传递给php isset?
- 28. 通过Post方法将“dd-MMM-yyyy”传递给datetime
- 29. 如何通过php Zend_Soap_Client将参数传递给soap方法?
- 30. 通过BuildView方法将变量传递给Twig Symfony2
我用Google搜索“c#创建pdf从html”,并找到了一些很好的起点。 –
这个网站开始吸收所有的投票无缘无故。 WTF。 –
这个网站开始吸收所有可以通过搜索网页来回答的问题。 – TripeHound