Tech Specs
How-to VB.NET
How to Start Convert PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

VB.NET PDF Image Editor Library
How to add Image to PDF Page in VB.NET

Guide VB.NET Programmers How to Add Images in PDF Document Using XDoc.PDF SDK for VB.NET

  • Free VB.NET PDF SDK library for processing PDF image in Visual Studio VB.NET program
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Support various image formats, like Jpeg or Jpg, Png, Gif, Bmp, Tiff and other bitmap images
  • Create high resolution PDF file without image quality losing in .NET WinForms application
  • Insert single or multiple images or graphics to PDF document
  • Enable users to insert images to PDF file in ASPX webpage project
  • Import graphic picture, digital photo, signature and logo into PDF document
  • Add images to any selected PDF page in VB.NET
  • Ability to put image into defined location on PDF page
  • Provide image attributes adjust functionalities, such as resize image by zooming and cropping
  • Save changes to existing PDF file or output a new PDF file
  • Insert images into PDF form field in VB.NET
  • An independent .NET framework component supports inserting image to PDF in preview without adobe PDF control installed
  • Access to freeware download and online VB.NET class source code

This smart and mature PDF image adding component of RasterEdge VB.NET PDF document processing SDK is an independent PDF handling application in high level. It has been perfectly programmed to provide users the most individualized PDF page image inserting function, allowing developers to add and insert single or a couple of images or graphics of specific format, such as Png, Gif and TIFF, to any selected PDF page with your defined location. Once the photo is inserted, its attributes, for instance, appearance and position, can be totally adjusted and readjusted before saving the PDF file with simple Visual Basic .NET codes.

With powerful VB PDF image compressing techniques, our PDF document also implements several international image compression mechanisms for embedding image, users are completely free to specify any compression model manually or leave it to the assembly program to decide.

Additionally, this PDF document image inserting toolkit in VB.NET still offers users the capabilities of burning and merging the added image with source PDF page for better storage and further viewing.

VB.NET add an image to a PDF page with the specified position

It is an easy job to add, insert an image to the existing pdf file. To add an image to an existing PDF file:

  1. Create a Bitmap object from an image resource
  2. Get the PDF page you want to add an image to.
  3. Add the Bitmap object to the PDF page with specified position

Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\output.pdf"

' load a sample image
Dim anImage As Bitmap = New Bitmap("C:\1.png")

' open the document
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' get the first page
Dim page As PDFPage = doc.GetPage(0)
' set image position in the page: x = 100.0F, Y = 400F
Dim position As PointF = New PointF(100.0F, 400.0F)

' add image to the page
PDFImageHandler.AddImage(page, anImage, position)

' output the New document

VB.NET add a scaled Bitmap image to a page with aspect ratio

//  load a sample image
Bitmap bitmap = new Bitmap(Program.RootPath + "\\" + "1.png");

int width = bitmap.Width;
int height = = bitmap.Height;

int scaledWidth = 400;
int scaledHeight = scaledWidth * height / width;

//  set image item option
PDFItemOptions ops = new PDFItemOptions();

//  set target page region to add the image.
ops.Position = new PointF(10F, 10F);
ops.Width = scaledWidth;
ops.Height = scaledHeight;
//  open the document
PDFDocument doc = new PDFDocument(inputFilePath);
int pageIndex = 0;

//  add image to the target page
PDFImageHandler.AddImage(doc, pageIndex, bitmap, ops);

//  output the new document

VB.NET retrieve color space information of an image in the document

If you need know an image color space information inside pdf file, you can try the following vb.net source code.

Dim inputFilePath As String = "C:\1.pdf"

' Open file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' Get all images in the document
Dim imgs As List(Of PDFImage) = PDFImageHandler.ExtractImages(doc)
For Each img As PDFImage In imgs
    If Not (img.IsInlineImage Or img.IsForm) Then
        ' Get color space name of the image. Eg.: DeviceGray, DeviceRGB, Indexed etc.
        Console.WriteLine("Color Space: {0}", img.GetColorSpaceName())
        ' Indicate if the image Is in color (RGB).
        Console.WriteLine("Is RGB:      {0}", img.IsRGB)
        ' Indicate if the image Is in grayscale.
        Console.WriteLine("Is Gray:     {0}", img.IsGray)
    End If

Image quality control

When you add multiple images to a single PDF file, you want to control all images' quality, and make sure all images in the same PDF page are using the same compression mode. You can try the following code.

Dim inputFilePath As String = "C:\2.pdf"
Dim outputFilePath As String = "C:\output2.pdf"

' open a document and select the page
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
Dim page As PDFPage = doc.GetPage(0)
' extract all images in the page
Dim images As List(Of PDFImage) = PDFImageHandler.ExtractImages(page)

' reduce resolution to half of original value
PDFImageHandler.ReduceImageSize(doc, images(0), 2.0F)

' output the new document