在文本模式下使用ColumnText时如何在iText中添加嵌入式图像 [英] How to add inline images in iText when using ColumnText in text mode

查看:73
本文介绍了在文本模式下使用ColumnText时如何在iText中添加嵌入式图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void processImage(Phrase phrase, Picture picture, ColumnText column)
{
    // TODO Auto-generated method stub
    byte[] pictureData = picture.getContent();
        float ls = 12.0f;
        float multiline = 1.0f;
        column.setLeading(ls, multiline);
        pictureData = WordToPdfUtils.getMetaFileAsImage(pictureData);           

    if (pictureData != null) {
        try {
            Image pic = Image.getInstance(pictureData);
            float[] scwh = scaleInlinePicture(picture);
            pic.scaleAbsolute(scwh[0], scwh[1]);
            phrase.add(new Chunk(pic, 0, 0, true)); 
            column.addText(phrase);         
        } catch (BadElementException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

当我将包含嵌入式图像的短语添加到ColumnText时,该图像似乎在生成的pdf的上述段落中重叠,如何在使用ColumnText时添加嵌入式图像. 与此问题一起生成的示例pdf文件的链接如下

When i add phrase containing inline image to the ColumnText, the image appears to overlap on the above paragraphs in the generated pdf, how to add inline images while working with ColumnText. A link to sample pdf file generated with the issue is as below

带有内嵌图片问题的pdf示例 谢谢.

推荐答案

请查看 ColumnTextChunkImage 示例.它添加了一个文本,其中包含包裹在Chunk中的图像.根据图像的高度自动调整引线:

Please take a look at the ColumnTextChunkImage example. It adds a text containing images wrapped in a Chunk. The leading is adapted automatically based on the height of the images:

实现此目标的代码与您的代码非常相似:

The code to achieve this is very similar to yours:

Image dog = Image.getInstance(DOG);
Image fox = Image.getInstance(FOX);
Phrase p = new Phrase("quick brown fox jumps over the lazy dog.");
p.add("Or, to say it in a more colorful way: quick brown ");
p.add(new Chunk(fox, 0, 0, true));
p.add(" jumps over the lazy ");
p.add(new Chunk(dog, 0, 0, true));
p.add(".");
ColumnText ct = new ColumnText(writer.getDirectContent());
ct.setSimpleColumn(new Rectangle(50, 600, 400, 800));
ct.addText(p);
ct.go();

我看到的唯一明显区别是您使用:

The only apparent difference I see, is that you use:

column.add(phrase);

此方法在iText的正式版本中不存在.您可以使用addText()(文本模式)或addElement()(复合模式).我的猜测是您使用的是非官方的iText版本.不幸的是,有些人使用FFF原理创建了iText的分支:Fork,F ***,Forget.如果您使用的是这样的叉子,并且不想被人遗忘或遗忘,请切换到使用iText的官方版本.

This method doesn't exist in the official version of iText. You either have addText() (text mode) or addElement() (composite mode). My guess is that you're using an unofficial version of iText. Unfortunately some individuals have created forks of iText using the FFF principle: Fork, F***, Forget. If you are using such a fork and you don't want to be f***ed or forgotten, please switch to using an official version of iText.

这篇关于在文本模式下使用ColumnText时如何在iText中添加嵌入式图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆