简体   繁体   English

使用itextsharp在pdf中并排添加图像

[英]Adding images side by side in pdf using itextsharp

I am writing some data to the pdf using itextsharp. 我正在使用itextsharp将一些数据写入pdf。 I am adding 2 images. 我要添加2张图片。 I used this code: 我使用以下代码:

 iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(System.Windows.Forms.Application.StartupPath + "\\t.jpg");
 iTextSharp.text.Image img2 = iTextSharp.text.Image.GetInstance(System.Windows.Forms.Application.StartupPath + "\\teiasLogo.jpg");
 pdfDocCreatePDF.Add(img);
 pdfDocCreatePDF.Add(img2);

I want to see them like that : 我想这样看他们: 图片

As a result I don't want new line ( \\n ) between the images, I want spaces. 结果,我不需要图像之间的换行符(\\ n),而是要留空格。 How can I do that? 我怎样才能做到这一点? Thanks.. 谢谢..

You can produce that by using PdfPTable. 您可以使用PdfPTable生成该文件。 Create a new table. 创建一个新表。 Then you can assign your images to each cell (with border=0). 然后,您可以将图像分配给每个单元格(border = 0)。

 PdfPTable resimtable = new PdfPTable(2); // two colmns create tabble
 resimtable.WidthPercentage = 100f;//table %100 width
 iTextSharp.text.Image imgsag = iTextSharp.text.Image.GetInstance(Application.StartupPath+"/sagkulak.jpg");
iTextSharp.text.Image imgsol = iTextSharp.text.Image.GetInstance(Application.StartupPath + "/sagkulak.jpg");
resimtable.AddCell(imgsag);//Table One colmns added first image
resimtable.AddCell(imgsol);//Table two colmns added second image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM