Articles in this section
Category / Section

How to draw image with specified size in PDF document using C# and VB.NET

4 mins read

The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library that is used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can draw an image with a specified size in PDF document using C# and VB.NET.

Steps to draw an image with a specified size in PDF document using C# programmatically

1. Create a new C# console application project.

Create Console application

2. Install the Syncfusion.PDF.WinForms NuGet packages as a reference to your .NET Framework application from NuGet.org.

Install NuGet packages

3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics

 

4. The following code example shows how to draw an image with a specified size in a PDF document using C#.

C#

           //Create a new PDF document   
            PdfDocument document = new PdfDocument();
 
            //Add a page to the document   
            PdfPage page = document.Pages.Add();
 
            //Create the PDF graphics for the page   
            PdfGraphics graphics = page.Graphics;
 
            //Load the image from the disk   
            PdfBitmap image = new PdfBitmap("../../Data/Autumn Leaves.jpg");
 
            //Draw the image   
            graphics.DrawImage(image, new PointF(26, 27), new SizeF(300, 300));
 
            //Save and close the documents 
            document.Save("Sample.pdf");
            document.Close(true);
 
            Process.Start("Sample.pdf");
 

 

VB.NET

'Create a new PDF document 
 Dim document As PdfDocument = New PdfDocument()
 'Add a page to the document
    Dim page As PdfPage = document.Pages.Add()
 'Create the PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
 'Load the image from the disk
    Dim image As PdfBitmap = New PdfBitmap("../../Data/Autumn Leaves.jpg")
 'Draw the image
 graphics.DrawImage(image, New PointF(26, 27), new SizeF(300, 300))
 'Save and close the documents 
 document.Save("Sample.pdf")
    document.Close(True)
    Process.Start("Sample.pdf")

 

By executing the program, you will get the PDF document as follows.

Output screenshotA complete working sample can be downloaded from PdfSample.zip.

Take a moment to peruse the documentation for working with images. You can load the image streams, files on disk for drawing in a PDF document, and more features like inserting an image in a new PDF documentImage pagination, and Image extraction with code examples.

Refer to here to explore a rich set of Syncfusion Essential® PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.

 

See Also:

https://help.syncfusion.com/file-formats/pdf/working-with-images

https://www.syncfusion.com/kb/9619/how-to-insert-images-in-the-pdf-table-using-c-and-vb-net

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied