Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Linearization crashes with doc.write() method #674

Closed
zufj opened this issue Oct 1, 2020 · 3 comments
Closed

[Bug] Linearization crashes with doc.write() method #674

zufj opened this issue Oct 1, 2020 · 3 comments
Assignees
Labels
bug wontfix no intention to resolve

Comments

@zufj
Copy link

zufj commented Oct 1, 2020

Describe the bug

When attempting to apply the linearization to a document while use the write()method generates the error "RuntimeError: cannot seek in buffer: No such file or directory". This does not happen when using the save() method.

To Reproduce

import fitz
doc = fitz.open(pdf_path)
# Works:
doc.save("linearized.pdf",garbage=0, deflate=False,linear=True)
# Returns error: "RuntimeError: cannot seek in buffer: No such file or directory"
linearized_pdf_bytes = doc.write(garbage=0, deflate=False,linear=True)

Expected behavior

The method should return the bytes of the linearized PDF data.

Your configuration (mandatory)

  • Ubuntu 20.04
  • Python 3.8.5
  • PyMuPDF 1.17.7 installed through pip

3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]

PyMuPDF 1.17.7: Python bindings for the MuPDF 1.17.0 library.
Version date: 2020-09-14 06:33:06.
Built for Python 3.8 on Liinux (64-bit).

@zufj zufj added the bug label Oct 1, 2020
@JorjMcKie
Copy link
Collaborator

Sorry, there is no way to heal this, because it's done by the underlying C library MuPDF.
You must save to disk and re-read the result.
I will update the documentation accordingly.

@JorjMcKie JorjMcKie added the wontfix no intention to resolve label Oct 1, 2020
@zufj
Copy link
Author

zufj commented Oct 1, 2020

Alright. Thanks for the quick answer and pyMuPDF! :)

@jloehel
Copy link
Contributor

jloehel commented Jan 20, 2021

Sorry, there is no way to heal this, because it's done by the underlying C library MuPDF.
You must save to disk and re-read the result.
I will update the documentation accordingly.

Maybe this has changed in the meanwhile. The function pdf_write_document() is calling do_pdf_save_document() which considers the linear option. pdf_save_document() is also calling do_pdf_save_document().

		if (opts->do_linear)
			linearize(ctx, doc, opts);

https://github.com/ArtifexSoftware/mupdf/blob/19057a9569774591bb4b5e3709c94c9a0f9684ac/source/pdf/pdf-write.c#L3466-L3467

Please let me know if I can help in any way with the implementation.

edit: It really looks like that the seek function is not implemented for a output with buffer. (https://github.com/ArtifexSoftware/mupdf/blob/19057a9569774591bb4b5e3709c94c9a0f9684ac/source/fitz/output.c#L287-L291)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug wontfix no intention to resolve
Projects
None yet
Development

No branches or pull requests

3 participants