iTextSharp ColumnText.SetSimpleColumn Addtext在Adobe Reader X 10.1.5中导致错误 [英] iTextSharp ColumnText.SetSimpleColumn Addtext causes Error in Adobe Reader X 10.1.5

查看:1196
本文介绍了iTextSharp ColumnText.SetSimpleColumn Addtext在Adobe Reader X 10.1.5中导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码说明了iTextSharp的一个问题。一切都很完美。 pdf文件已创建并在屏幕上显示正确。当我从Adobe Reader X打印pdf时,它看起来完全正确,但Adobe报告此页面上存在错误.Acrobat可能无法正确显示页面。请联系创建PDF文档的人员以解决问题。

The code below illustrates a problem I have with iTextSharp. Everything works perfectly. The pdf file is created and appears correct on the screen. When I print the pdf from Adobe Reader X, it looks exactly right but Adobe reports "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem."

不幸的是,该文件必须附加到电子邮件并发送给客户。错误消息不好看,我想解决它。它发生在我尝试过的所有Reader版本中,包括今天安装的10.1.15。

Unfortunately, the file has to be attached to an email and sent to clients. The error message is not a good look and I want to fix it. It happens in all versions of Reader that I have tried, including 10.1.15 installed today.

我在Windows 7 Pro SP1下有iTextSharp 5.3.4.0

I have iTextSharp 5.3.4.0 under Windows 7 Pro SP1

    private void writeTestDoc()
    {
        string fname = "test.pdf";
        float textWidth = 500;
        float leftMgn = 60;
        float rubricTop = 720;
        float leftPad = 5;
        float topPad = 12;
        float leading = 0;
        BaseFont baseCalibri = BaseFont.CreateFont("c:/windows/fonts/calibri.ttf", BaseFont.WINANSI, true);
        Font plainFont = new Font(baseCalibri, 11, Font.NORMAL);
        Document document = new Document();
        try
        {
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fname, FileMode.Create));
            document.Open();
            PdfContentByte cb = writer.DirectContent;
            cb.BeginText();
            ColumnText ct = new ColumnText(cb);
            float boxTop = rubricTop;
            ct.SetSimpleColumn(leftMgn + leftPad, boxTop - topPad, leftMgn + textWidth, boxTop, leading, Element.ALIGN_CENTER);
            ct.AddText(new Phrase("A test message", plainFont));
            ct.Go();
            cb.EndText();
            document.Close();
        }
        catch (Exception ex)
        {
            writeFile("ERROR in writeTestDoc " + ex.Message);
        }
    }


推荐答案

删除 cb.BeginText(); cb.EndText(); BT / ET 要嵌套的文本对象是非法的。报告您找到文档的地方,该文档告诉您使用 BeginText() / EndText ColumnText ,以便我们可以要求作者从他或她的文档中更正它。

Remove cb.BeginText(); and cb.EndText();. It's illegal for BT/ET text objects to be nested. Report the place where you've found the documentation that told you to use BeginText()/EndText in combination with ColumnText, so that we can ask the author to correct it from his or her documentation.

这篇关于iTextSharp ColumnText.SetSimpleColumn Addtext在Adobe Reader X 10.1.5中导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆