Add Image to PDF (.NET Core/Framework)
Images can be added to a PDF easily using DynamicPDF Core Suite. Different image formats (GIF, JPEG, JPG, JPEG2000, PNG, BMP, EMF, EXIF, TIFF, Multi Page Tiff, TIFF to PDF, WMF and Transparent Images) can be added to a PDF document.
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 the Document instance. - Create an
Image
object. - Add the
Image
object to the Page 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 the Document 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");
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