我想知道ITextSharp是否具有将HTML转换为PDF的能力.我将转换的所有内容都只是纯文本,但遗憾的是ITextSharp上几乎没有文档,所以我无法确定这对我来说是否是一个可行的解决方案.
如果它不能这样做,有人可以指向一些好的,免费的.net库,可以采用简单的纯文本HTML文档并将其转换为PDF格式吗?
TIA.
我希望使用"使用PDFsharp的HTML HTML渲染器"将HTML转换为PDF.我已经看到在几个网站上提到它是可能的.但是,我似乎无法找到任何基本的示例代码来执行此操作.
我添加了以下NuGet包.
Install-Package HtmlRenderer.PdfSharp
这就是我所拥有的.任何帮助将不胜感激.
我有一个带有文本,图像的html页面,我正在将HTML内容解析为iText以生成PDF.在生成的PDF中,未显示包含的图像,仅显示文本.
如果我传递绝对路径,如D:/Deiva/CRs/HTMLPage/article-101-horz.jpg那么图像将被打印.但是如果我尝试从服务器上打印图像就像
http://localhost:8085/content/dam/article-101-h1.jpg or http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif 
那么它不会在PDF中打印出来.
注意:我使用itextpdf-5.2.1.jar生成PDF.
我的HTML代码(Article.html):
<html>
   <head>
   </head>
   <body>   
     <p>Generate PDF with image using iText.</p>
     <img src="http://localhost:8085/content/dam/article-10-h1.jpg"></img>
     <img src="http://www.google.co.in/intl/en_ALL/images/logos/imgs_logo_lg.gif"></img>
     <img class="right horz" src="D:/Deiva/CRs/HTMLPage/article-101-horz.jpg"></img>
   </body>
</html>
我使用以下java代码生成PDF:
private void createPDF (){
  String path = "D:/Deiva/Test.pdf";
  PdfWriter pdfWriter = null;
  //create a new document
  Document document = new Document();
  try {
   //get Instance of the PDFWriter
   pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(path));
   //document header attributes
   document.addAuthor("betterThanZero");
   document.addCreationDate();
   document.addProducer();
   document.addCreator("MySampleCode.com");
   document.addTitle("Demo for iText XMLWorker");
   document.setPageSize(PageSize.LETTER);
   //open …我试图用iTextSharpMVC Razor 将HTML转换为PDF ,但我尝试过的一切都没有用.有谁知道如何做到这一点?
我尝试使用PdfSharp和HtmlRenderer将HTML转换为PDF.这是代码的一部分:
private byte[] CreateHtmlContent()
{
    string htmlContent = File.ReadAllText(@"htmlExample.txt");
    using (MemoryStream ms = new MemoryStream())
    {
        PdfDocument pdfDocument = new PdfDocument();
        PdfDocument pdf = PdfGenerator.GeneratePdf(htmlContent, PdfSharp.PageSize.A4, 60);
        pdf.Save(ms);
        res = ms.ToArray();
    }
    return res;
}
除了分页符,一切正常.在某些页面上,我的结果就像在这张图片上
有可能解决这个问题吗?HTML内容是简单的html,只包含标题和段落,没有其他标签.我对iTextSharp没有这个问题,但在这个项目中我必须使用PdfSharp和MigraDoc.
我正在寻找一个好的,开源的 PDF生成器/库,它将html(带样式等)转换为PDF文件.
需求:
是的,我已经尝试过自己搜索 - 我已经尝试了很多我在Google等上找到的"解决方案".但是还没有让我满意.许多似乎不完整,有缺陷或在GAE上运作不佳.所以我想我会向StackOverflow社区寻求意见或建议.
我们使用wkhtmltopdf将动态html页面转换为pdf.我们需要等到所有的ajax请求都完成.
是否有可能按条件延迟打印?
我需要将包含传单映射的页面导出为pdf.我试图将地图容器转换为图像,但这并不完美.我使用的代码在这里 http://jsfiddle.net/Sq7hg/2/
html2canvas([document.getElementById('mydiv')], {
onrendered: function (canvas) {
    document.getElementById('canvas').appendChild(canvas);
    var data = canvas.toDataURL('image/png');
    console.log(data)
    // AJAX call to send `data` to a PHP file that creates an image from the dataURI string and saves it to a directory on the server
    var image = new Image();
    image.src = data;
    document.getElementById('image').appendChild(image);
}
});
这段代码不能完美地用于传单map.How我可以实现这个吗?
是否有任何类似于Flying Saucer项目的开源.NET项目(或端口),它使用iText将HTML呈现为PDF?
我正在使用jsPDF从连接的 HMTL 字符串生成 PDF 文档。
我需要使用这种方法,而不是getElementById()使用 TypeScript 动态拉取 HTML。
我已经能够从 HTML 字符串生成 PDF 文档,问题是文本在 PDF 上的显示方式 - 它从屏幕右侧拖尾(下图)。
我一直无法找到这个特定问题的答案,并尝试了各种方法来解决这个问题(如下所述),但收效甚微。
我希望有一种更简单的方法,在 jsPDF 库中使用右边距、文本换行或其他一些格式化功能,有人可以指点我吗?
最初,我认为添加下面的margin和width选项可以纠正这个问题。但事实并非如此。
TypeScript 代码(主要功能):
generatePdf() {
    console.log('Generating PDF');
    // (orientation: portrait, units: pt, PDF page size: A4)
    const doc = new jspdf('p', 'pt', 'a4');
    const editor1Content = this.getEditorHtml(this.editorComponent1); // HTML string
    const editor2Content = this.getEditorHtml(this.editorComponent2); // HTML string
    const source = editor1Content + editor2Content; // combined HTML string
    console.log('source: …html-to-pdf ×10
c# ×3
itextsharp ×3
.net ×2
itext ×2
pdf ×2
asp.net ×1
asp.net-mvc ×1
html ×1
java ×1
javascript ×1
jspdf ×1
leaflet ×1
wkhtmltopdf ×1