itextSharp pdfpcellチャンクとの配置
-
21-12-2019 - |
質問
ITextSharpを使用してプログラムでPDFを作成し、PDFPTableを生成しています。
いくつかの細胞では、私はハイパーリンクを持つ必要があります。
ハイパーリンクなしで、セル内のテキストを水平方向と垂直方向に揃えることができますが、ハイパーリンクを含むチャンクに追加すると、セルはそのアライメントプロパティを失います。
これは私のコードです...
var webAddress = new Chunk(row["product_code"].ToString(), linkFont);
webAddress.SetAnchor(row["url"].ToString());
PdfPCell ProductCodeCell = new PdfPCell();
ProductCodeCell.AddElement(webAddress);
ProductCodeCell.VerticalAlignment = Element.ALIGN_MIDDLE;
ProductCodeCell.HorizontalAlignment = Element.ALIGN_CENTER;
ProductCodeCell.Padding = 3f;
table.AddCell(ProductCodeCell);
.
誰もがリンクを再調整するのを手伝ってくれる?
感謝します。
解決
AddElement()
を使用する場合は、セル自体の代わりにオブジェクトのアライメントを設定する必要があります。ただし、Chunk
にはアラインメントがありません。そのため、Paragraph
であるものにあなたのチャンクをラップする必要があります。
var table = new PdfPTable(1);
//Create our chunk with anchor
var webAddress = new Chunk("hello");
webAddress.SetAnchor("http://www.example.net/");
//Create a paragraph holding the chunk and set the alignment on _it_
var para = new Paragraph(webAddress);
para.Alignment = Element.ALIGN_CENTER;
//Create our cell
PdfPCell ProductCodeCell = new PdfPCell();
//Add the paragrph to it
ProductCodeCell.AddElement(para);
//Padding on the cell still works
ProductCodeCell.Padding = 30f;
//Add cell to table
table.AddCell(ProductCodeCell);
. 所属していません StackOverflow