如何将图像转换为单个pdf?
问题描述:
我在一个文件夹中有多个图像。我想在c#中找到该文件夹,然后所有图像都成为单个pdf。
我如何使用免费组件?
I have number of images in a folder.I want to address the folder in c# and then all the images become a single pdf.
How can I do it with free component?
答
试着看看
将图像文件转换为PDF [ ^ ]
我正在使用PDFSharp。如果您使用它,那么您可以尝试以下代码:
I am using PDFSharp. If you use it then you can try the following code:
using(PdfDocument doc = new PdfDocument())
{
using(Image myimage = Image.FromFile(ImageFilePath))
{
PdfPage page = new PdfPage();
page.Width = myimage.Width + 20;
page.Height = myimage.Height + 20;
doc.Pages.Add(page);
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(fileName);
xgr.DrawImage(img, 10, 10, myimage.Width, myimage.Height);
doc.Save(PathToSavePDFDoc);
doc.Close();
}
}
要获取有关PDFSharp的信息,请转到 http://www.pdfsharp.net/wiki/ [ ^ ]