質問

BIRT レポートライブラリを使用してPDFファイルを作成しています。後でこれらのファイルにデジタル署名する必要があります。 iText を使用して、ドキュメントにデジタル署名します。

私が直面している問題は、異なるレポートの異なる場所に署名を配置する必要があるということです。ドキュメントにデジタル署名するためのコードは既にありますが、現在は常にすべてのレポートの最後のページの下部に署名を配置しています。

最終的に、各レポートに署名を配置する必要がある場所を伝える必要があります。次に、iTextを使用して場所を読み取り、その場所に署名を配置する必要があります。

BIRTとiTextを使用してこれを達成することは可能ですか

ありがとう

役に立ちましたか?

解決

少しごまかしたい場合は、リンクを使用できます。BIRTがサポートしているのは、今のドキュメントの詳細です。

リンクは注釈です。悲しいことに、iTextはアノテーションを高レベルで調べることをサポートせず、それらを生成するだけなので、低レベルのオブジェクト呼び出しを使用する必要があります。

それを抽出するコードは次のようになります:

// getPageN is looking for a page number, not a page index
PdfDictionary lastPageDict = myReader.getPageN(myReader.getNumberOfPages());

PdfArray annotations = lastPageDict.getAsArray( PdfName.ANNOTS );
PdfArray linkRect = null;
if (annotations != null) {
  int numAnnots = annotations.size();
  for (int i = 0; i < numAnnots; ++i) {
    PdfDictionary annotDict = annotations.getAsDict( i );
    if (annotDict == null) 
      continue; // it'll never happen, unless you're dealing with a Really Messed Up PDF.

    if (PdfName.LINK.equals( annotDict.getAsName( PdfName.SUBTYPE ) )) {
      // if this isn't the only link on the last page, you'll have to check the URL, which
      // is a tad more work.
      linkRect = annotDict.getAsArray( PdfName.RECT );

      // a little sanity check here wouldn't hurt, but I have yet to come across a PDF
      // that was THAT screwed up, and I've seen some Really Messed Up PDFs over the years.

      // and kill the link, it's just there for a placeholder anyway.
      // iText doesn't maintain any extra info on links, so no need for other calls.
      annotations.remove( i ); 
      break;
    }
  }
}

if (linkRect != null) {
  // linkRect is an array, thusly: [ llx, lly, urx, ury ].
  // you could use floats instead, but I wouldn't go with integers.  
  double llx = linkRect.getAsNumber( 0 ).getDoubleValue(); 
  double lly = linkRect.getAsNumber( 1 ).getDoubleValue();
  double urx = linkRect.getAsNumber( 2 ).getDoubleValue();
  double ury = linkRect.getAsNumber( 3 ).getDoubleValue();

  // make your signature
  magic();
}

BIRTが視覚的表現のためにリンクの下のページコンテンツにテキストを生成する場合、それは小さな問題です。署名で完全にカバーする必要があります。

最初にBIRTから直接署名を生成できるなら、間違いなく優れていますが、ドキュメントの私の小さな検査では、PDFカスタマイズ機能に自信がありませんでした... iText自体の。それはたまたまPDFを生成できるレポートジェネレーターです... あまりにも期待するべきではありません。 `

編集:特定のURLを探す必要がある場合は、「12.5.6.5リンクアノテーション」セクションをご覧ください。ここにあるPDFリファレンスの http://www.adobe.com/content /dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf

他のヒント

BIRTについては何も知りませんが、iTextについては少しだけ知っています。しかし、おそらくこれは動作します...

BIRTは、署名ボックスのアウトラインを、指定されたフィールド名を持つ通常のフォームフィールドとして生成できますか?その場合、次のことができるはずです。

  1. getFieldを使用して、iTextのAcroFieldsハッシュマップで名前でそのフィールドを検索します。
  2. pdfスタンパーを使用して新しい署名を作成し、古いフィールドオブジェクトの値に基づいてジオメトリを設定します。そして
  3. removeFieldを使用して古いフィールドを削除します。
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top