我正在使用 XMLWorker 将 HTML 字符串解析为 PDF 文档,但找不到控制正在生成的 PDF 的行距的方法。
Document document = new Document(PageSize.LETTER, 72f, 72f, 108f, 90f);
MemoryStream stream1 = new MemoryStream();
PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream1);
document.Open();
//parse HTML into document
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, document, new StringReader(summary.Content));
“summary.Content”是来自数据库字段的 HTML 字符串。
现在,我最近将我们的 ITextSharp 库升级到 5.5.5.0,并升级到新的 XMLWorker 库。使用上面的代码,行距(PDF 中的“前导”)比之前生成的 PDF 小得多。我需要确保行距看起来和以前一样。
我读到我可以在我构建的段落上设置前导,但是当简单地调用 ParseXHtml() 时,这对我没有帮助。我读到 ITextSharp 默认的前导大小是字体大小的 1.5 倍。
我在这里阅读了itextsupport 文档,我可以使用这一行来使用 XML Worker 附带的 default.css。
CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
我认为默认 CSS 可能会生成与我的旧 PDF 具有相同前导的 PDF,但以下代码生成的输出 PDF 与我仅使用 ParseXHtml() 时的输出 PDF 相同。 …
我想转换HTML到PDF在使用iTextSharp的ASP.NET同时使用Web应用程序的MVC,和 网页形式.在<img>和<a>元素有绝对和相对 URL和一些的<img>元素的base64.典型的答案在这里SO和谷歌搜索结果中使用泛型HTML来PDF的代码XMLWorkerHelper看起来是这样的:
using (var stringReader = new StringReader(xHtml))
{
    using (Document document = new Document())
    {
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        document.Open();
        XMLWorkerHelper.GetInstance().ParseXHtml(
            writer, document, stringReader
        );
    }
}
所以这样的样本HTML:
<div>
    <h3>HTML Works, but Broken in Converted PDF</h3>
    <div>Relative local <img>: <img src='./../content/images/kuujinbo_320-30.gif' /></div>
    <div>
        Base64 <img>:
        <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' />
    </div>
    <div><a …我正在尝试创建一个 PDF 文档,其中纵向超过 2 页,其他页面为横向,我发现页面和文本都旋转到横向,我需要防止页面内容旋转。正在使用以下代码
 Document document = new Document(PageSize.A4, 36, 36, 36, 72);
    PdfWriter writer = PdfWriter.getInstance(document, new 
    FileOutputStream(outPutDirectory + indexID + ".pdf"));
    writer.setPageEvent(new Orientation(orientation));
    document.open();
    XMLWorkerHelper.getInstance().parseXHtml(writer,document, new ByteArrayInputStream(parserXHtml(page.getPageContent()).getBytes()))
    document.close();
我的预期结果应该是这样的

我正在使用itextsharp将html转换为pdf.我必须在图像旁边放置文字而不是图像下方.在html中,我能够在图像旁边放置文本,但在pdf中,文本行在图像之后开始
请帮忙.
我有java代码在itext 5.5和xmlworker jars的帮助下编写阿拉伯字符,但是即使在使用writer.setRunDirection(PdfWriter.RUN_DIRECTION_RTL)之后它也是从左到右编写的.
使用的代码是:
public class CreateArabic extends DefaultHandler {
    /** Paths to and encodings of fonts we're going to use in this example */
    public static String[][] FONTS = {
        {"C:/arialuni.ttf", BaseFont.IDENTITY_H},
        {"C:/abserif4_5.ttf", BaseFont.IDENTITY_H},
        {"C:/damase.ttf", BaseFont.IDENTITY_H},
        {"C:/fsex2p00_public.ttf", BaseFont.IDENTITY_H}
    };
    /** Holds he fonts that can be used for the peace message. */
    public FontSelector fs;
     public CreateArabic() {
            fs = new FontSelector();
            for (int i = 0; i < FONTS.length; i++) {
                fs.addFont(FontFactory.getFont(FONTS[i][0], FONTS[i][1], BaseFont.EMBEDDED));
            }
        } …我有一个带有示例的字符串 - 它的效果非常好,但是当我添加波兰字母时,它们就消失了.我试过这样的事情:
        byte[] byteArray = str.getBytes(Charset.forName("UTF-8"));
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
        worker.parseXHtml(pdfWriter, document, byteArrayInputStream, Charset.forName("UTF-8"));
但它没有改变任何东西.如何添加波兰字母?
编辑:它仍然无法正常工作.
码:
        document.open();
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        String str = "<html><head></head><body style=\"font-size:12.0pt; font-family:Times New Roman\">"+
                "<a href='http://www.rgagnon.com/howto.html'><b>Real's HowTo</b></a>" +
                "<h1>Show your support</h1>" +
                "<p>It DOES cost a lot to produce this site - in ISP storage and transfer fees</p>" +
                "<p>TEST POLSKICH ZNAKÓW: ???CÓó????????</p>" +
                "<hr/>" +
                "<p>the huge amounts of time it takes for one person to design and write the actual …我用Itext和创建PDF xmlworker.我的问题是我想在新页面中创建内容.以下是我的代码.
File file = new File("D:/PDFFiles/Sathesh.pdf");
FileOutputStream fos=new FileOutputStream(file);
Document doc=new Document(PageSize.A4, 50, 50, 70, 70);
PdfWriter pdfWriter=PdfWriter.getInstance(doc, fos);
doc.open();
XMLWorkerHelper worker=XMLWorkerHelper.getInstance();
String firstString="<table><tr><td>First Page</td></tr></table>" ;
String secondString="<table><tr><td>Second Page</td></tr></table>" ; 
String final=firstString+secondString;
ByteArrayInputStream is = new ByteArrayInputStream(final.getBytes());
worker.parseXHtml(pdfWriter, doc, is);
doc.close();
fos.close();
我希望firstString在第一页和secondString页面中.等待你的答复.
我正在将 ElementList 中的元素添加到 PdfPCell。这些元素可以是从简单的文本短语到要点列表的任何内容。但是,将这些元素打印到 pdf 的字体太大了。所以,我的问题是:如何调整解析为 pdf 的元素的默认字体大小。
我知道如何使用 paragrhaps,您可以在其中输入字符串和字体作为参数,但是在向单元格添加元素时如何执行此操作,如下所示:
PdfPCell cell = new PdfPCell();
for (Element e : XMLWorkerHelper.parseToElementList(HTML, CSS)) {   
    cell.addElement(e);
}
table.addCell(cell);
我正在尝试编写一个应用程序,它将触发我在ASP.NET中构建的一系列Web报表.所以我有一个Web应用程序,其中页面存在,但我真的不想使用该网站查看页面,我想创建我可以提供给我的客户的PDF.
我正在尝试编写的应用程序是一个控制台应用程序,在c#中使用Visual Studio 2010编写并使用iTextSharp v5.5.2和.NET 4.5.它目前只是一个框架,因为我尚未完成"解雇PDF"部分.我正在从网上访问一个页面并试图将其保存为PDF,但我找不到任何有关我得到的编译错误的信息.我在应用程序中有以下Using指令:
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.xml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using iTextSharp.text.io;
using iTextSharp.text.xml.simpleparser;
using iTextSharp.text.html.simpleparser;
namespace ConsoleApplication1
{
    public partial class BuildReports : System.Web.UI.Page
    {
        static void Main(string[] args)
        {
            WebRequest wReq = WebRequest.Create("http://www.somesite.com/");
            WebResponse wRsp = null;
            try
            {
                wRsp = wReq.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} exception caught.", …