Add Images to PDF
Add images to a PDF using DynamicPDF Core Suite. Image formats include GIF, JPEG, JPG, JPEG2000, PNG, BMP, EMF, EXIF, TIFF, multi-page Tiff, TIFF to PDF, WMF, and transparent images.
How to Add Image to PDF in C#
The following steps and sample code add an image to a PDF document using DynamicPDF Core Suite.
Steps for Adding an image to a PDF Document
- Create a
Document
object. - Create a
Page
object and add to theDocument
instance. - Create an
Image
object. - Add the
Image
object to thePage
instance. - Save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Image image = new Image(@"MyImage.jpg", 0, 0);
page.Elements.Add(image);
document.Draw(@"MyDocument.pdf");
How to Add Background Image to PDF in C#
Adding a background image to a PDF using DynamicPDF Core Suite is straightforward. Use the BackgroundImage
class to place and stretch an image to the dimensions of a page. The following steps and sample code illustrate adding a Background Image to a PDF document using DynamicPDF Core Suite.
Steps for Adding Background Image to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
BackgroundImage
object by specifying the image path. - Place the image within the page margins.
- Add
BackgroundImage
instance to thePage
instance. - Save the PDF.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
BackgroundImage backgroundImage = new BackgroundImage(imagePath);
backgroundImage.UseMargins = true;
page.Elements.Add(backgroundImage);
document.Draw(@"Output.pdf");
GitHub Project
Clone or view the example project at GitHub. This example code is contained in the Examples/AddImageExample.cs file.
Getting Started
NuGet Package
The easiest way to install DynamicPDF Core Suite is by using the Visual Studio Package Manager. However, you can also download the NuGet package directly.
DynamicPDF Core Suite Information
For more information on DynamicPDF Core Suite, refer to the following web page.
Available on Other Platforms
The DynamicPDF Core Suite is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX