Skip to main content

A 100% standalone Pdf Python API for Processing Pdf Files

Project description

Independent Python API for PDF Creating, Editing, and Converting

Foo

Product Page | Documentation | Examples | Forum | Temporary License | Customized Demo

Spire.PDF for Python is an independent Python API that enables developers to create, read, edit, save, and convert PDF files in Python programs. It provides developers with various functions to process PDF documents without any other dependencies.

Spire.PDF for Python supports various PDF features including security settings, extracting text/image from PDF, merging/splitting PDF, drawing text/image/shape/barcode to PDF, creating and filling in form fields, adding tables to PDF, compressing PDF documents, etc.

With this professional Python API, developers can also easily convert PDF to XPS, XPS to PDF, PDF to SVG, SVG to PDF, PDF to Excel, PDF to Word, PDF to HTML, HTML to PDF and PDF to PDF/A in high quality.

Support for Various PDF Versions

  • PDF 1.2 to PDF 1.7
  • PDF/A - 1b
  • PDF/x1a
  • PDF/A1
  • PDF/A2
  • PDF/A3
  • PDF/UA

High-Fidelity PDF File Conversion

  • Convert HTML to PDF
  • Convert HTML to PDF
  • Convert Image to PDF
  • Convert Text to PDF
  • Convert PDF to HTML
  • Convert XPS to PDF
  • Convert PDF to SVG
  • Convert PDF to XPS
  • Convert PDF to Image
  • Convert PDF to Word
  • Convert PDF to Excel

Security Features

Spire.PDF for Python can protect PDF documents by setting passwords and adding digital signatures. User password and owner password can determine the encrypted PDF documents readability, modifiability, printability and other selective restrictions. And digital signatures can ensure the authenticity and integrity of PDF documents, and confirm the identity in document exchange.

Examples

Create a PDF document in Python

from spire.pdf.common import *
from spire.pdf import *

outputFile = "HelloWorld.pdf"

#Create a pdf document
doc= PdfDocument()
#Create one page
page = doc.Pages.Add()
s = "Hello, World"
x = 10.0
y = 10.0
font = PdfFont(PdfFontFamily.Helvetica ,30.0)
color = PdfRGBColor(Color.get_Black())
textBrush = PdfSolidBrush(color)
#Draw the text
page.Canvas.DrawString(s, font, textBrush, x, y)
#Save the document
doc.SaveToFile(outputFile)
doc.Close()

Convert PDF to Word

from spire.pdf.common import *
from spire.pdf import *

outputFile = "ToDocx.docx"
inputFile = "./Demos/Data/ToDocx.pdf"

# Load a pdf document
inputfile = inputFile
doc = PdfDocument()
doc.LoadFromFile(inputfile)
# Convert to doc file.
doc.SaveToFile(outputFile, FileFormat.DOCX)
doc.Close()

Add a watermark to PDF

from spire.pdf.common import *
from spire.pdf import *

inputFile = "./Demos/Data/ImageWaterMark.pdf"
outputFile = "TextWaterMark.pdf"

#Create a pdf document and load file from disk
doc = PdfDocument()
doc.LoadFromFile(inputFile)
#Get the first page
page = doc.Pages[0]
#Draw text watermark
brush = PdfTilingBrush(SizeF(page.Canvas.ClientSize.Width / float(2), page.Canvas.ClientSize.Height / float(3)))
brush.Graphics.SetTransparency(0.3)
brush.Graphics.Save()
brush.Graphics.TranslateTransform(brush.Size.Width / float(2), brush.Size.Height / float(2))
brush.Graphics.RotateTransform(-45.0)
brush.Graphics.DrawString("Spire.Pdf Demo", PdfFont(PdfFontFamily.Helvetica, 24.0), PdfBrushes.get_Violet(), 0.0, 0.0, PdfStringFormat(PdfTextAlignment.Center))
brush.Graphics.Restore()
brush.Graphics.SetTransparency(1.0)
page.Canvas.DrawRectangle(brush, RectangleF(PointF(0.0, 0.0), page.Canvas.ClientSize))
#Save pdf file
doc.SaveToFile(outputFile)
doc.Close()

Add a stamp to PDF

from spire.pdf.common import *
from spire.pdf import *

inputFile = "./Demos/Data/AddTextStamp.pdf"
outputFile = "AddTextStamp_out.pdf"

#Open a pdf document
document = PdfDocument()
document.LoadFromFile(inputFile)
#Get the first page
page = document.Pages[0]
#Create a pdf template
template = PdfTemplate(125.0, 55.0)
font1 = PdfTrueTypeFont("Elephant", 10.0, PdfFontStyle.Italic, True)
brush = PdfSolidBrush(PdfRGBColor(Color.get_DarkRed()))
pen = PdfPen(brush)
rectangle = RectangleF(PointF(5.0, 5.0), template.Size)
CornerRadius = 20.0
path = PdfPath()
path.AddArc(template.GetBounds().X, template.GetBounds().Y, CornerRadius, CornerRadius, 180.0, 90.0)
path.AddArc(template.GetBounds().X + template.Width - CornerRadius, template.GetBounds().Y, CornerRadius, CornerRadius, 270.0, 90.0)
path.AddArc(template.GetBounds().X + template.Width - CornerRadius, template.GetBounds().Y + template.Height - CornerRadius, CornerRadius, CornerRadius, 0.0, 90.0)
path.AddArc(template.GetBounds().X, template.GetBounds().Y + template.Height - CornerRadius, CornerRadius, CornerRadius, 90.0, 90.0)
path.AddLine(template.GetBounds().X, template.GetBounds().Y + template.Height - CornerRadius, template.GetBounds().X, template.GetBounds().Y + CornerRadius / float(2))
template.Graphics.DrawPath(pen, path)
#Draw stamp text
s1 = "REVISED\n"
s2 = "by E-iceblue at " + DateTime.get_Now().ToString("MM dd, yyyy")
template.Graphics.DrawString(s1, font1, brush, PointF(5.0, 10.0))
font2 = PdfTrueTypeFont("Lucida Sans Unicode", 9.0, PdfFontStyle.Bold, True)
template.Graphics.DrawString(s2, font2, brush, PointF(2.0, 30.0))
#Create a rubber stamp
stamp = PdfRubberStampAnnotation(rectangle)
apprearance = PdfAppearance(stamp)
apprearance.Normal = template
stamp.Appearance = apprearance
#Draw stamp into page
page.AnnotationsWidget.Add(stamp)
#Save pdf document
document.SaveToFile(outputFile)
document.Close()

Product Page | Documentation | Examples | Forum | Temporary License | Customized Demo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

Spire.Pdf-9.9.0-py3-none-win_amd64.whl (26.0 MB view details)

Uploaded Python 3 Windows x86-64

Spire.Pdf-9.9.0-py3-none-manylinux1_x86_64.whl (40.4 MB view details)

Uploaded Python 3

File details

Details for the file Spire.Pdf-9.9.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: Spire.Pdf-9.9.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 26.0 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for Spire.Pdf-9.9.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5919d0642876ddd473bd3ce1a5db907cb5ae9b8e94c02bc3caa39d164a0dca0a
MD5 7cf44ce91a2c9a03b0f74eea57ee0bf2
BLAKE2b-256 09447b7fb23c5be6550865e05d7837afdcfb7a160a5a62c8559c2001c523ec47

See more details on using hashes here.

File details

Details for the file Spire.Pdf-9.9.0-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for Spire.Pdf-9.9.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cd402beb48bba1c4b14a22505c16d240d868bbc031938321247050b7e01a98ee
MD5 1c822ae63e37f2e5bf6271477429dfd1
BLAKE2b-256 5d099b342e0fa80a5629e371eb0b8e5bf985f7f9f34f3c433b99460e9f039f92

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page