使用itextsharp将数百个图像添加到pdf

时间:2012-10-24 06:30:12

标签: c# itextsharp

如何使用itextsharp将数百个图像(其实际大小与任何缩小/压缩无关)添加到PDF。我希望以某些表格格式添加这些格式,每个pdf页面修复没有图像。所有图像都是相同的大小。 我该怎么办?

1 个答案:

答案 0 :(得分:3)

您可以尝试使用此代码在pdf中添加图片

Document doc = new Document(PageSize.A4, 10, 10, 30, 30);
MemoryStream PDFData = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, PDFData);
doc.Open();

PdfPTable table = new PdfPTable(1);
table.WidthPercentage = 100F;

Image imgLogo = Image.GetInstance(<image_path>);
PdfPCell cell1 = new PdfPCell { BorderWidth = 0F,  Padding = 3 };
cell1.AddElement(imgLogo);
table.AddCell(cell1);

//Add your more images.

doc.Add(table );
doc.Close();

writer.Close();
相关问题