我需要在Windows Phone 8(c#)中將HTML文件轉換爲pdf或圖像。我需要一種方法來呈現HTML文件,以PDF或圖像 任何人都知道如何?HTML到PDF或圖像c#
0
A
回答
1
您可以使用pdfcrowd在線對其進行轉換。
0
對於轉換PDF,你可以用它wkhtmltopdf
而且代碼
string pdfHtmlToPdfExePath ="C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe"
string urlsSeparatedBySpaces = string.Empty;
try
{
//Determine inputs
if ((urls == null) || (urls.Length == 0))
throw new Exception("No input URLs provided for HtmlToPdf");
else
urlsSeparatedBySpaces = String.Join(" ", urls); //Concatenate URLs
string outputFolder = pdfOutputLocation;
//string outputFilename = outputFilenamePrefix + "_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss-fff") + ".PDF"; // assemble destination PDF file name
var p = new System.Diagnostics.Process()
{
StartInfo =
{
FileName = pdfHtmlToPdfExePath,
Arguments = ((options == null) ? "" : String.Join(" ", options)) + " " + urlsSeparatedBySpaces + " " + outputFilename,
UseShellExecute = false, // needs to be false in order to redirect output
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true, // redirect all 3, as it should be all 3 or none
WorkingDirectory = HttpContext.Current.Server.MapPath(outputFolder)
}
};
p.Start();
// read the output here...
var output = p.StandardOutput.ReadToEnd();
var errorOutput = p.StandardError.ReadToEnd();
// ...then wait n milliseconds for exit (as after exit, it can't read the output)
p.WaitForExit(60000);
// read the exit code, close process
int returnCode = p.ExitCode;
p.Close();
// if 0 or 2, it worked so return path of pdf
if ((returnCode == 0) || (returnCode == 2))
return HttpContext.Current.Server.MapPath(outputFolder +"//"+ outputFilename);
else
throw new Exception(errorOutput);
}
catch (Exception exc)
{
throw new Exception("Problem generating PDF from HTML, URLs: " + urlsSeparatedBySpaces + ", outputFilename: " + outputFilename, exc);
}
1
相關問題
- 1. 使用DevExpress或Infragistics將HTML或PDF轉換爲RTF/DOC或HTML/PDF圖像
- 2. HTML到JavaScript或python圖像
- 3. VML到HTML或圖像
- 4. Html二進制圖像到PDF在java
- 5. 將圖像添加到HTML/PDF報告
- 6. Html(帶圖像)爲PDF - Java
- 7. itext7 pdf到圖像
- 8. 出口從HTML到PDF(C#)
- 9. c#中的HTML到PDF#
- 10. PDF使用圖像C#.NET
- 11. 從PDF將頁面分隔成圖像或HTML
- 12. 將Rtf,Excel,Pdf或Html文件格式轉換爲圖像
- 13. PDFBOX:將pdf轉換爲文本或html,包括pdf中的圖像
- 14. PDF到圖像轉換器
- 15. HTML圖像在PDF不打印
- 16. 在HTML中顯示PDF爲圖像
- 17. 將PDF或圖像從URL加載到CoverFlow視圖中
- 18. PS文件爲PDF或圖像
- 19. 在db4o中保存圖像或pdf
- 20. 試圖在c中插入圖像到pdf中#
- 21. 在安全的網站上圖像不呈現爲pdf - itext飛碟HTML到PDF
- 22. PDF到Html(+ javascript)
- 23. ABCPDF版本8 HTML到PDF圖像不顯示
- 24. 飛龍:圖出口到圖像/ PDF
- 25. 使用C從PDF中提取圖像#
- 26. 在C#中閱讀PDF文本圖像
- 27. 轉換PDF文件爲圖像 - VB/C#
- 28. 將PDF轉換爲圖像序列C#
- 29. 工具圖像轉換文本到Word或TXT或HTML
- 30. 在pdf c中將圖像水印添加到另一圖像中#
這是一個非常好的工具,但圖像/輸出PDF字體可以在某些情況下,很醜陋。 – ChruS 2013-02-28 13:09:21
謝謝,但這對Windows Phone來說很有用 – 2013-02-28 13:24:55