简体   繁体   English

使用ItextSharp生成PDF时出错

[英]Error While Generating PDF using ItextSharp

I am Creating a PDF using ItextSharp 5.0.5 我正在使用ItextSharp 5.0.5创建PDF

Used follwing Code 使用以下代码

1) 1)

var _with1 = underContent;
_with1.SaveState();
_with1.SetGState(gstate);
_with1.SetColorFill(color);
_with1.BeginText();
_with1.SetFontAndSize(font, txt_Font2);
_with1.SetTextMatrix(30, 30);

//**1**//

_with1.ShowTextAligned(Element.ALIGN_CENTER, watermarkText, txt_X2, txt_Y2, txt_Rotat2);

//**1**//

_with1.EndText();
_with1.RestoreState();

2) 2)

//**2**//

ColumnText.ShowTextAligned(_with1, Element.ALIGN_CENTER, new Phrase(new Chunk(watermarkText, FontFactory.GetFont(@"C:\WINDOWS\Fonts\" + FntNm + ".TTF", txt_Font2, 0))), txt_X2, txt_Y2, txt_Rotat2);

//**2**//

Replacing //**1**// with //**2**// i am getting Following Error //**2**//替换//**1**//我得到以下错误

错误

i need to use // 2 // for generating UNDERLINE which is not supported in BaseFont of iTextsharp 我需要使用// 2 //来生成UNDERLINE,这在iTextsharp的BaseFont中是不受支持的

Please Help!! 请帮忙!!

You are nesting text objects! 你正在嵌套文本对象! That's illegal. 那是违法的。 More recent iTextSharp versions warn you about this problem. 最新的iTextSharp版本警告您这个问题。

Bottom line: you need to remove at least the following lines: 底线:您需要删除至少以下行:

_with1.BeginText();
_with1.SetFontAndSize(font, txt_Font2);
_with1.SetTextMatrix(30, 30);
_with1.EndText();

The whole idea of using the ColumnText method is that you don't have to worry about creating the text object yourself (as explained in Chapter 3 of my book). 使用ColumnText方法的整个想法是您不必担心自己创建文本对象(如我的书的第3章所述)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM