Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 10, 2014 7:47 pm

I have a set of PNG files which need to be part of one PDF document. Can I add as many images as I need to build a single PDF with Spire.PDF for .NET ?

JORGEMAL
 
Posts: 9
Joined: Fri Jan 10, 2014 5:18 pm

Mon Jan 13, 2014 3:54 am

Hello JORGEMAL,

Thanks for your inquiry. Spire.PDF supports adding a set of PNG files to a single PDF file.
And I provide you sample code here, check this:
Code: Select all
PdfDocument doc = new PdfDocument();

PdfPageBase page;
PdfImage image;

//add png files here
String[] str = new String[] { "pic-1.png", "pic-2.png", "pic-3.png" };

for (int i = 0; i < str.Length; i++)
{
    page = doc.Pages.Add();
    image = PdfImage.FromFile(str[i]);
    float width = image.Width * 1f;
    float height = image.Height * 1f;
    float x = (page.Canvas.ClientSize.Width - width) / 2;

    page.Canvas.DrawImage(image, x, 60, width, height);
}

doc.SaveToFile("Image.pdf");
doc.Close();

If you have any questions, please get it back to us.

Best Regards,
Benjamin
E-iceblue support team
User avatar

Benjamin Du
 
Posts: 82
Joined: Thu Jul 25, 2013 2:38 am

Return to Spire.PDF