PDF文件使用iTextSharp的给错误在第一个打印命令时产生的 [英] PDFs generated using itextsharp giving error at the time of first print command

查看:908
本文介绍了PDF文件使用iTextSharp的给错误在第一个打印命令时产生的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到下面的第一次给打印命令。

I am getting below for the first time giving print command.

此页面上存在错误,Acrobat可能无法正确​​显示页面,请 联系谁创造了PDF文档解决该问题的人。

"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".

打印出正在添加是非常精细的。而第二次打印命令没有给出任何错误。

Print out is comming very fine. and Second time print out command not giving any error.

请帮我为什么这个错误是正在添加的第一次印刷。

Please help me why this error is comming for the first time print.

这是我的code创建PDF一部分

This is part of my code to create PDF

PdfContentByte cb = writer.DirectContent;
cb.BeginText();
Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);
// Add an image to a fixed position 
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(Server.MapPath("~/images/images/banner.tiff"));
img.SetAbsolutePosition(35, 760);
img.ScalePercent(50);
cb.AddImage(img);
// Draw a line by setting the line width and position
cb.SetLineWidth(2);
cb.MoveTo(20, 740);
cb.LineTo(570, 740);
cb.Stroke();
//Header Details
cb.BeginText();
writeText(cb, drHead["EmpName"].ToString(), 25, 745, f_cb, 14);
writeText(cb, "Employee ID:", 450, 745, f_cn, 12);
writeText(cb, drHead["EmployeeID"].ToString(), 515, 745, f_cb, 12);
cb.EndText();
cb.BeginText();
writeText(cb, "XXXX:", 25, 725, f_cb, 8);
cb.EndText();
cb.SetLineWidth(2);
cb.MoveTo(20, 675);
cb.LineTo(570, 675);
cb.Stroke();
cb.EndText();
// Acknowledgement section
cb.BeginText();
writeText(cb, "XXXXXXXXXXXXXXXX", 20, 140, f_cb, 12);
cb.EndText();
cb.EndText();

请帮我知道什么是问题。

Please help me to know what is the issue.

推荐答案

您已经嵌套的文本块。这是非法的PDF语法。我觉得最近iTextSharp的版本警告你这一点,所以我想您使用的是旧版本。

You have nested text blocks. That's illegal PDF syntax. I think recent versions of iTextSharp warn you about this, so I guess you're using an old version.

这是错误的:

cb.BeginText();
...
cb.BeginText();
...
cb.EndText();
...
cb.EndText();

这是正确的:

cb.BeginText();
...
cb.EndText();
...
cb.BeginText();
...
cb.EndText();

此外:ISO-32000-1告诉你,有些操作是在文本块内禁止

Moreover: ISO-32000-1 tells you that some operations are forbidden inside a text block.

这是错误的:

cb.BeginText();
...
cb.AddImage(img);
...
cb.EndText();

这是正确的:

cb.BeginText();
...
cb.EndText();
...
cb.AddImage(img);

最后,有些运营商创造一个文本块时,是强制性的。例如:你总是需要 setFontAndSize()(我不知道你在做的 WRITETEXT什么() ,但我相信你正确设置字体)。

Finally, some operators are mandatory when creating a text block. For instance: you always need setFontAndSize() (I don't know what you're doing in writeText(), but I assume you're setting the font correctly).

在任何情况下:您已选择使用iTextSharp的最低水平,几乎是手工编写的PDF语法。这是假设你知道ISO-32000-1内而外。如果不这样做,你应该使用一些高层次的对象,如 Col​​umnText 中以绝对位置位置的内容。

In any case: you have chosen to use iTextSharp at the lowest level, writing PDF syntax almost manually. This assumes that you know ISO-32000-1 inside-out. If you don't, you should use some of the high-level objects, such as ColumnText to position content at absolute positions.

这篇关于PDF文件使用iTextSharp的给错误在第一个打印命令时产生的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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