使用itextsharp将文本放在图像html到pdf旁边 [英] place text next to image html to pdf using itextsharp
本文介绍了使用itextsharp将文本放在图像html到pdf旁边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用itextsharp将html转换为pdf。我必须将文字放在图像旁边的图像旁边。在html中,我可以将文本放置在图片旁边,但在pdf中,文本行在图片后开始。
I am converting html to pdf using itextsharp. I have to place text next to the image not below the image. In html I am able to place text next to image but in pdf the text line starts after image
请帮助。
推荐答案
由于您提到了HTML,您了解了 block 和 inline 显示,对吗?通过类推,iTextSharp的默认 Image
显示是 block 。至 inline 图片
您需要的物件:
$ b
Since you mention HTML, you understand block and inline display, right? By analogy, iTextSharp's default Image
display is block. To inline Image
objects you need to:
- 将图像添加到
Chunk
对象 - 在
短语
对象中添加文字(s) - 然后将这些对象添加到
段落
对象
- Add images to
Chunk
object(s) - Add text in
Phrase
object(s) - Then add those object to a
Paragraph
object
类似于这样:
Something like this:
Image image = Image.GetInstance(imagePath);
Paragraph p = new Paragraph();
p.Add(new Phrase("Text next to the image "));
p.Add(new Chunk(image, 0, 0));
p.Add(new Phrase(" and text after the image."));
document.Add(p);
将 imagePath
替换为物理路径您的图片
Replace imagePath
above with the physical path to your image
这篇关于使用itextsharp将文本放在图像html到pdf旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文