我需要在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