使用 python、borb 和 Adob​​e Acrobat DC,保存文件时为最后一个文本字段输入的值将覆盖前三个文本字段。重新开放

发布于 2025-01-10 07:33:13 字数 2799 浏览 0 评论 0原文

环境

  • 操作系统 – Windows 10
  • Python版本 – 3.10.2
  • Adob​​e Acrobat Reader DC(64位)|持续发布|版本 2021.011.20039 | 64 位

第 1 部分

  1. 使用文件资源管理器使用 Adob​​e Acrobat Reader 打开 output_original.pdf

  2. 更新表单。为每个标签输入相应的值:

    姓名:史密斯

    姓氏:约翰

    支票号码:1000

    金额:5000

  3. 将文件另存为 output_original_results.pdf

  4. 退出阅读器

第 2 部分

  1. 使用文件资源管理器使用 Adob​​e Acrobat Reader 打开 output_original_results.pdf

  2. 比较输入的表单值与显示的值

    姓名:5000

    姓氏:5000

    支票号码:5000

    金额:5000

  3. 对于每个标签,单击文本字段并验证该值是否等于输入的值

代码

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

  1. Using the File Explorer open output_original.pdf using Adobe Acrobat Reader

  2. Update the form. For each label enter the corresponding value:

    Name: Smith

    Surname: John

    Check No.: 1000

    Amount: 5000

  3. Save the file as output_original_results.pdf

  4. Exit the reader

Part 2

  1. Using the File Explorer open output_original_results.pdf using Adobe Acrobat Reader

  2. Compare the form values entered vs. the values displayed

    Name: 5000

    Surname: 5000

    Check No.: 5000

    Amount: 5000

  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文