Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在PdfCell中添加包含文本的图像?_Java_Image_Pdf_Itext - Fatal编程技术网

Java 如何在PdfCell中添加包含文本的图像?

Java 如何在PdfCell中添加包含文本的图像?,java,image,pdf,itext,Java,Image,Pdf,Itext,我试图在PdfCell中添加一个后跟文本的图像。到目前为止,我所能达到的最好效果就是将图像置于文本之上。但是,我希望图像位于同一行文本的左侧。以下是我当前的代码: PdfCell cell = new PdfCell() cell.addElement(myImage); Chunk staffChunk = new Chunk("This is my text"); staffChunk.setFont(font); Paragraph p = new Paragraph(staffChunk

我试图在PdfCell中添加一个后跟文本的图像。到目前为止,我所能达到的最好效果就是将图像置于文本之上。但是,我希望图像位于同一行文本的左侧。以下是我当前的代码:

PdfCell cell = new PdfCell()
cell.addElement(myImage);
Chunk staffChunk = new Chunk("This is my text");
staffChunk.setFont(font);
Paragraph p = new Paragraph(staffChunk);
cell.addElement(p);

我已经做了
myImage.setAlignment(Image.LEFT)
。文本仍显示在图像下方。

您需要将图像和文本作为块添加到段落中,然后将此段落添加到单元格中:

Paragraph p = new Paragraph() { new Chunk(itextImg, 0, 0), "Hello World" };

您是否尝试过将
图像
包装在
块中
?最终使其工作如下:段落p=新段落(新块(groupImage,0,0));p.add(textcunk);