문제

iTextSharp를 사용하여 프로그래밍 방식으로 PDF를 생성하고 PDFPTVABLE을 생성하고 있습니다.

몇몇 셀에서는 하이퍼 링크가 필요합니다.

하이퍼 링크가없는 i는 셀의 텍스트를 수평 및 수직으로 정렬 할 수 있지만, 하이퍼 링크가 포함 된 청크를 추가하면 셀이 정렬 속성을 느슨하게합니다.

여기 내 코드가 있습니다 ...

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);
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top