使用itextsharp将文本放在图像html到pdf旁边 [英] place text next to image html to pdf using itextsharp

查看:111
本文介绍了使用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:


  1. 将图像添加到 Chunk 对象

  2. 短语对象中添加文字(s)

  3. 然后将这些对象添加到段落对象

  1. Add images to Chunk object(s)
  2. Add text in Phrase object(s)
  3. 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屋!

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