XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Image: Copy, Paste, Cut Image in Page
  |  
Home ›› XDoc.PDF ›› C# PDF: Copy, Paste, Cut Image in Page

C#.NET PDF SDK - Copy, Paste, Cut PDF Image in 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




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


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 also supports image copying, pasting, and cutting.




C#.NET Project DLLs: Copy, Paste, Cut Image in PDF Page



In order to run the sample code, the following steps would be necessary.


Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




C#.NET Demo Code: Copy and Paste Image in PDF Page in C#.NET



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




// Define input and output documents.
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.
doc.Save(outputFilePath);





C#.NET Demo Code: Cut Image in PDF Page in C#.NET



PDF image cutting is similar to image deleting. So, in C# demo code below, we will explain how to cut image from PDF file page by using image deleting API.




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

// Open a PDF document.
PDFDocument doc = new PDFDocument(inputFilePath);

// Extract all images from the document.
List<PDFImage> allImages = PDFImageHandler.ExtractImages(doc);

// Delete all images from the document.
foreach (PDFImage image in allImages)
{
    PDFImageHandler.DeleteImage(doc, image);
}

// Output the new PDF document.
doc.Save(outputFilePath);





public static List<PDFImage> ExtractImages(PDFDocument doc)

Description:
     Extract all images in a PDF document.

Parameters:

Return:
     A list of image objects, null if failed.



public static List<Bitmap> ExtractOriginalImages(PDFDocument doc)

Description:
     Extract all images in a document with their original size.

Parameters:

Return:
     A list of image objects, null if failed.



public static List<PDFImage> ExtractImages(PDFPage page)

Description:
     Extract all images in a page.

Parameters:

Return:
     A list of image objects, null if failed.



public static List<Bitmap> ExtractOriginalImages(PDFPage page)

Description:
     Extract all images in a page with their original size.

Parameters:

Return:
     A list of image objects, null if failed.