How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator 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

C# PDF Image Library
How to copy, paste images from existing PDF file using C# .net

C# Guide for How to Cut or Copy an Image from One Page and Paste to Another One with C#.NET Demo Codes

In this C# tutorial, you will learn how to use XDoc.PDF image editor C# library to

  • Copy, paste an image inside a PDF file
  • Move an image position
  • Replace an existing image inside PDF

How to move, copy, paste, replace image from PDF file using C#

  1. Download XDoc.PDF image edit C# library
  2. Install C# library to move, replace, copy, paste PDF images.
  3. Step by Step Tutorial

  • Best .NET framework PDF editor SDK control for image copying, pasting and cutting from adobe PDF file in Visual C#
  • Free .NET components and SDK library able to copy, paste and cut image from PDF in C#.NET WinForms and ASP.NET project
  • Visual C# class source code for copying, pasting, cutting image from PDF in Visual Studio .NET framework program
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Free source code for C# PDF image tutorials: c# pdf add image, c# remove images from pdf, extract text from pdf file using c#, add text to existing pdf c#, get coordinates of text in pdf c#, c# replace text in pdf.
  • Ability to copy, paste and cut vector image, graphic picture, digital photo, scanned signature, logo, etc
  • High quality image can be saved after cutting, copying and pasting into PDF page in .NET console application
  • Guarantee high performance image processing by implementing coordinates to locate image position accurately
  • Empower to cut, copy and paste a single image, multiple images and whole PDF document images
  • Allow to copy an image from existing PDF file and paste it into another one
  • Easy to zoom and crop image for adjusting image size

Besides image extracting, adding, and removing, RasterEdge XDoc.PDF for .NET C# library also supports image copying, pasting, and cutting.

Copy an image from a pdf file and paste to another position

This C#.NET example describes how to copy an image from one page of PDF document and paste it into another page.

String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);

//  get the first page
int pageIndex = 0;
PDFPage page1 = (PDFPage)doc.GetPage(pageIndex);

//  select image at the position (480F, 550F) in the page
PointF cursorPos = new PointF(480F, 550F);
PDFImage image = PDFImageHandler.SelectImage(page1, cursorPos);

//  copy the image
Bitmap anImage = (Bitmap)image.Image.Clone();

//  get the second page
PDFPage page2 = (PDFPage)doc.GetPage(1);
//  set image position in the page: X = 100F, Y = 400F
PointF position = new PointF(100F, 400F);

//  add image to the page
PDFImageHandler.AddImage(page2, anImage, position);

//  output the new document

Move an image in the PDF page using C#

The following C# source code shows how to move an image from one position to another in the same PDF page.

String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

//  open a document and select the page
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
//  extract all images in the page
List<PDFImage> images = PDFImageHandler.ExtractImages(page);
//  move the first image to position (0, 0) in the same page
PDFImageHandler.MoveImageTo(doc, images[0], 0, new PointF(0F, 0F));

//  output the new document

Replace an image in the document

The following C# example code shows how to replace an image with another in the PDF page using C#

String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.pdf";
Bitmap bitmap = new Bitmap(@"C:\1.png");

//  Open file and get the first page
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);

//  Select the image at position (70, 80).
PDFImage img = PDFImageHandler.SelectImage(page, new PointF(70, 80));

//  Replace the selected image by the new image.
PDFImageHandler.ReplaceImage(page, img, bitmap);