あなたの質問は間違っているように聞こえます。ドキュメントに画像の透かしを追加したいようなものです。これは、PDF iText ASP C# ですべてのページに固定背景画像を設定する方法や、私のすべてのページに画像を追加する方法など、他の多くの質問で適切に説明されています。 PDF? (これらの回答は C# の質問に関するものですが、公式 Web サイトには透かしとページ イベントの例が多数あります。)
madheshと同じように、画像にテキストを追加する方法という質問に対する私の回答を読んだ後でも、StackOverflow リーダーを混乱させます。私が書いた場所:
これは、誰も正しく答えられないような言い回しの質問の良い例です。何度もコメントをやり取りした後、OP が画像にテキストの透かしを追加したいことが最終的に明らかになりました。不適切なフレーズの質問は、非常にイライラすることがあります。質問する際はその点を考慮してください。この場合、実際に何を尋ねられたのかが明らかになる前に、私はいくつかの間違った答えを出しました。
に を追加したいのですが、画像にテキストを追加する方法などの質問への回答とともに提供される例を理解して適用するには、知識が不十分PdfPTableです。ItextSharp を使用して PDF の画像に線を描画します。Image
あなたが求めていることは非常に簡単です。
あなたが言及するgetWatermarkedImage()方法は次のようになります。
public Image getWatermarkedImage(PdfContentByte cb, Image img) throws DocumentException {
float width = img.getScaledWidth();
float height = img.getScaledHeight();
PdfTemplate template = cb.createTemplate(width, height);
template.addImage(img, width, 0, 0, height, 0, 0);
template.saveState();
template.setColorStroke(BaseColor.GREEN);
template.setLineWidth(3);
template.moveTo(width * .25f, height * .25f);
template.lineTo(width * .75f, height * .75f);
template.moveTo(width * .25f, height * .75f);
template.lineTo(width * .25f, height * .25f);
template.stroke();
template.setColorStroke(BaseColor.WHITE);
template.ellipse(0, 0, width, height);
template.stroke();
template.restoreState();
return Image.getInstance(template);
}
これは、画像に線を引くにはどうすればよいですか?という質問への回答から取った例です。
線を描画したくないので、線を描画するすべてのコードを削除できます。
public Image getWatermarkedImage(PdfContentByte cb, Image img) throws DocumentException {
float width = img.getScaledWidth();
float height = img.getScaledHeight();
PdfTemplate template = cb.createTemplate(width, height);
template.addImage(img, width, 0, 0, height, 0, 0);
// removed the code that draws lines
return Image.getInstance(template);
}
線の代わりに を描きたいPdfPTableので、 と書かれているところにコードを追加します// removed the code that draws lines。文書化されているように、絶対位置にテーブルを追加するには、次のwriteSelectedRows()メソッドを使用します。
public Image getWatermarkedImage(PdfContentByte cb, Image img) throws DocumentException {
float width = img.getScaledWidth();
float height = img.getScaledHeight();
PdfTemplate template = cb.createTemplate(width, height);
template.addImage(img, width, 0, 0, height, 0, 0);
PdfPTable table = new PdfPTable(2);
table.setTotalWidth(width);
table.getDefaultCell().setBorderColor(BaseColor.Yellow);
table.addCell("Test1");
table.addCell("Test2");
table.addCell("Test3");
table.addCell("Test4");
table.writeSelectedRows(0, -1, 0, height, template);
return Image.getInstance(template);
}
公式ドキュメント ( WatermarkedImages5を参照) の多くの例の 1 つを採用した結果は次のとおりです。

これを実現するために必要なすべての機能は、ドキュメントで利用できました。別の質問を投稿する前に、そのドキュメントをお読みください。