2011-11-03 32 views
2

我想創建一個格式化的PdfPCell,其中我的文本在左側,圖像(QRCode)「浮動」(在css意義上)向右。我目前的代碼將圖像移動到右側,但文本在下一行,與圖像不在同一行。如何「漂浮」一個單元格中的圖像 - iTextPDF

想法?

PdfPCell cell = new PdfPCell(); 
    Paragraph p = new Paragraph(); 
    p.add(new Paragraph("Ciao Baby",RESTNAME)); 
    BarcodeQRCode qrcode = new BarcodeQRCode("http://www.tvfoodmaps.com", 72, 72, null); 
    Image img = qrcode.getImage(); 
    img.scaleToFit(32,32); 
    img.setAlignment(Element.ALIGN_RIGHT); 
    cell.addElement(img); 
    cell.addElement(p); 

回答

2

你可以嘗試用

img.Alignment = Image.TEXTWRAP | Image.ALIGN_RIGHT; 
0

更換

img.setAlignment(Element.ALIGN_RIGHT); 

試試這個。

Phrase phrase = new Phrase("Ciao Baby",RESTNAME); 
BarcodeQRCode qrcode = new BarcodeQRCode("http://www.tvfoodmaps.com", 72, 72, null); 
Image img = qrcode.getImage(); 
img.scaleToFit(32,32); 
phrase.add(new Phrase(new Chunk(img, 0, 0))); 
cell.addElement(phrase);