Skip to content

Convert word to pdf #3261

@sunblog3

Description

@sunblog3

Description of the bug

Example:

import fitz

doc = fitz.open("demo.docx")
pdfbytes = doc.convert_to_pdf()

pdf = fitz.open("pdf", pdfbytes)
pdf.save("some.pdf")

demo.docx

How to reproduce the bug

Result error:

Traceback (most recent call last):
  File "E:\dr\venv\Lib\site-packages\fitz\__init__.py", line 2659, in __init__
    self.this = extra.Document_init( filename, stream, filetype, rect, width, height, fontsize)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\dr\venv\Lib\site-packages\fitz\extra.py", line 153, in Document_init
    return _extra.Document_init(filename, stream, filetype, rect, width, height, fontsize)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: code=2: cannot find fixed document sequence start part

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\dr\html_to_pdf.py", line 3, in <module>
    doc = fitz.open("demo.docx")
          ^^^^^^^^^^^^^^^^^^^^^^
  File "E:\dr\venv\Lib\site-packages\fitz\__init__.py", line 2666, in __init__
    raise FileDataError( MSG_BAD_DOCUMENT) from e
fitz.FileDataError: cannot open broken document

PyMuPDF version

1.23.26

Operating system

Linux

Python version

3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions