Skip to content

Commit

Permalink
[BP] CLI/render: fix XFA document length recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed May 9, 2024
1 parent eded6c2 commit 2577f5b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/pypdfium2/_cli/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ def add_n_digits(parser):
)


def get_input(args, **kwargs):
def get_input(args, init_forms=False, **kwargs):
pdf = pdfium.PdfDocument(args.input, password=args.password, **kwargs)
if init_forms:
pdf.init_forms()
if "pages" in args and not args.pages:
args.pages = [i for i in range(len(pdf))]
return pdf
Expand Down
5 changes: 1 addition & 4 deletions src/pypdfium2/_cli/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def main(args):

# TODO turn into a python-usable API yielding output paths as they are written

pdf = get_input(args)
pdf = get_input(args, init_forms=args.draw_forms)

# TODO move to parsers?
pdf_len = len(pdf)
Expand Down Expand Up @@ -349,9 +349,6 @@ def main(args):
if len(args.pages) <= args.linear:

logger.info("Linear rendering ...")
if args.draw_forms:
pdf.init_forms()

for i in args.pages:
_render_job(i, pdf, kwargs, engine)

Expand Down
5 changes: 2 additions & 3 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def init_forms(self, config=None):
Initialize a form env, if the document has forms. If already initialized, nothing will be done.
See the :attr:`formenv` attribute.
Note:
If form rendering is desired, this method should be called directly after constructing the document,
before getting any page handles (due to PDFium's API).
Attention:
If form rendering is desired, this method shall be called immediately after document construction, before getting document length or page handles.
Parameters:
config (FPDF_FORMFILLINFO | None):
Expand Down

0 comments on commit 2577f5b

Please sign in to comment.