Add Images to PDF document via Python

Insert images to PDF document programmatically using Aspose.PDF for Python via C++ Library

Add Image to PDF Document Using Python Library

In order to add Image in PDF, we’ll use Aspose.PDF for Python via C++ API which is a feature-rich, powerful and easy to use document manipulation API for Python platform.

Add Image to PDF using Python


You need Aspose.PDF for Python via C++ to try the code in your environment.

  1. Import the Aspose.PDF module.
  2. Define a constant for output file.
  3. Define a constant for image file.
  4. Call the AsposePdf function.
  5. Call the AsposePdfAddImage method.
  6. Use the console.log method to print the result.

Add Image to PDF document - Python

This sample code shows how to add Images into PDF page - Python

import AsposePDFPythonWrappers as apw
document = apw.Document("sample.pdf")
image = apw.Image()
image.file = "sample.jpg"
image.fix_height = 110
image.fix_width = 89
document.pages[1].paragraphs.add(image)
document.save("sample-image.pdf")