0

iTextSharpを使用して既存のPDFドキュメントのAcroFormフィールドのフォントを変更しているときに、「textfont」プロパティを設定している行でnullポインター例外が発生します。ただし、同じコードを使用してフィールドの値を設定することはできます。次の例に従って、コードを作成しました https://stackoverflow.com/questions/14748901/custom-font-not-getting-applied-on-existing-pdf-template-itextsharppdfstamper

私のスタックトレースは次のようになります。

at iTextSharp.text.pdf.PdfContentByte.SaveColor(BaseColor color, Boolean fill)
at iTextSharp.text.pdf.PdfContentByte.SetRGBColorFill(Int32 red, Int32 green, Int32 blue)
at iTextSharp.text.pdf.PdfContentByte.SetColorFill(BaseColor value)
at iTextSharp.text.pdf.AcroFields.SetFieldProperty(String field, String name, Object value, Int32[] inst)
at iTextSharpUsage.Utilities.UpdateFontUsingEmbededFont(String inputPdf, String resultPdf) in D:\iTextSharpUsage\iTextSharpUsage\iTextSharpUsage\Utilities.cs:line 229

私のコードは次のようになります。

var pdfReader = new PdfReader(inputPdf);
string fontsfolder = @"D:\Airmole\airmole.ttf";
var pdfStamper = new PdfStamper(pdfReader, new FileStream(resultPdf, FileMode.Create));
BaseFont customfont = BaseFont.CreateFont();
AcroFields af = pdfStamper.AcroFields;
List<BaseFont> list = new List<BaseFont>();
list.Add(customfont);
iTextSharp.text.Font bold = new iTextSharp.text.Font(customfont, 13,0,BaseColor.BLACK);
af.SubstitutionFonts = list;
foreach (var field in af.Fields)
{
    af.SetField(field.Key, "s");
    //this line works fine
    bool isSuccess = pdfStamper.AcroFields.SetFieldProperty(field.Key, "textcolor ", BaseColor.BLACK , null);
    //the line bellow throws a null pointer exception
    bool isSucces1s = pdfStamper.AcroFields.SetFieldProperty(field.Key, "textfont", customfont, null);
}

これを機能させるには、さらにコードを追加する必要がありますか?

ここでの簡単な更新...@Brunoによって投稿されたコメントのおかげで問題は解決しました、この機能はバージョン5.3.3で正常に機能します。

4

1 に答える 1

0

あなたがPDFを共有しなかったので、私は私が作成したいくつかのPDFでいくつかのテストを行いました。/NeedAppearances設定がtrueの形式で事前入力されたフィールドがフラット化されていない(空のフィールドとして表示された)場合を見つけました。私はいつもfalse(デフォルト)のフォームで作業してい/NeedAppearancesので、問題が発生することはなかったと思います。私はこれを修正しました:http ://sourceforge.net/p/itext/code/5682/

修正は次のリリースで行われます。

于 2013-02-08T11:51:59.643 に答える