diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Aspose.PDF-for-Python-via-.NET.iml b/.idea/Aspose.PDF-for-Python-via-.NET.iml new file mode 100644 index 0000000..d552ef2 --- /dev/null +++ b/.idea/Aspose.PDF-for-Python-via-.NET.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3653b1f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3fabe05 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 5ce42ff..b096f4d 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ [Aspose.PDF for Python via .NET](https://products.aspose.com/pdf/python-net) is a Python wrapper that enables the developers to add PDF processing capabilities to their applications. It can be used to generate or read, convert and manipulate PDF files without the use of Adobe Acrobat. -Directory | Description ---------- | ----------- -[examples](examples) | A collection of Python examples that help you learn the product features. -[sample_data](sample_data) | A collection of test data for running Python examples. +| Directory | Description | +|----------------------------|---------------------------------------------------------------------------| +| [examples](examples) | A collection of Python examples that help you learn the product features. | +| [sample_data](sample_data) | A collection of test data for running Python examples. | -

+

- + Download

@@ -20,7 +20,7 @@ Directory | Description - Supports most established PDF standards and PDF specifications. - Ability to read & export PDFs in multiple image formats including BMP, GIF, JPEG & PNG. - Set basic information (e.g. author, creator) of the PDF document. -- Configure PDF Page properties (e.g. width, height, cropbox, bleedbox etc.). +- Configure PDF Page properties (e.g. width, height, cropBox, bleedBox etc.). - Set page numbering, bookmark level, page sizes etc. - Ability to work with text, paragraphs, headings, hyperlinks, graphs, attachments etc. @@ -73,9 +73,9 @@ To learn more about **Aspose.PDF for Python via .NET** and explore the basic req Below code snippet follows these steps: -1. Create an instance of the HtmlLoadOptions object. -1. Initialize Document object. -1. Save output PDF document by calling Document.save() method. +1. Create an instance of the HtmlLoadOptions object. +2. Initialize Document object. +3. Save output PDF document by calling Document.save() method. ```python import aspose.pdf as ap diff --git a/examples/accessibility_tagged_pdf/example_tagged_pdf_extract.py b/examples/accessibility_tagged_pdf/example_tagged_pdf_extract.py index 198f100..a847e59 100644 --- a/examples/accessibility_tagged_pdf/example_tagged_pdf_extract.py +++ b/examples/accessibility_tagged_pdf/example_tagged_pdf_extract.py @@ -36,7 +36,7 @@ def get_root_structure(outfile): tagged_content.set_language("en-US") # Properties StructTreeRootElement and RootElement are used for access to - # StructTreeRoot object of pdf document and to root structure element (Document structure element). + # StructTreeRoot object of PDF document and to root structure element (Document structure element). struct_tree_root_element = tagged_content.struct_tree_root_element root_element = tagged_content.root_element diff --git a/examples/convert_pdf_document/example_html_to_pdf.py b/examples/convert_pdf_document/example_html_to_pdf.py index 5d0a338..f7c9313 100644 --- a/examples/convert_pdf_document/example_html_to_pdf.py +++ b/examples/convert_pdf_document/example_html_to_pdf.py @@ -162,7 +162,7 @@ def convert_WebPage_to_PDF(infile, outfile): convert_WebPage_to_PDF("https://docs.aspose.com/pdf/python-net/", "sample_page.pdf") Note: - This feature is not implemented yet. Requires requests library and temp file handling. + This feature is not implemented yet. It requires requests library and temp file handling. """ raise NotImplementedError("Web page to PDF conversion is not implemented yet") diff --git a/examples/parsing/example_parsing_acroforms.py b/examples/parsing/example_parsing_acroforms.py index 003f6e6..9a1b9bc 100644 --- a/examples/parsing/example_parsing_acroforms.py +++ b/examples/parsing/example_parsing_acroforms.py @@ -30,7 +30,6 @@ def extract_form_fields_JSON(infile, outfile): with io.FileIO(outfile, "w") as json_file: form.export_json(json_file, True) - def extract_form_fields_json_doc(infile, outfile): form = ap.facades.Form(infile) form_data = {} diff --git a/examples/parsing/example_parsing_xfa.py b/examples/parsing/example_parsing_xfa.py new file mode 100644 index 0000000..f4c2d7f --- /dev/null +++ b/examples/parsing/example_parsing_xfa.py @@ -0,0 +1,45 @@ +import sys +from os import path + +import aspose.pdf as ap + +sys.path.append(path.join(path.dirname(__file__), "..")) + +from config import initialize_data_dir, set_license + + +def extract_xfa_form_fields(infile): + + document = ap.Document(infile) + # Get names of XFA form fields + names = document.form.xfa.field_names + + # Get field position + if len(names) > 0: + name0=names[0] + t = document.form.xfa.get_field_template(name0) + print(t.attributes["x"].value) + print(t.attributes["y"].value) + + +def run_all_examples(data_dir=None, license_path=None): + set_license(license_path) + input_dir, output_dir = initialize_data_dir(data_dir) + + examples = [ + ("Extract XFA form fields", extract_xfa_form_fields, "sample-xfa.pdf", None), + ] + + for name, func, input_file, output_file in examples: + try: + args = [path.join(input_dir, input_file)] + if output_file: + args.append(path.join(output_dir, output_file)) + func(*args) + print(f"✅ Success: {name}") + except Exception as e: + print(f"❌ Failed: {name} - {e}") + + +if __name__ == "__main__": + run_all_examples() \ No newline at end of file diff --git a/examples/working_with_documents/example_manipulate_pdf_document.py b/examples/working_with_documents/example_manipulate_pdf_document.py index d916199..0048a9d 100644 --- a/examples/working_with_documents/example_manipulate_pdf_document.py +++ b/examples/working_with_documents/example_manipulate_pdf_document.py @@ -10,7 +10,10 @@ def _validate_pdfa_standard(input_pdf, output_pdf, pdf_format): document = ap.Document(input_pdf) - document.validate(output_pdf, pdf_format) + if (document.validate(output_pdf, pdf_format)): + print("PDF is valid") + else: + print("PDF is not valid") def validate_pdfa_standard_a1a(input_pdf, output_pdf): @@ -164,9 +167,7 @@ def set_pdf_expiry_date(input_pdf, output_pdf): def flatten_fillable_pdf(input_pdf, output_pdf): document = ap.Document(input_pdf) - if document.form and document.form.fields: - for field in document.form.fields: - field.flatten() + document.flatten() document.save(output_pdf) diff --git a/examples/working_with_text/example_text_adding.py b/examples/working_with_text/example_text_adding.py index 5e23bd5..08a90b7 100644 --- a/examples/working_with_text/example_text_adding.py +++ b/examples/working_with_text/example_text_adding.py @@ -320,6 +320,7 @@ def add_text_with_rtl_text(output_file_name): text_fragment.horizontal_alignment = ap.HorizontalAlignment.RIGHT page.paragraphs.add(text_fragment) + document.direction = ap.Direction.R2L document.save(output_file_name) diff --git a/sample_data/parsing/input/sample-xfa.pdf b/sample_data/parsing/input/sample-xfa.pdf new file mode 100644 index 0000000..f2b7f2c Binary files /dev/null and b/sample_data/parsing/input/sample-xfa.pdf differ