2012-09-19 62 views
-1

我想将样式为静态html文件转换为pdf文件。 我只有几个字段在HTML, 像文本,选择,textarea,按钮,标签(但都包含内联样式) 我已经检查了itextsharp,这是转换为没有样式的pdf。将HTML文件转换为PDF(带内联样式)

我可以生成PDF,因为我看到了HTML文件的浏览器

我使用C#赢窗体应用程序做到这一点。

+0

看一看[wkhtmtopdf](http://code.google.com/p/wkhtmltopdf/)。此外,可能重复的[在HTML中将HTML转换为PDF](http://stackoverflow.com/questions/564650/convert-html-to-pdf-in-net) –

+0

我已更新我的答案看看 – iJade

+0

可能复制[C#HTML到PDF代码以用于服务(在服务器上)](http://stackoverflow.com/questions/12058560/c-sharp-html-to-pdf-code-for-use-in-一个服务器上的服务器) – yms

回答

1

使用http://www.html-to-pdf.net/从html页面生成pdf首先从网站下载dll并在你的代码中引用它...我写下了其余的代码,看看。

PdfConverter pdfConverter = new PdfConverter(); 
      //pdfConverter.LicenseKey = "put your license key here"; 

      pdfConverter.PdfDocumentOptions.EmbedFonts = false; 
      pdfConverter.PdfDocumentOptions.ShowFooter = false; 
      pdfConverter.PdfDocumentOptions.ShowHeader = false; 
      pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true; 
      pdfConverter.ActiveXEnabled = true; 
      pdfConverter.AvoidImageBreak = true; 
      pdfConverter.NavigationTimeout = 2147483647; 

      pdfConverter.ScriptsEnabled = true; 
      pdfConverter.PdfDocumentOptions.AutoSizePdfPage = true; 
      pdfConverter.SavePdfFromUrlToFile(html file path, output file path filepath); 
+0

搜索了很多,但无法想出一个确切的解决方案,这个问题 “生成pdf,因为我看到浏览器中的HTML文件” – user1621791

+0

谢谢:),任何演示的关键测试? – user1621791

+0

你不需要一个演示密钥来测试;)它会留下一个水印在pdf上,除非你买了一个许可证密钥 – iJade

0

我使用WKHtmlToPdf一个基于标准WebKit引擎的shell实用程序。试一试。

+0

C#的任何代码示例都会有帮助 – user1621791

0

Amyuni WebkitPDF是一个可用于HTML到PDF转换的免费库。它附带了C#和C++中的示例代码以及可用于评估结果的示例桌面应用程序。

通常免责声明适用