通過將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