itext 7 add image to existing pdf code example

Example: itext 7 add image to existing pdf

// Modify PDF located at "source" and save to "target"
PdfDocument pdfDocument = new PdfDocument(new PdfReader(source), new PdfWriter(target));
// Document to add layout elements: paragraphs, images etc
Document document = new Document(pdfDocument);

// Load image from disk
ImageData imageData = ImageDataFactory.Create(imageSource);
// Create layout image object and provide parameters. Page number = 1
Image image = new Image(imageData).ScaleAbsolute(100, 200).SetFixedPosition(1, 25, 25);
// This adds the image to the page
document.Add(image);

// Don't forget to close the document.
// When you use Document, you should close it rather than PdfDocument instance
document.Close();

Tags:

Misc Example