Adhere Image

Skip to end of metadata
Go to start of metadata
Adhere Image

Similar to adhering text in a PDF document page, Aspose.Pdf.Kit also enables developers to adhere image (in Jpg, Gif or Png formats) in a PDF document page.AddImage method of PdfFileMend class adds image to the page of the PDF document at any specified location (determined by lower left X-axis, lower left Y-axis, upper right X-axis and upper right Y-axis) in a specified page number of the PDF document.
In .NET, follow these steps to adhere image in the PDF document:

  1. Create streams holding the paths of input and output PDF files
  2. Create the stream of image to be adhered in PDF file
  3. Set the current position of input PDF file stream to the beginning of the stream using Seek method of PDF file stream
  4. Instantiate PdfFileMend object and pass input and output PDF streams to its constructor
  5. Call AddImage method and pass the adhering image stream to AddImage with the page number (where to add the image) and other location parameters (lower left X-axis, lower left Y-axis, upper right X-axis and upper right Y-axis) to add the image at specified location in the page.

In Java, follow these steps to adhere image in the PDF document:

  1. Create streams holding the paths of input and output PDF files
  2. Create the stream of image to be adhered in PDF file
  3. Set the current position of input PDF file stream to the beginning of the stream using Seek method of PDF file stream
  4. Instantiate PdfFileMend object and pass input and output PDF streams to its constructor
  5. Call AddImage method and pass the adhering image stream to AddImage with the page number (where to add the image) and other location parameters (lower left X-axis, lower left Y-axis, upper right X-axis and upper right Y-axis) to add the image at specified location in the page.

We can also use another overloaded AddImage method to add image to more than one PDF document pages. In that case, an array of page numbers will be passed to AddImage method instead of a single page number.

[Java]
String inputFile = "example2.pdf";
String imageName = "butterfly.jpg";
String outputFile = "kitOut.pdf";
int[] pages = new int[] {1, 2, 3, 4, 5};
FileInputStream inPdfStream = new FileInputStream(inputFile);
FileInputStream inImgStream = new FileInputStream(imageName);
FileOutputStream outputStream = new FileOutputStream(outputFile);
PdfFileMend mendor = new PdfFileMend(inPdfStream, outputStream);
mendor.addImage(inImgStream, pages, 50, 50, 100, 100);
mendor.close();
outputStream.close();
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.