What's new
What’s new in Aspose.PDF 23.12
From Aspose.PDF 23.12, support was added to the new conversion features:
- Implement PDF to Markdown conversion
import aspose.pdf as ap
input_pdf_path = DIR_INPUT + "input.pdf"
markdown_output_file_path = DIR_OUTPUT + "output_md_file.md"
doc = ap.Document(input_pdf_path)
save_options = ap.pdftomarkdown.MarkdownSaveOptions()
save_options.resources_directory_name = "images"
doc.save(markdown_output_file_path, save_options)
- Implement OFD to PDF conversion
import aspose.pdf as ap
input_path = DIR_INPUT + "input.ofd"
output_path = DIR_OUTPUT + "output.pdf"
document = ap.Document(input_path, ap.OfdLoadOptions())
document.save(output_path)
Support for Python 3.6 has been discontinued.
What’s new in Aspose.PDF 23.11
Since 23.11 possible to remove the hidden text. The following code snippet can be used:
import aspose.pdf as ap
document = ap.Document(input_file)
text_absorber = ap.text.TextFragmentAbsorber()
# This option can be used to prevent other text fragments from moving after hidden text replacement.
text_absorber.text_replace_options = ap.text.TextReplaceOptions(ap.text.TextReplaceOptions.ReplaceAdjustment.NONE)
document.pages.accept(text_absorber)
for fragment in text_absorber.text_fragments:
if fragment.text_state.invisible:
fragment.text = ''
document.save(output_file)
What’s new in Aspose.PDF 23.8
Since the 23.8 version supports to add Incremental Updates detection.
The function for detecting Incremental Updates in a PDF document has been added. This function returns ’true’ if a document was saved with incremental updates; otherwise, it returns ‘false’.
import aspose.pdf as ap
doc = ap.Document(file_path)
updated = doc.has_incremental_update()
print(updated)
Also, 23.8 supports the ways to work with nested checkbox fields. Many fillable PDF forms have checkbox fields that act as radio groups:
- Create multi-value checkbox field:
import aspose.pdf as ap
document = ap.Document()
page = document.pages.add()
checkbox = ap.forms.CheckboxField(page, ap.Rectangle(50, 50, 70, 70, True))
# Set the first checkbox group option value
checkbox.export_value = "option 1"
# Add new option right under existing ones
checkbox.add_option("option 2")
# Add new option at the given rectangle
checkbox.add_option("option 3", ap.Rectangle(100, 100, 120, 120, True))
document.form.add(checkbox)
# Select the added checkbox
checkbox.value = "option 2"
document.save(DIR_OUTPUT + "checkbox_group.pdf")
- Get and set value of a multi-value checkbox:
import aspose.pdf as ap
doc = ap.Document("example.pdf")
form = doc.form
checkbox = cast(ap.forms.CheckboxField, form.fields[0])
# Allowed values may be retrieved from the AllowedStates collection
# Set the checkbox value using Value property
checkbox.value = checkbox.allowed_states[0]
checkbox_value = checkbox.value # the previously set value, e.g. "option 1"
# The value should be any element of AllowedStates
checkbox.value = "option 2"
checkbox_value = checkbox.value # option 2
# Uncheck boxes by either setting Value to "Off" or setting Checked to false
checkbox.value = "Off"
# or, alternately:
# checkbox.checked = False
checkbox_value = checkbox.value # Off
- Update checkbox state on user click:
import aspose.pdf as ap
from aspose.pycore import cast
input_file = DIR_INPUT + "input.pdf"
document = ap.Document(input_file)
point = ap.Point(62,462) # for example, the coordinates of a mouse click
# Option 1: look through the annotations on the page
page = document.pages[5]
for annotation in page.annotations:
if(annotation.rect.contains(point)):
widget = cast(ap.annotations.WidgetAnnotation, annotation)
checkbox = cast(ap.forms.CheckboxField, widget.parent)
if(annotation.active_state == "Off"):
checkbox.value = widget.get_checked_state_name()
else:
checkbox.value = "Off"
break
# Option 2: look through the fields in the AcroForm
for widget in document.form:
field = cast(ap.forms.Field, widget)
if(field == None):
continue
checkBoxFound = False
for annotation in field:
if(annotation.rect.contains(point)):
checkBoxFound = True
if(annotation.active_state=="Off"):
annotation.parent.value = annotation.get_checked_state_name()
else:
annotation.parent.value = "Off"
if(checkBoxFound):
break
What’s new in Aspose.PDF 23.7
Since the 23.7 version supports to add the shape extraction:
import aspose.pdf as ap
input1_file = DIR_INPUT + "input_1.pdf"
input2_file = DIR_INPUT + "input_2.pdf"
source = ap.Document(input1_file)
dest = ap.Document(input2_file)
graphic_absorber = ap.vector.GraphicsAbsorber()
graphic_absorber.visit(source.pages[1])
area = ap.Rectangle(90, 250, 300, 400, True)
dest.pages[1].add_graphics(graphic_absorber.elements, area)
Also supports the ability to detect Overflow when adding text:
import aspose.pdf as ap
output_file = DIR_OUTPUT + "output.pdf"
doc = ap.Document()
paragraph_content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras nisl tortor, efficitur sed cursus in, lobortis vitae nulla. Quisque rhoncus, felis sed dictum semper, est tellus finibus augue, ut feugiat enim risus eget tortor. Nulla finibus velit nec ante gravida sollicitudin. Morbi sollicitudin vehicula facilisis. Vestibulum ac convallis erat. Ut eget varius sem. Nam varius pharetra lorem, id ullamcorper justo auctor ac. Integer quis erat vitae lacus mollis volutpat eget et eros. Donec a efficitur dolor. Maecenas non dapibus nisi, ut pellentesque elit. Sed pellentesque rhoncus ante, a consectetur ligula viverra vel. Integer eget bibendum ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur elementum, sem a auctor vulputate, ante libero iaculis dolor, vitae facilisis dolor lorem at orci. Sed laoreet dui id nisi accumsan, id posuere diam accumsan."
fragment = ap.text.TextFragment(paragraph_content)
rectangle = ap.Rectangle(100, 600, 500, 700, False)
paragraph = ap.text.TextParagraph()
paragraph.vertical_alignment = ap.VerticalAlignment.TOP
paragraph.formatting_options.wrap_mode = ap.text.TextFormattingOptions.WordWrapMode.BY_WORDS
paragraph.rectangle = rectangle
is_fit_rectangle = fragment.text_state.is_fit_rectangle(paragraph_content, rectangle)
while is_fit_rectangle == False:
fragment.text_state.font_size -= 0.5
is_fit_rectangle = fragment.text_state.is_fit_rectangle(paragraph_content, rectangle)
paragraph.append_line(fragment)
builder = ap.text.TextBuilder(doc.pages.add())
builder.append_paragraph(paragraph)
doc.save(output_file)
What’s new in Aspose.PDF 23.6
Support the ability to set the title of the HTML, Epub page:
import aspose.pdf as ap
input_pdf = DIR_INPUT + "input.pdf"
output_html = DIR_OUTPUT + "output_title.html"
options = ap.HtmlSaveOptions()
options.fixed_layout = True
options.raster_images_saving_mode = ap.HtmlSaveOptions.RasterImagesSavingModes.AS_EMBEDDED_PARTS_OF_PNG_PAGE_BACKGROUND
options.parts_embedding_mode = ap.HtmlSaveOptions.PartsEmbeddingModes.EMBED_ALL_INTO_HTML
options.title = "NEW PAGE & TITILE" # <-- this added
document = ap.Document(input_pdf)
document.save(output_html, options)
What’s new in Aspose.PDF 23.5
Since the 23.5 version supports to add RedactionAnnotation FontSize option. Use the next code snippet to solve this task:
import aspose.pdf as ap
doc = ap.Document(DIR_INPUT + "input.pdf")
# Create RedactionAnnotation instance for specific page region
annot = ap.annotations.RedactionAnnotation(doc.pages[1], ap.Rectangle(367, 756.919982910156, 420, 823.919982910156, True))
annot.fill_color = ap.Color.black
annot.border_color = ap.Color.yellow
annot.color = ap.Color.blue
# Text to be printed on redact annotation
annot.overlay_text = "(Unknown)"
annot.text_alignment = ap.HorizontalAlignment.CENTER
# Repat Overlay text over redact Annotation
annot.repeat = False
# New property there !
annot.font_size = 20
# Add annotation to annotations collection of first page
doc.pages[1].annotations.add(annot, False)
# Flattens annotation and redacts page contents (i.e. removes text and image
# Under redacted annotation)
annot.redact()
out_file = DIR_OUTPUT + "RedactPage_out.pdf"
doc.save(out_file)
Support for Python 3.5 has been discontinued. Support for Python 3.11 has been added.
What’s new in Aspose.PDF 23.3
Version 23.3 introduced support for adding a resolution to an image. Two methods can be used to solve this problem:
import aspose.pdf as ap
input_file = DIR_INPUT + "input.jpg"
table = ap.Table()
table.column_widths = "600"
image = ap.Image()
image.is_apply_resolution = True
image.file = input_file
for i in range(0, 2):
row = table.rows.add()
cell = row.cells.add()
cell.paragraphs.add(image)
page.paragraphs.add(table)
The image will be placed with scaled resolution or u can set FixedWidth or FixedHeight properties in combination with IsApplyResolution
What’s new in Aspose.PDF 23.1
Since the 23.1 version supports to creation of PrinterMark annotation.
Printer’s marks are graphic symbols or text added to a page to assist production personnel in identifying components of a multiple-plate job and maintaining consistent output during production. Examples commonly used in the printing industry include:
- Registration targets for aligning plates
- Gray ramps and colour bars for measuring colours and ink densities
- Cut marks showing where the output medium is to be trimmed
We will show the example of the option with color bars for measuring colors and ink densities. There is a basic abstract class PrinterMarkAnnotation and from it child ColorBarAnnotation - which already implements these stripes. Let’s check the example:
import aspose.pdf as ap
out_file = DIR_OUTPUT + "ColorBarTest.pdf"
doc = ap.Document()
page = doc.pages.add()
page.trim_box = ap.Rectangle(20, 20, 580, 820, True)
add_annotations(page)
doc.save(out_file)
def add_annotations(page: ap.Page):
rect_black = ap.Rectangle(100, 300, 300, 320, True)
rect_cyan = ap.Rectangle(200, 600, 260, 690, True)
rect_magenta = ap.Rectangle(10, 650, 140, 670, True)
color_bar_black = ap.annotations.ColorBarAnnotation(page, rect_black, ap.annotations.ColorsOfCMYK.BLACK)
color_bar_cyan = ap.annotations.ColorBarAnnotation(page, rect_cyan, ap.annotations.ColorsOfCMYK.CYAN)
color_ba_magenta = ap.annotations.ColorBarAnnotation(page, rect_magenta, ap.annotations.ColorsOfCMYK.BLACK)
color_ba_magenta.color_of_cmyk = ap.annotations.ColorsOfCMYK.MAGENTA
color_bar_yellow = ap.annotations.ColorBarAnnotation(page, ap.Rectangle(400, 250, 450, 700, True), ap.annotations.ColorsOfCMYK.YELLOW)
page.annotations.add(color_bar_black, False)
page.annotations.add(color_bar_cyan, False)
page.annotations.add(color_ba_magenta, False)
page.annotations.add(color_bar_yellow, False)
Also support the vector images extraction. Try using the following code to detect and extract vector graphics:
import aspose.pdf as ap
input_pdf = DIR_INPUT + "input.pdf"
output_pdf = DIR_OUTPUT + "output.svg"
doc = ap.Document(input_pdf)
doc.pages[1].try_save_vector_graphics(output_pdf)