Image

Image (12)

The following code snippets show you how we can find x and y coordinates of an image in a PDF document.

Step 1: Create a PdfDocument object and load a sample PDF file.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");

Step 2: Get all the image information from the specified page.

PdfImageInfo[] imageInfo = doc.Pages[0].ImagesInfo;

Step 3: Get the x and y coordinates of the first image through Bounds property.

RectangleF rect = imageInfo[0].Bounds;
Console.WriteLine("The image is located at({0},{1})", rect.X, rect.Y);

Output:

How to Get X/Y Position of Image in PDF in C#, VB.NET

Full Code:

[C#]
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
PdfImageInfo[] imageInfo = doc.Pages[0].ImagesInfo;
RectangleF rect = imageInfo[0].Bounds;
Console.WriteLine("The image is located at({0},{1})", rect.X, rect.Y);
[VB.NET]
Dim doc As PdfDocument = New PdfDocument()
doc.LoadFromFile("sample.pdf")
Dim imageInfo As PdfImageInfo() = doc.Pages(0).ImagesInfo
Dim rect As RectangleF = imageInfo(0).Bounds
Console.WriteLine("The image is located at({0},{1})", rect.X, rect.Y)
Tuesday, 11 April 2017 07:45

How to Extract Image from Signature in PDF

Written by support iceblue

Spire.PDF allows extracting images from signatures using ExtractSignatureAsImages method in PdfFormWidget class. This article demonstrates how we can use Spire.PDF to implement this feature.

Code Snippet:

Step 1: Instantiate an object of PdfDocument class and load the PDF document.

PdfDocument document = new PdfDocument("sample.pdf");

Step 2: Get the existing forms of the document.

PdfFormWidget form = document.Form as PdfFormWidget;

Step 3: Extract images from signatures in the existing forms and put them into an Image Array.

Image[] images = form.ExtractSignatureAsImages();

Step 4: Save the images to disk.

int i = 0;
for (int j = 0; j < images.Length; j++)
{
    images[j].Save(String.Format(@"Image/Image-{0}.png", i), ImageFormat.Png);
    i++;
}

Screenshot:

How to Extract Image from Signature in PDF

Full code:

[C#]
//Load the PDF document
PdfDocument document = new PdfDocument("sample.pdf");

//Get the existing forms of the document
PdfFormWidget form = document.Form as PdfFormWidget;

//Extract images from signatures in the existing forms
Image[] images = form.ExtractSignatureAsImages();

//Save the images to disk
int i = 0;
for (int j = 0; j < images.Length; j++)
{
    images[j].Save(String.Format(@"Image/Image-{0}.png", i), ImageFormat.Png);
    i++;
}

//Close the document
document.Close();
[VB.NET]
'Load the PDF document
Dim document As New PdfDocument("sample.pdf")

'Get the existing forms of the document
Dim form As PdfFormWidget = TryCast(document.Form, PdfFormWidget)

'Extract images from signatures in the existing forms
Dim images As Image() = form.ExtractSignatureAsImages()

'Save the images to disk
Dim i As Integer = 0
For j As Integer = 0 To images.Length - 1
	images(j).Save([String].Format("Image/Image-{0}.png", i), ImageFormat.Png)
	i += 1
Next

'Close the document
document.Close()
Tuesday, 15 November 2016 07:43

How to change the image on button field in C#

Written by support iceblue

We have already had an article of showing how to replace the image on the existing PDF file. Starts from Spire.PDF V3.8.45, it newly supports to update the image on button field via the method of field.SetButtonImage(PdfImage.FromFile(@"")). This article will focus on demonstrate how to replace the image on the button field in C#.

Firstly, check the original PDF file with the button field.

How to change the image on button field in C#

Step 1: Create a PDF document and load from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);

Step 2: Get the form from the loaded PDF document.

PdfFormWidget form = pdf.Form as PdfFormWidget;

Step 3: Find the button field named "Image" and then set a new image for this button field.

for (int i = 0; i < form.FieldsWidget.Count; i++)
{
    if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
    {
        PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
        if (field.Name == "Image")
        { field.SetButtonImage(PdfImage.FromFile("logo.png")); }
    }
}

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot after replace the image on the button field.

How to change the image on button field in C#

Full codes:

public ButtonField()
{
    PdfDocument pdf = new PdfDocument();
    pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);

    PdfFormWidget form = pdf.Form as PdfFormWidget;

    for (int i = 0; i < form.FieldsWidget.Count; i++)
    {
        if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
        {
            PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
            if (field.Name == "Image")
            { field.SetButtonImage(PdfImage.FromFile("logo.png")); }

        }
    }

    pdf.SaveToFile("result.pdf");

}
Friday, 09 October 2015 07:28

How to delete an image from a PDF file in C#

Written by support iceblue

With the help of Spire.PDF for .NET, we can easily add a new image to an existing PDF file. Now starts from Spire.PDF v3.5.80, we can delete an image via the index of image from a PDF file in C# easily. Firstly, check the original PDF file with an image at the page and the other image as background image.

How to delete an image from a PDF file in C#

The following code snippet shows how to delete an image from a PDF file:

Step 1: Create a new instance of PdfDocument and load a PDF document from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");

Step 2: Get the first page of the loaded PDF file.

PdfPageBase page=pdf.Pages[0];

Step 3: Delete an image via the index of image.

page.DeleteImage(1);

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot:

How to delete an image from a PDF file in C#

Full codes:

class Program
{
    static void Main(string[] args)
    {
        PdfDocument pdf = new PdfDocument();
        pdf.LoadFromFile("Sample.pdf");
        PdfPageBase page=pdf.Pages[0];
        page.DeleteImage(1);
        pdf.SaveToFile("result.pdf");
    }
}

Universal 3D (U3D) is a compressed file format for 3D computer graphic data. 3D modules in U3D format can be inserted into PDF documents and interactively visualized by Acrobat Reader. This article presents how to embed a pre-created U3D file into a PDF document using Spire.PDF in C#, VB.NET.

Main Steps:

Step 1: Initialize a new object of PdfDocuemnt, and add a blank page to the PDF document.

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

Step 2: Draw a rectangle on the page to define the canvas area for the 3D file.

Rectangle rt = new Rectangle(0, 80, 200, 200);

Step 3: Initialize a new object of Pdf3DAnnotation, load the .u3d file as 3D annotation.

Pdf3DAnnotation annotation = new Pdf3DAnnotation(rt, "teapot.u3d");
annotation.Activation = new Pdf3DActivation();
annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen;

Step 4: Define a 3D view mode.

Pdf3DView View= new Pdf3DView();
View.Background = new Pdf3DBackground(new PdfRGBColor(Color.Purple
));
View.ViewNodeName = "test";
View.RenderMode = new Pdf3DRendermode(Pdf3DRenderStyle.Solid);
View.InternalName = "test";
View.LightingScheme = new Pdf3DLighting();
View.LightingScheme.Style = Pdf3DLightingStyle.Day;

Step 5: Set the 3D view mode for the annotation.

annotation.Views.Add(View);

Step 6: Add the annotation to PDF.

page.AnnotationsWidget.Add(annotation);

Step 7: Save the file.

doc.SaveToFile("Create3DPdf.pdf", FileFormat.PDF);

Output:

How to Embed 3D Interactive Graphics into PDF Document in C#, VB.NET

Full Code:

[C#]
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

Rectangle rt = new Rectangle(0, 80, 200, 200); 
Pdf3DAnnotation annotation = new Pdf3DAnnotation(rt, "teapot.u3d");
annotation.Activation = new Pdf3DActivation();
annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen; 
Pdf3DView View= new Pdf3DView();
View.Background = new Pdf3DBackground(new PdfRGBColor(Color.Purple));
View.ViewNodeName = "test";
View.RenderMode = new Pdf3DRendermode(Pdf3DRenderStyle.Solid);
View.InternalName = "test";
View.LightingScheme = new Pdf3DLighting();
View.LightingScheme.Style = Pdf3DLightingStyle.Day;
annotation.Views.Add(View);

page.AnnotationsWidget.Add(annotation);
doc.SaveToFile("Create3DPdf.pdf", FileFormat.PDF);
[VB.NET]
Dim doc As New PdfDocument()
Dim page As PdfPageBase = doc.Pages.Add()

Dim rt As New Rectangle(0, 80, 200, 200)
Dim annotation As New Pdf3DAnnotation(rt, "teapot.u3d")
annotation.Activation = New Pdf3DActivation()
annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen
Dim View As New Pdf3DView()
View.Background = New Pdf3DBackground(New PdfRGBColor(Color.Purple))
View.ViewNodeName = "test"
View.RenderMode = New Pdf3DRendermode(Pdf3DRenderStyle.Solid)
View.InternalName = "test"
View.LightingScheme = New Pdf3DLighting()
View.LightingScheme.Style = Pdf3DLightingStyle.Day
annotation.Views.Add(View)

page.AnnotationsWidget.Add(annotation)
doc.SaveToFile("Create3DPdf.pdf", FileFormat.PDF)

Sometimes when we want to change the existing image on the PDF file with a new image, we will find it is not so easy to accomplish it. With the help of Spire.PDF, we can directly use the method of page.ReplaceImage to replace the existing image with the new image. This article will show you how to replace the image on the PDF file in C#.

Firstly, view the original PDF file that the image on it needs to be replaced.

How to replace the existing image on the PDF file in C#

Step 1: Create a new instance of PdfDocument and load a PDF document from file.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Test.pdf");

Step 2: Get the first page of the loaded PDF file.

PdfPageBase page = doc.Pages[0];

Step 3: Load the new image that we want to replace the existing image.

PdfImage image = PdfImage.FromFile("image.png");

Step 4: Replace first image on the PDF file with the new loaded image.

page.ReplaceImage(0, image);

Step 5: Save the document to file.

doc.SaveToFile("result.pdf");

Effective screenshot:

How to replace the existing image on the PDF file in C#

Full codes:

static void Main(string[] args)
 {
     PdfDocument doc = new PdfDocument();
     doc.LoadFromFile("Test.pdf");
     PdfPageBase page = doc.Pages[0];
     PdfImage image = PdfImage.FromFile("image.png");
     page.ReplaceImage(0, image);
     doc.SaveToFile("result.pdf");
 }

This article mainly introduces a detail method to draw an image into pdf document and make sure the pdf page size is same with image size. This method would show you how to draw an image into PDF file and save the PDF as image file with the same size of image via a .NET PDF component in C#, VB.NET.

Using Spire.PDF, you can not only draw image into PDF but also save the PDF as an image file. In my solution, I used the size of image as the PDF size via PdfUnitConvertor.ConvertFromPixels() function to get the image size in point. You can view output pdf file and image file as below pictures

Output PDF file:

Draw image in pdf with same size

Output image file:

Draw image in pdf with same size

The main steps of the method

Draw an image into PDF

Step 1: Create a new PDF document.

PdfDocument doc = new PdfDocument();

Step 2: Use PdfImage.FromImage() function to load pdf image.

PdfImage pdfimage = PdfImage.FromImage(image); 

Step 3: Use PdfUnitConvertor.ConvertFromPixels() function to get the image size in point and create a new page with image size.

PdfUnitConvertor uinit = new PdfUnitConvertor();
SizeF pageSize = uinit.ConvertFromPixels(image.Size, PdfGraphicsUnit.Point);
PdfPageBase page = doc.Pages.Add(pageSize, new PdfMargins(0f));

Step 4: Draw the PDF image into the PDF page.

page.Canvas.DrawImage(pdfimage, new PointF(0, 0));

Step 5: Save to a PDF file.

doc.SaveToFile("sample.pdf");

Save the PDF as image file

Step 1: Load the PDF file.

doc.LoadFromFile("sample.pdf");

Step 2: Use the doc.SaveAsImage( ) function to save the PDF as image.

Image img = doc.SaveAsImage(0);

Step 3: Save to an image file.

img.Save("sample.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

Download and install Spire.Pdf for .NET and use below code to experience this solution to draw an image into PDF and save it as image file with original size.

The full code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace ConvertPdfToImage
{
    class Program
    {
        static void Main(string[] args)
        {  
          
            PdfDocument doc = new PdfDocument();

            Image image = Image.FromFile(@"sample.jpg");
            PdfImage pdfimage = PdfImage.FromImage(image); 

            PdfUnitConvertor uinit = new PdfUnitConvertor();
            SizeF pageSize = uinit.ConvertFromPixels(image.Size, PdfGraphicsUnit.Point);
            PdfPageBase page = doc.Pages.Add(pageSize, new PdfMargins(0f));

            page.Canvas.DrawImage(pdfimage, new PointF(0, 0));
            doc.SaveToFile("sample.pdf");

            doc.LoadFromFile("sample.pdf");
            Image img = doc.SaveAsImage(0);
            img.Save("sample.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing
Module Module1
    Sub Main()
       
        Dim doc As New PdfDocument()

        Dim image As Image = image.FromFile("sample.jpg")
        Dim pdfimage As PdfImage = pdfimage.FromImage(image)

        Dim uinit As New PdfUnitConvertor()
        Dim pageSize As SizeF = uinit.ConvertFromPixels(image.Size, PdfGraphicsUnit.Point)
        Dim page As PdfPageBase = doc.Pages.Add(pageSize, New PdfMargins(0.0F))

        page.Canvas.DrawImage(pdfimage, New PointF(0, 0))

        doc.SaveToFile("sample.pdf")

        doc.LoadFromFile("sample.pdf")
        Dim img As Image = doc.SaveAsImage(0)
        img.Save("sample.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    End Sub
End Module

Spire.PDF for .NET is a PDF component which contains an incredible wealth of features to create, read, edit and manipulate PDF documents on .NET, Silverlight and WPF Platform. As a professional .NET PDF component, it also includes many useful features, for example, functionalities of adding header and footer, drawing table, saving PDF document as tiff and Splitting tiff image and drawing to pdf document without installing Adobe Acrobat or any other third party libraries.

This article would introduce a detail method to split the tiff image and draw to pdf document. The below picture show the effect of splitting tiff image and drawing to pdf document:

Split tiff image and Convert to pdf document

The main steps of the method are:

One: Split multi-page TIFF file to multiple frames

  • Load a multipage Tiff.
  • Use Image.GetFrameCount method to get the number of frames of tiff Image.
  • Initialize a new instance of Guid to save the dimension from tiff image.
  • Using Guid to initialize a new instance of the System.Drawing.Imaging.FrameDimension class.
  • Iterate over the Tiff Frame Collection and save them to Image array.

Two: Draw image to PDF

  • Initialize a new instance of Spire.Pdf.PdfDocument.
  • Iterate over the image array.
  • Use Spire.Pdf.PdfPageBase.Canvas.DrawImage method to draw image into page with the specified coordinates and image size.

Download and install Spire.Pdf for .NET and use below code to experience this method to split tiff and convert it to pdf document.

The full code of method:

[C#]
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace SplitTiff
{
    class Program
    {
        static void Main(string[] args)
        {
            using (PdfDocument pdfDocument = new PdfDocument())
            {
                Image tiffImage = Image.FromFile(@"..\..\demo.tiff");
                Image[] images = SplitTIFFImage(tiffImage);
                for (int i = 0; i < images.Length; i++)
                {
                    PdfImage pdfImg = PdfImage.FromImage(images[i]);
                    PdfPageBase page = pdfDocument.Pages.Add();
                    float width = pdfImg.Width * 0.5f;
                    float height = pdfImg.Height * 0.5f;
                    float x = (page.Canvas.ClientSize.Width - width) / 2;
                    //set the image of the page 
                    page.Canvas.DrawImage(pdfImg, x, 0, width, height);
                }
                pdfDocument.SaveToFile(@"..\..\result.pdf");
                System.Diagnostics.Process.Start(@"..\..\result.pdf");
            }
        }
        public static Image[] SplitTIFFImage(Image tiffImage)
        {
            int frameCount = tiffImage.GetFrameCount(FrameDimension.Page);
            Image[] images = new Image[frameCount];
            Guid objGuid = tiffImage.FrameDimensionsList[0];
            FrameDimension objDimension = new FrameDimension(objGuid);
            for (int i = 0; i < frameCount; i++)
            {
                tiffImage.SelectActiveFrame(objDimension, i);
                using (MemoryStream ms = new MemoryStream())
                {
                    tiffImage.Save(ms, ImageFormat.Tiff);
                    images[i] = Image.FromStream(ms);
                }
            }
            return images;
        }
    }
}
[VB.NET]
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports Spire.Pdf
Imports Spire.Pdf.Graphics

Namespace SplitTiff
    Class Program
        Shared Sub Main(ByVal args() As String)
            Using pdfDocument As New PdfDocument

                Dim tiffImage As Image = Image.FromFile("..\..\demo.tiff")
                Dim images() As Image = SplitTIFFImage(tiffImage)

                Dim i As Integer
                For i = 0 To images.Length - 1 Step i + 1
                    Dim pdfImg As PdfImage = PdfImage.FromImage(images(i))
                    Dim page As PdfPageBase = pdfDocument.Pages.Add()
                    Dim width As Single = pdfImg.Width * 0.5F
                    Dim height As Single = pdfImg.Height * 0.5F
                    Dim x As Single = (page.Canvas.ClientSize.Width - width) / 2
                    'set the image of the page 
                    page.Canvas.DrawImage(pdfImg, x, 0, width, height)
                Next


                pdfDocument.SaveToFile("..\..\result.pdf")
                System.Diagnostics.Process.Start("..\..\result.pdf")
            End Using
        End Sub
        Private Shared Function SplitTIFFImage(ByVal tiffImage As Image)

            Dim frameCount As Integer = tiffImage.GetFrameCount(FrameDimension.Page)
            Dim images() As Image = New Image(frameCount) {}
            Dim objGuid As Guid = tiffImage.FrameDimensionsList(0)
            Dim objDimension As FrameDimension = New FrameDimension(objGuid)
            Dim i As Integer
            For i = 0 To frameCount - 1 Step i + 1
                tiffImage.SelectActiveFrame(objDimension, i) 

                Using ms As New MemoryStream

                    tiffImage.Save(ms, ImageFormat.Tiff)
                    images(i) = Image.FromStream(ms)
                End Using

            Next
            Return images
        End Function
    End Class
End Namespace

If you are interested in the method of converting pdf to tiff image you can refer the Save PDF Document as tiff image article in our website.

This sample demo has demonstrated how to draw nested grid in PDF document and set grid row&cell format. In the following section, we are going to create a simple PDF grid and show you how to insert an image to a specific PDF grid cell in C#. Before we can follow the code snippet below to accomplish the task, we have to prepare the environment first.

Download Spire.PDF and install it on system, create or open a .NET class application in Visual Studio 2005 or above versions, add Spire.PDF.dll to your .NET project assemblies.Then let's code step by step to make a better understanding about the whole procedure.

Step 1: Create a PDF document and add a new page.

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

Step 2: Create a 2×2 grid to PDF.

PdfGrid grid = new PdfGrid();
PdfGridRow row = grid.Rows.Add();
           row = grid.Rows.Add();
                 grid.Columns.Add(2);

Step 3: Set the cell padding of the PDF grid.

grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);

Step 4: Set the width of the columns.

float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
      grid.Columns[0].Width = width * 0.25f;
      grid.Columns[1].Width = width * 0.25f;

Step 5: Load an image from disk.

PdfGridCellContentList lst = new PdfGridCellContentList();
PdfGridCellContent textAndStyle = new PdfGridCellContent();
textAndStyle.Image = PdfImage.FromFile("..\\..\\image1.jpg");

Step 6: Set the size of image and insert it to the first cell.

textAndStyle.ImageSize = new SizeF(50, 50);
lst.List.Add(textAndStyle);
          
grid.Rows[0].Cells[0].Value = lst;
grid.Rows[1].Height = grid.Rows[0].Height;

Step 7: Draw PDF grid into page at the specific location.

PdfLayoutResult result = grid.Draw(page, new PointF(10, 30));

Step 8: Save to a PDF file and launch the file.

doc.SaveToFile(outputFile, FileFormat.PDF);
System.Diagnostics.Process.Start(outputFile);

Result:

Insert an Image to PDF Grid Cell in C#

Full C# Code:

static void Main(string[] args)
        {
            string outputFile = @"..\..\output.pdf";
            //Create a pdf document
            PdfDocument doc = new PdfDocument();
            //Add a page for the pdf document
            PdfPageBase page = doc.Pages.Add();
            //Create a pdf grid
            PdfGrid grid = new PdfGrid();
            //Set the cell padding of pdf grid
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
            //Add a row for pdf grid
            PdfGridRow row = grid.Rows.Add();
            //Add two columns for pdf grid 
            grid.Columns.Add(2);
            float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            //Set the width of the first column
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            //Add a image
            PdfGridCellContentList lst = new PdfGridCellContentList();
            PdfGridCellContent textAndStyle = new PdfGridCellContent();
            textAndStyle.Image = PdfImage.FromFile("..\\..\\image1.jpg");
            //Set the size of image
            textAndStyle.ImageSize = new SizeF(50, 50);
            lst.List.Add(textAndStyle);
            //Add a image into the first cell. 
            row.Cells[0].Value = lst;
            //Draw pdf grid into page at the specific location
            PdfLayoutResult result = grid.Draw(page, new PointF(10, 30));
            //Save to a pdf file 
            doc.SaveToFile(outputFile, FileFormat.PDF);
            System.Diagnostics.Process.Start(outputFile);
        }
Tuesday, 07 February 2012 06:44

Draw PDF Image in C#, VB.NET

Written by support iceblue

PDF image is an important part of PDF document, especially in some material instructions, a small image can show useful information that even thousands of words cannot explain. While PDF images are also used to make the document more attractive. This section will show you a solution to draw PDF image via a .NET PDF component in C#, VB.NET.

Spire.PDF for .NET, a .NET PDF library for handling PDF file, enables you to draw image in PDF with C#, VB.NET. Using this PDF component, you can not only set your image size in the PDF file but also place the image at a specific position. In my solution, I set the transparency to avoid covering PDF text by PDF image. You can view the target PDF file as below picture:

Draw Image in PDF

Here you can download Spire.PDF for .NET, after installing it on system and adding Spire.Pdf dll, you can start your PDF task by following steps.

Detail Code:

There are mainly three simple steps in my solution. The first step requires you to load an image, which can be achieved by this method: System.Drawing.Image FromFile(string filename). The second step needs you to set image size to match the PDF appropriately through setting image width and height via System.Drawing.Size(int width, int height). The last step is designed to set the PDF image position and draw image in PDF. You can call DrawImage(PdfImage image, PointF point) method in which there are with two parameters passed. The second parameter is mainly responsible for setting image to a specific position. If necessary, you also can set transparency by SetTransparency(float alpha). Please see the whole code here.

[C#]
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace PDFimage
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"..\Sample.pdf");
            Image image = Image.FromFile(@"..\images.jpg");

            //adjust image size
            int width=image.Width;
            int height=image.Height;
            float schale=1.5f;
            Size size=new Size ((int)(width*schale),(int)(height*schale));
            Bitmap schaleImage = new Bitmap(image, size);

            //insert image into the first PDF page at specific position
            PdfImage pdfImage = PdfImage.FromImage(schaleImage);
            PdfPageBase page0 = doc.Pages[0];
            PointF position = new PointF((page0.Canvas.ClientSize.Width - schaleImage.Width) / 2, 210);
            page0.Canvas.SetTransparency(0.5f);
            page0.Canvas.DrawImage(pdfImage, position);
            page0.Canvas.SetTransparency(1.0f);

            doc.SaveToFile(@"pdfimage.pdf");
            System.Diagnostics.Process.Start(@"pdfimage.pdf");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics

Namespace PDFimage
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Create a pdf document.
            Dim doc As PdfDocument = New PdfDocument
            doc.LoadFromFile("..\Sample.pdf")
            Dim image As Image = Image.FromFile("..\images.jpg")
            'adjust image size
            Dim width As Integer = image.Width
            Dim height As Integer = image.Height
            Dim schale As Single = 1.5!
            Dim size As Size = New Size(CType((width * schale),Integer), CType((height * schale),Integer))
            Dim schaleImage As Bitmap = New Bitmap(image, size)
            'insert image into the first PDF page at specific position
            Dim pdfImage As PdfImage = PdfImage.FromImage(schaleImage)
            Dim page0 As PdfPageBase = doc.Pages(0)
            Dim position As PointF = New PointF(((page0.Canvas.ClientSize.Width - schaleImage.Width)  _
                            / 2), 210)
            page0.Canvas.SetTransparency(0.5!)
            page0.Canvas.DrawImage(pdfImage, position)
            page0.Canvas.SetTransparency(1!)
            doc.SaveToFile("pdfimage.pdf")
            System.Diagnostics.Process.Start("pdfimage.pdf")
        End Sub
    End Class
End Namespace

Spire.PDF for .NET allows developers to perform a wide range of tasks directly without Adobe Acrobat such as create, edit, read and manage PDF documents in C#,VB.NET.