【问题标题】:How to "float" an image in a cell - iTextPDF如何“浮动”单元格中的图像 - iTextPDF
【发布时间】:2011-11-03 16:58:24
【问题描述】:

我正在尝试创建一个格式化的 PdfPCell,其中我的文本位于左侧,图像(QRCode)“浮动”(在 css 意义上)到右侧。我当前的代码将图像向右移动,但文本在下一行与图像不同。

想法?

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

【问题讨论】:

    标签: java pdf-generation itext


    【解决方案1】:

    你可以试试替换

    img.setAlignment(Element.ALIGN_RIGHT);
    

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

    【讨论】:

      【解决方案2】:

      试试这个。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-11
        • 2011-05-21
        • 2020-03-17
        • 1970-01-01
        • 2011-05-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多