使用 python、borb 和 Adobe Acrobat DC,保存文件时为最后一个文本字段输入的值将覆盖前三个文本字段。重新开放
环境
- 操作系统 – Windows 10
- Python版本 – 3.10.2
- Adobe Acrobat Reader DC(64位)|持续发布|版本 2021.011.20039 | 64 位
第 1 部分
使用文件资源管理器使用 Adobe Acrobat Reader 打开 output_original.pdf
更新表单。为每个标签输入相应的值:
姓名:史密斯
姓氏:约翰
支票号码:1000
金额:5000
将文件另存为 output_original_results.pdf
退出阅读器
第 2 部分
使用文件资源管理器使用 Adobe Acrobat Reader 打开 output_original_results.pdf
比较输入的表单值与显示的值
姓名:5000
姓氏:5000
支票号码:5000
金额:5000
对于每个标签,单击文本字段并验证该值是否等于输入的值
代码
from borb.pdf.document import Document
from borb.pdf.page.page import Page
from borb.pdf.pdf import PDF
from borb.pdf.canvas.layout.page_layout.multi_column_layout import SingleColumnLayout
from borb.pdf.canvas.layout.page_layout.page_layout import PageLayout
# Create empty Document
pdf = Document()
# Create empty Page
page = Page()
# Add Page to Document
pdf.append_page(page)
# Create PageLayout
layout: PageLayout = SingleColumnLayout(page)
# New import(s)
from borb.pdf.canvas.layout.table.fixed_column_width_table import FixedColumnWidthTable
from borb.pdf.canvas.layout.text.paragraph import Paragraph
from borb.pdf.canvas.layout.forms.text_field import TextField
from borb.pdf.canvas.color.color import HexColor
from decimal import Decimal
from borb.pdf.canvas.layout.layout_element import Alignment
from borb.pdf.canvas.layout.forms.drop_down_list import DropDownList
# Let's start by adding a heading
layout.add(Paragraph("Patient Information:", font="Helvetica-Bold"))
# Use a table to lay out the form
table: FixedColumnWidthTable = FixedColumnWidthTable(number_of_rows=4, number_of_columns=2)
# Name
table.add(Paragraph("Name : ", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
# Surname
table.add(Paragraph("Surname : ", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
table.add(Paragraph("Check No.", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
table.add(Paragraph("Amount", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
layout.add(table)
# New import(s)
from borb.pdf.pdf import PDF
# Store
with open("output_original.pdf", "wb") as out_file_handle:
PDF.dumps(out_file_handle, pdf)
enter code here
Environment
- OS – Windows 10
- Python Version – 3.10.2
- Adobe Acrobat Reader DC (64-bit) |Continuous Release | Version 2021.011.20039 | 64-bit
Part 1
Using the File Explorer open output_original.pdf using Adobe Acrobat Reader
Update the form. For each label enter the corresponding value:
Name: Smith
Surname: John
Check No.: 1000
Amount: 5000
Save the file as output_original_results.pdf
Exit the reader
Part 2
Using the File Explorer open output_original_results.pdf using Adobe Acrobat Reader
Compare the form values entered vs. the values displayed
Name: 5000
Surname: 5000
Check No.: 5000
Amount: 5000
For each label click on the textfield and verify that the value equals the entered value
Code
from borb.pdf.document import Document
from borb.pdf.page.page import Page
from borb.pdf.pdf import PDF
from borb.pdf.canvas.layout.page_layout.multi_column_layout import SingleColumnLayout
from borb.pdf.canvas.layout.page_layout.page_layout import PageLayout
# Create empty Document
pdf = Document()
# Create empty Page
page = Page()
# Add Page to Document
pdf.append_page(page)
# Create PageLayout
layout: PageLayout = SingleColumnLayout(page)
# New import(s)
from borb.pdf.canvas.layout.table.fixed_column_width_table import FixedColumnWidthTable
from borb.pdf.canvas.layout.text.paragraph import Paragraph
from borb.pdf.canvas.layout.forms.text_field import TextField
from borb.pdf.canvas.color.color import HexColor
from decimal import Decimal
from borb.pdf.canvas.layout.layout_element import Alignment
from borb.pdf.canvas.layout.forms.drop_down_list import DropDownList
# Let's start by adding a heading
layout.add(Paragraph("Patient Information:", font="Helvetica-Bold"))
# Use a table to lay out the form
table: FixedColumnWidthTable = FixedColumnWidthTable(number_of_rows=4, number_of_columns=2)
# Name
table.add(Paragraph("Name : ", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
# Surname
table.add(Paragraph("Surname : ", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
table.add(Paragraph("Check No.", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
table.add(Paragraph("Amount", horizontal_alignment=Alignment.RIGHT, font_color=HexColor("56cbf9")))
table.add(TextField(font_color=HexColor("56cbf9"), font_size=Decimal(20)))
layout.add(table)
# New import(s)
from borb.pdf.pdf import PDF
# Store
with open("output_original.pdf", "wb") as out_file_handle:
PDF.dumps(out_file_handle, pdf)
enter code here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论