Skip to main content

๐Ÿ“‘ PDF API Reference

This page is currently only available in Chinese. Please switch to ็ฎ€ไฝ“ไธญๆ–‡ for the full content.

๐Ÿ“‘ PDF API Reference

Sub-package: popdf | Install: pip install popdf Import: import office or import popdf

The PDF module is the most feature-rich module in python-office (13 functions).

Function Overviewโ€‹

FunctionDescription
pdf2docxPDF to Word
pdf2imgsPDF to image
txt2pdfText to PDF
split4pdfSplit PDF
encrypt4pdfEncrypt PDF
decrypt4pdfDecrypt PDF
merge2pdfMerge PDF
add_text_watermarkText watermark
add_img_waterImage watermark
add_markWatermark (legacy)
add_watermark_by_parametersParameterized watermark
del4pdfDelete pages
add_watermarkInteractive watermark

pdf2docxโ€‹

office.pdf.pdf2docx(
input_file=None,
output_file=None,
input_path=None,
output_path=None
)
office.pdf.pdf2docx(
input_file='document.pdf',
output_file='document.docx'
)

pdf2imgsโ€‹

office.pdf.pdf2imgs(
input_file=None,
output_file=None,
merge=False
)
office.pdf.pdf2imgs(
input_file='document.pdf',
output_file='./long.png',
merge=True
)

txt2pdfโ€‹

office.pdf.txt2pdf(
input_file='text.txt',
output_file='output.pdf'
)

split4pdfโ€‹

office.pdf.split4pdf(
input_file='big.pdf',
output_file='part1.pdf',
from_page=1,
to_page=10
)

encrypt4pdf / decrypt4pdfโ€‹

# Encrypt
office.pdf.encrypt4pdf(
password='mypassword123',
input_file='document.pdf',
output_file='encrypted.pdf'
)

# Decrypt
office.pdf.decrypt4pdf(
password='mypassword123',
input_file='encrypted.pdf',
output_file='decrypted.pdf'
)

merge2pdfโ€‹

office.pdf.merge2pdf(
input_file_list=['1.pdf', '2.pdf', '3.pdf'],
output_file='merged.pdf'
)

add_text_watermarkโ€‹

office.pdf.add_text_watermark(
input_file='document.pdf',
text='Confidential - For Internal Use Only',
output_file='watermarked.pdf',
fontsize=20,
color=(0, 0, 1)
)

add_img_waterโ€‹

office.pdf.add_img_water(
input_file='document.pdf',
mark_file='logo.png',
output_file='watermarked.pdf'
)

add_markโ€‹

Legacy watermark interface.

office.pdf.add_mark(
input_file='document.pdf',
mark_str='python-office',
output_path='./output/'
)

add_watermark_by_parametersโ€‹

Parameterized watermark (recommended).

office.pdf.add_watermark_by_parameters(
input_file='document.pdf',
mark_str='Confidential',
output_path='./output/',
output_file='watermarked.pdf'
)

del4pdfโ€‹

office.pdf.del4pdf(
input_file='document.pdf',
output_file='deleted.pdf',
page_nums=[1, 3]
)

add_watermarkโ€‹

office.pdf.add_watermark() # Interactive
AI ๅŠžๅ…ฌๆ•ˆ็އ่ฏพ
35 ่ฎฒ AI ่‡ชๅŠจๅŒ–ๅŠžๅ…ฌๅฎžๆˆ˜่ฏพ็”จ Python + AI ๅค„็† Excelใ€Wordใ€PDFใ€้‚ฎไปถ็ญ‰ๅŠžๅ…ฌๅœบๆ™ฏใ€‚
ๅŽปๅญฆไน