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 existing PDF file using VB.NET


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





In this vb.net tutorial, you will learn how to add jpg, png images to PDF files using VB.NET code in Visual Studio applications.

  • Add jpg, png, bitmap images to PDF page
  • Add an image with aspect ratio settings
  • Add background image or image to PDF page header, footer
  • Easy to develop in Windows Forms, WPF applications, ASP.NET using VB.NET

How to add, insert images to PDF file using Visual Basic .NET

  1. Download XDoc.PDF VB.NET library
  2. Install vb library to add image to PDF files
  3. Step by Step Tutorial










  • Free VB.NET PDF SDK library for processing PDF image in Visual Studio VB.NET program
  • View complete C# source code at How to add, insert images to PDF using C#
  • 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
  • PDF viewer, editor control for asp.net control: pdf preview in asp net c# example, asp.net open word document, asp.net pdf writer, pdf viewer in asp.net core mvc, asp.net add text to pdf file, c# asp.net pdf viewer, asp.net core image viewer.
  • 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, insert image to an existing PDF file


It is an easy job using VB.NET code to add, insert 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
doc.Save(outputFilePath)




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
doc.Save(outputFilePath);






How to add a background image to PDF page using Visual Basic .NET


The following Visual Basic source code shows how to add, insert an image as PDF background image.



Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\1_backgd.b.pdf"
Dim srcImageFilePath As String = "C:\SourceImage.png")

' open a PDF file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Create a background resource by an image file.
Dim resBackground As PDFBackgroudRes = New PDFBackgroundImageRes(New Bitmap(srcImageFilePath))

' define a page background setting
Dim background As PDFPageBackground = New PDFPageBackground(resBackground)
' Set transparency
background.Opacity = 0.2F

' Alignment the background to center.
background.HoriAlignment = BackgroundHoriAlignment.Center
background.VertAlignment = BackgroundVertAlignemnt.Center

' Indicate if use image's acutal size or not.
' If set to false, it would fill the image to the target page.
' Default: false
background.EnableAbsoluteScale = True

' define page range to all pages
Dim pageRange As PageRangeOptions = New PageRangeOptions()
pageRange.AllPages = True
pageRange.Subset = PageRangeSubset.All

' apply page background settings to all pages
PDFPageFieldHandler.ApplyBackground(doc, background, pageRange)

doc.Save(outputFilePath)




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
Next




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
doc.Save(outputFilePath)