Last active
April 21, 2023 05:51
How to Create Tagged PDF using Python. For further details: https://kb.aspose.com/pdf/python/how-to-create-tagged-pdf-using-python/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pdf as pdf | |
# Load License | |
license = pdf.License() | |
license.set_license("Aspose.Total.lic") | |
# Create a PDF | |
document = pdf.Document() | |
# Get the tagged content and root element | |
taggedContent = document.tagged_content | |
rootElement = taggedContent.root_element | |
# Set Title and Language | |
taggedContent.set_title("A Pdf Document with tags") | |
taggedContent.set_language("en-US") | |
# Create a header and set the text | |
mainHeader = taggedContent.create_header_element() | |
mainHeader.set_text("Top Header") | |
# Create a paragraph and set the text | |
paragraphElement = taggedContent.create_paragraph_element() | |
paragraphElement.set_text("This is a sample text for the paragraph " + | |
"element that is appended to the root element later") | |
# Append header and paragraph to the root element | |
rootElement.append_child(mainHeader) | |
rootElement.append_child(paragraphElement) | |
# Save the tagged PDF Document | |
document.save("SampleTagged.pdf") | |
print("Tagged PDF created successfully") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment