Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
5ff4c7c
feat: add documentation for importing, exporting, and managing AcroFo…
AnHolub Aug 14, 2025
78ae312
feat: add FDF import functionality to PDF form data handling
AnHolub Aug 26, 2025
078e3b3
fix: update installation guide for Aspose.PDF for Rust via C++
AnHolub Aug 27, 2025
e255262
Merge pull request #490 from aspose-pdf/fixrust
AnHolub Aug 28, 2025
aaff771
Merge remote-tracking branch 'origin/develop' into acroforms
AnHolub Aug 28, 2025
d662d61
fix: moved article Working with Headings in PDF into correct location
andruhovski Sep 1, 2025
6b44868
Merge branch 'develop' of https://github.com/aspose-pdf/Aspose.PDF-Do…
andruhovski Sep 1, 2025
5144623
Merge branch 'master' into develop
andruhovski Sep 1, 2025
39b8cce
Refactor AcroForm examples for Python
AnHolub Sep 2, 2025
f1f3269
Update en/python-net/advanced-operations/working-with-forms/acroforms…
AnHolub Sep 2, 2025
9ef3a5c
Update en/python-net/advanced-operations/working-with-forms/acroforms…
AnHolub Sep 2, 2025
9d001d7
Merge pull request #491 from aspose-pdf/acroforms
AnHolub Sep 2, 2025
bf7185b
Update en/python-net/advanced-operations/working-with-forms/acroforms…
andruhovski Sep 3, 2025
f8f998a
Update en/python-net/advanced-operations/working-with-forms/acroforms…
andruhovski Sep 3, 2025
9100630
fix: fixed typos
andruhovski Sep 3, 2025
ace9735
fix: Rename AcroForms JSON export doc and update sitemap
andruhovski Sep 3, 2025
1089acf
Fix formatting and capitalization in AcroForm documentation
andruhovski Sep 3, 2025
9cb7f3b
Update en/python-net/advanced-operations/working-with-forms/acroforms…
andruhovski Sep 3, 2025
a39ad14
Update en/python-net/advanced-operations/working-with-forms/acroforms…
andruhovski Sep 3, 2025
a1017a1
Update en/python-net/advanced-operations/working-with-forms/acroforms…
andruhovski Sep 3, 2025
caada0a
refactor: Refactor PDF form file path handling in docs
andruhovski Sep 3, 2025
4ac073a
refactor: Update file path handling in AcroForm examples for consistency
andruhovski Sep 4, 2025
05ff256
Fix formatting and typos in AcroForms docs
andruhovski Sep 4, 2025
e9b35d2
Merge branch 'master' into develop
AnHolub Sep 5, 2025
8440c4a
feat: Add FAQ section for Aspose.PDF for Python via .NET with common …
AnHolub Sep 5, 2025
efa7cea
Merge pull request #494 from aspose-pdf/faq_page
AnHolub Sep 5, 2025
be982c5
chore: Update documentation for clarity and consistency
AnHolub Sep 5, 2025
b64b348
chore: Update FAQ metadata for Aspose.PDF for Python via .NET
AnHolub Sep 5, 2025
4bb24b6
Merge branch 'develop' of https://github.com/aspose-pdf/Aspose.PDF-Do…
AnHolub Sep 5, 2025
758ca05
Merge branch 'whats_new' into develop
AnHolub Sep 5, 2025
1aa67bf
chore: Update content for adding headers and footers in PDF documenta…
AnHolub Sep 5, 2025
2e5b5ab
chore: Add documentation for working with PDF layers in Python
AnHolub Sep 8, 2025
7853fc7
Merge pull request #495 from aspose-pdf/layers
AnHolub Sep 8, 2025
d602f89
Update documentation for converting files to PDF in Python
AnHolub Sep 12, 2025
4d1da0f
chore: Add code examples for converting CDR and JPEG images to PDF in…
AnHolub Sep 12, 2025
7558102
Add code examples for converting
AnHolub Sep 14, 2025
6831157
Update en/python-net/advanced-operations/working-with-documents/_inde…
AnHolub Sep 17, 2025
b1dae30
Update en/python-net/advanced-operations/working-with-documents/worki…
AnHolub Sep 17, 2025
b34b5bf
Update lastmod dates and add code examples for converting PDF to PNG …
AnHolub Sep 17, 2025
9f2b211
Add conversion guides for PDF/x and PDF/A formats in Python
AnHolub Sep 17, 2025
d979436
Add documentation for replacing and extracting images in PDF using Py…
AnHolub Sep 18, 2025
45030dd
minoe fix
AnHolub Sep 18, 2025
920f5a5
Update en/python-net/converting/convert-pdfx-to-pdf/_index.md
AnHolub Sep 18, 2025
fd5ac18
Update en/python-net/converting/convert-pdf-to-images-format/_index.md
AnHolub Sep 18, 2025
0f666de
Update en/python-net/converting/convert-pdf-to-images-format/_index.md
AnHolub Sep 18, 2025
461c44a
Update en/python-net/converting/convert-pdf-to-images-format/_index.md
AnHolub Sep 18, 2025
ce0042a
Update conversion guide for PDF/x to include PDF/A compliance details
AnHolub Sep 18, 2025
c4c271d
Update en/python-net/converting/convert-html-to-pdf/_index.md
AnHolub Sep 22, 2025
34d2f3e
Update en/python-net/converting/convert-pdf-to-html/_index.md
AnHolub Sep 22, 2025
7a96828
Update en/python-net/converting/convert-pdf-to-html/_index.md
AnHolub Sep 22, 2025
b899822
Update en/python-net/converting/convert-pdf-to-html/_index.md
AnHolub Sep 22, 2025
c748105
Update en/python-net/converting/convert-pdf-to-images-format/_index.md
AnHolub Sep 22, 2025
71a0e82
Update en/python-net/converting/convert-pdf-to-html/_index.md
AnHolub Sep 22, 2025
d31da15
Update en/python-net/converting/convert-pdf-to-html/_index.md
AnHolub Sep 22, 2025
54af073
Update en/python-net/converting/convert-pdf-to-html/_index.md
AnHolub Sep 22, 2025
578a9c6
Refactor documentation for PDF conversion in Python
AnHolub Sep 22, 2025
142302c
Merge branch 'develop' into conversion
AnHolub Sep 22, 2025
36bf6f1
Merge branch 'develop' into images
AnHolub Sep 22, 2025
f5b66a5
Update extract images from PDF documentation for clarity and detail
AnHolub Sep 22, 2025
991d3a4
Update documentation for converting PDF to Word in Python
AnHolub Sep 22, 2025
d978e65
Update DICOM conversion instructions and code snippets in documentation
AnHolub Sep 22, 2025
1938018
Add abbreviations for image formats in conversion documentation
AnHolub Sep 22, 2025
4a15b30
Update documentation for converting various file formats to PDF in Py…
AnHolub Sep 30, 2025
de9fac3
Update en/python-net/converting/convert-html-to-pdf/_index.md
AnHolub Oct 1, 2025
a63f7d3
Update en/python-net/converting/convert-html-to-pdf/_index.md
AnHolub Oct 1, 2025
4b258fa
Update en/python-net/converting/convert-images-format-to-pdf/_index.md
AnHolub Oct 1, 2025
d9dc909
Add HTML and PPTX abbreviations in conversion documentation
AnHolub Oct 1, 2025
e3f3e01
Update en/python-net/advanced-operations/working-with-images/delete-i…
AnHolub Oct 1, 2025
adae019
Update en/python-net/advanced-operations/working-with-images/extract-…
AnHolub Oct 1, 2025
07643e5
Update en/python-net/advanced-operations/working-with-images/extract-…
AnHolub Oct 1, 2025
7c5594c
Update en/python-net/advanced-operations/working-with-images/extract-…
AnHolub Oct 1, 2025
fcaa343
Update en/python-net/advanced-operations/working-with-images/extract-…
AnHolub Oct 1, 2025
4396619
Refine descriptions for image handling examples in PDF documentation
AnHolub Oct 1, 2025
58e8840
Merge branch 'images' of https://github.com/aspose-pdf/Aspose.PDF-Doc…
AnHolub Oct 1, 2025
1f6bf5d
Merge pull request #497 from aspose-pdf/images
AnHolub Oct 1, 2025
cb698c4
Merge pull request #496 from aspose-pdf/conversion
AnHolub Oct 1, 2025
50c47a2
Merge branch 'master' into develop
andruhovski Oct 1, 2025
5b7513b
Update en/python-net/converting/convert-pdf-to-pdfx/_index.md
andruhovski Oct 1, 2025
fe3ebf3
Apply suggestion from @Copilot
andruhovski Oct 1, 2025
9226320
Update en/python-net/converting/convert-pdf-to-pdfx/_index.md
andruhovski Oct 1, 2025
bc13826
Fix formatting and improve image processing logic in PDF extraction e…
andruhovski Oct 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Work with PDF layers using Python
linktitle: Work with PDF layers
type: docs
weight: 50
url: /net/working-with-pdf-layers/
url: /python-net/working-with-pdf-layers/
description: The next task explains how to lock a PDF layer, extract PDF layer elements, flatten a layered PDF, and merge all layers inside PDF into one.
lastmod: "2025-09-17"
sitemap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type: docs
weight: 40
url: /python-net/working-with-images/
description: This section describes the features of working with images in a PDF file using Python library.
lastmod: "2025-02-27"
lastmod: "2025-09-27"
sitemap:
changefreq: "monthly"
priority: 0.7
Expand All @@ -23,4 +23,6 @@ You are able to do the following:
- [Add Image to Existing PDF File](/pdf/python-net/add-image-to-existing-pdf-file/) - add images and references of a single image in PDF document, after that control quality.
- [Delete Images from PDF File](/pdf/python-net/delete-images-from-pdf-file/) - check code snippet for deleting images from PDF file.
- [Extract Images from PDF File](/pdf/python-net/extract-images-from-pdf-file/) - the next article shows how to extract images from PDF file using Python library.
- [Search and Get Images from PDF Document](/pdf/python-net/search-and-get-images-from-pdf-document/) - you can get an image from an individual page and search among images on all pages with Python.
- [Replace Image in Existing PDF File](/pdf/python-net/replace-image-in-existing-pdf-file/) - check our code snippet, it shows you how to replace an image in a PDF file.

Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,158 @@ type: docs
weight: 10
url: /python-net/add-image-to-existing-pdf-file/
description: This section describes how to add image to existing PDF file using Python library.
lastmod: "2025-02-27"
lastmod: "2025-09-27"
TechArticle: true
AlternativeHeadline: How to add images into PDf using Python
AlternativeHeadline: How to add images into PDF using Python
Abstract: This article provides guidance on adding images to existing PDF files using Python with the Aspose.PDF library. Two methods are outlined for achieving this. The first method involves using the `Document` class from Aspose.PDF, where the user loads the PDF, specifies the page number, and uses the `add_image` method of the `Page` class to position the image. The document is then saved using the `save()` method. The second method utilizes the `PdfFileMend` class from the Aspose.PDF.Facades namespace, which offers a simpler interface. Here, the `add_image()` method is invoked to add the image to the specified page and coordinates, followed by saving the updated PDF and closing the `PdfFileMend` object. Code snippets are provided for both methods to demonstrate the process.
---

## Add Image in an Existing PDF File

The following code snippet shows how to add image in the PDF file.

1. Load the input PDF file.
1. Specify the page number on which the picture will be placed.
1. To define the position of the image on the page call the [Page](https://reference.aspose.com/pdf/python-net/aspose.pdf/page/) class [add_image](https://reference.aspose.com/pdf/python-net/aspose.pdf/page/#methods) method.
1. Call the [Document](https://reference.aspose.com/pdf/python-net/aspose.pdf/document/) class [save()](https://reference.aspose.com/pdf/python-net/aspose.pdf/document/#methods) method.
This example demonstrates how to insert an image into a specific position on a PDF page using Aspose.PDF for Python via .NET.

1. Load the PDF document with 'ap.Document'.
1. Select the target page '(document.pages[1]' - the first page).
1. Use 'page.add_image()' to place the image:
- File path of the image.
- A 'Rectangle' object defining the image’s coordinates (left=20, bottom=730, right=120, top=830).
1. Save the updated PDF.

```python

import aspose.pdf as ap
from io import FileIO
from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, "python", outfile)

document = ap.Document(path_infile)
page = document.pages[1]
page.add_image(
path.join(self.data_dir, image_file),
ap.Rectangle(20, 730, 120, 830, True),
)
document.save(path_outfile)
```

# Open document
document = ap.Document(input_file)

document.pages[1].add_image(image_file, ap.Rectangle(20, 730, 120, 830, True))
## Add an Image Using Operators

document.save(output_pdf)
```
Next code snippet shows a low-level approach to adding an image to a PDF page by manually working with PDF operators rather than high-level helper methods.

## Add Image in an Existing PDF File (Facades)
Steps:

There is also an alternative, easier way to add a Image to a PDF file. You can use [AddImage](https://reference.aspose.com/pdf/python-net/aspose.pdf.facades/pdffilemend/methods/addimage/index) method of the [PdfFileMend](https://reference.aspose.com/pdf/python-net/aspose.pdf.facades/pdffilemend/) class. The [add_image()](https://reference.aspose.com/pdf/python-net/aspose.pdf.facades/pdffilemend/#methods) method requires the image to be added, the page number at which the image needs to be added and the coordinate information. After that, save the updated PDF file, and close the PdfFileMend object using [close()](https://reference.aspose.com/pdf/python-net/aspose.pdf.facades/pdffilemend/#methods) method. The following code snippet shows you how to add image in an existing PDF file.
1. Create a new blank 'Document'.
1. Add a page and set its size (842 × 595 - landscape A4).
1. Access the page’s image resources (page.resources.images).
1. Load the image file into a stream and add it to the resources.
- The method returns an 'image_id'.
- The newly added image object is retrieved from the resources.
1. Define a rectangle that maintains the aspect ratio of the image:
1. Build an operator sequence:
- 'GSave()' - Save the current graphics state.
- 'ConcatenateMatrix(matrix)' - Apply transformation (scale and center the image vertically on the page).
- 'Do(image_id)' - Render the image.
- 'GRestore()' - Restore graphics state.
1. Add the operator sequence to 'page.contents'.
1. Save the resulting PDF.

```python

import aspose.pdf as ap
from io import FileIO
from os import path

path_infile = path.join(self.data_dir, image_file)
path_outfile = path.join(self.data_dir, "python", outfile)

document = ap.Document()
page = document.pages.add()
page.set_page_size(842,595)

# Get page resources
resources_images = page.resources.images

# Add image to resources
image_stream = FileIO(path.join(self.data_dir, path_infile), "rb")
image_id = resources_images.add(image_stream)

# Open document
mender = ap.facades.PdfFileMend()
x_image = list(resources_images)[-1]

# Create PdfFileMend object to add text
mender.bind_pdf(input_file)
rectangle = ap.Rectangle(
0,
0,
page.media_box.width,
(page.media_box.width * x_image.height) / x_image.width,
True,
)

# Add image in the PDF file
mender.add_image(image_file, 1, 100.0, 600.0, 200.0, 700.0)
# Create operator sequence for adding image
operators = []

# Save changes
mender.save(output_pdf)
# Save graphics state
operators.append(ap.operators.GSave())

# Close PdfFileMend object
mender.close()
# Set transformation matrix (position and size)
matrix = ap.Matrix(
rectangle.urx - rectangle.llx,
0,
0,
rectangle.ury - rectangle.lly,
rectangle.llx,
rectangle.llx + (page.media_box.height - rectangle.height) / 2,
)
operators.append(ap.operators.ConcatenateMatrix(matrix))

# Draw the image
operators.append(ap.operators.Do(image_id))

# Restore graphics state
operators.append(ap.operators.GRestore())

# Add operators to page contents
page.contents.add(operators)

document.save(path_outfile)
```

## Add Image with Alternative Text

This example shows how to add an image to a PDF page and assign alternative text (alt text) for accessibility compliance (such as PDF/UA).

1. Create a new 'Document' and add a page (842 × 595, landscape A4).
1. Place the image on the page using 'page.add_image()' with a rectangle that spans the full page.
1. Access the page’s image resources ('page.resources.images').
1. Define an alternative text string (e.g., 'Alternative text for image').
1. Retrieve the first image object from resources ('x_image = resources_images[1]').
1. Use 'try_set_alternative_text(alt_text, page)' to assign alt text to the image.
1. Save the resulting PDF.

```python

import aspose.pdf as ap
from io import FileIO
from os import path

path_image_file = path.join(self.data_dir, image_file)
path_outfile = path.join(self.data_dir, "python", outfile)

document = ap.Document()
page = document.pages.add()
page.set_page_size(842,595)

page.add_image(
path_image_file,
ap.Rectangle(0, 0, 842, 595, True),
)

resources_images = page.resources.images
alt_text = "Alternative text for image"
x_image = resources_images[1]
result = x_image.try_set_alternative_text(alt_text, page)

# If set is successful, then get the alternative text for the image
if (result):
print ("Text has been added successfuly")
document.save(path_outfile)
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ type: docs
weight: 20
url: /python-net/delete-images-from-pdf-file/
description: This section explain how to delete Images from PDF File using Aspose.PDF for Python via .NET.
lastmod: "2025-02-27"
lastmod: "2025-09-27"
TechArticle: true
AlternativeHeadline: How to remove images from PDF using Python
Abstract: The article discusses the various reasons for removing images from PDF files, such as protecting privacy, preventing unauthorized access to sensitive information, reducing file size for easier sharing and storage, and preparing the document for compression or text extraction. It introduces **Aspose.PDF for Python via .NET** as a tool to accomplish this task. The article provides step-by-step instructions and code snippets for deleting specific images or all images from a PDF file using Aspose.PDF. The process involves opening an existing PDF document, deleting images either individually or in bulk, and saving the updated file. The provided Python code demonstrates how to remove images by accessing the document's resources and modifying the desired pages.
---

There are many reasons for removing all or specific images from PDFs.

Sometimes a PDF file may contain important images that need to be removed to protect privacy or prevent unauthorized access to certain information.

Removing unwanted or redundant images can help reduce file size, making it easier to share or store PDFs.

If necessary, you can reduce the number of pages by removing all images from the document.
Also, deleting images from the document will help prepare the PDF for compression or extraction of text information.

Expand All @@ -35,33 +33,12 @@ The following code snippet shows how to delete an image from a PDF file.
```python

import aspose.pdf as ap
from os import path

# Open document
document = ap.Document(input_file)

# Delete particular image
document.pages[2].resources.images.delete(1)

# Save updated PDF file
document.save(output_pdf)
```

## Delete all images from input PDF

```python

import aspose.pdf as ap

# Open document
document = ap.Document(input_file)

# Delete all images on all pages
for i in range(len(document.pages)):
while len(document.pages[i + 1].resources.images) != 0:
document.pages[i + 1].resources.images.delete(1)

# Save updated PDF file
document.save(output_file)
```

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = ap.Document(path_infile)
document.pages[1].resources.images.delete(1)
document.save(path_outfile)
```
Loading