2016-10-10 5 views
3

テーブルを備えたPDF文書があります。次されているコード:iText 7を使用して、セル内の画像を囲むテキストを囲みます。

PdfWriter _writer = new PdfWriter(@"C:\output.pdf"); 
PdfDocument _document = new PdfDocument(_writer); 
Document MyDocument = new Document(_document, PageSize.A4); 

Table MyTable = new Table(new float[] { 1, 4 }); 
MyTable.SetWidthPercent(100); 
MyTable.AddHeaderCell(new Cell().Add(new Paragraph("ID"))); 
MyTable.AddHeaderCell(new Cell().Add(new Paragraph("Description"))); 

MyTable.AddCell(new Cell().Add(new Paragraph("1"))); 
Cell descCell = new Cell(); 
descCell.Add(IMG); // iText.Layout.Element.Image 
descCell.Add(new Paragraph("This is the description.")); 
MyTable.AddCell(descCell); 

MyDocument.Add(MyTable); 
MyDocument.Close(); 

は、実際に出力がこれです:私が達成しようとしています何

enter image description here

これです:

enter image description here

私はいくつかの試験を読んだiText 5のplesとこのプロパティを使用するすべてのポイント:

image.setAlignment(Image.LEFT | Image.TEXTWRAP);

問題は、任意の助けをいただければ幸いですiTextの7

にavaliableであるように思わないことです。

+0

浮動イメージは現在iText7ではサポートされていませんが、ロードマップ上にあります。 –

答えて

2

フローティングエレメント機能は7.0.3-SNAPSHOTに実装されており、7.0.3リリースになる可能性があります。

テキストがセルの画像を囲むようにするには、HTMLの場合と同じように画像が浮動要素であることを指定する必要があります。これを行うには、次に

Image img = ... 
img.setProperty(Property.FLOAT, FloatPropertyValue.LEFT); 

を使用し、そこに画像やテキストを追加することによって、いつものようにセルを構成する:

enter image description here

table.addCell(new Cell().add(img).add(textStr); 

出力は次のようになります。

関連する問題