Articles in this section

How to use same image multiple times in a PDF using C# and VB.NET?

Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can use the same image multiple times in a PDF using C# and VB.NET.

Steps to use the same image multiple times in a PDF programmatically:

  1. Create a new C# console application project. Create a console application project in .NET PDF library
  2. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org. NuGet package reference screenshot in .NET PDF library
  3. Use the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System.Drawing;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports System.Drawing

 

  1. Use the following code snippet to use the same image multiple times in a PDF.

C#

//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Load the image from the disk
PdfImage image = new PdfBitmap("Autumn Leaves.jpg");
for (int i = 0; i < 5; i++)
{
    //Add a page to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Draw an image
    graphics.DrawImage(image, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));
}
//Save the document
doc.Save("Sample.pdf");
//Close the document
doc.Close(true); //This will open the PDF file so, the result will be seen in default PDF viewer System.Diagnostics.Process.Start("Sample.pdf");

 

VB.NET

'Create a new PDF document
Dim doc As PdfDocument = New PdfDocument()
'Load the image from the disk
Dim image As PdfImage = New PdfBitmap("Autumn Leaves.jpg")
For i As Integer = 0 To 5 - 1
    'Add a page to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Draw an image
    graphics.DrawImage(image, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height))
Next
'Save the document
doc.Save("Sample.pdf")
'Close the document
doc.Close(True)
'This will open the PDF file so, the result will be seen in default PDF viewer
System.Diagnostics.Process.Start("Sample.pdf")

 

A complete working sample can be downloaded from ImageSample.zip.

Take a moment to peruse the documentation, where you can find other options like inserting images in a new and existing PDF document, inserting a vector image, image masking, image pagination, replacement of images, applying transparency and rotation to the image and features like image extraction with code examples.

Refer here to explore the rich set of Syncfusion Essential&reg; PDF features.

Note:

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

 

Conclusion

I hope you enjoyed learning about how to use same image multiple times in a PDF using C# and VB.NET.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

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