Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
+ Allow to save result to file-like object.

17.04.2025 ver.1.7
------------------

Expand Down
6 changes: 4 additions & 2 deletions markdown_pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def save(self, file_name: typing.Union[str, pathlib.Path]) -> None:
doc.save(file_name)
doc.close()

def save_bytes(self, bytesio: io.BytesIO) -> None:
"""Save pdf to file-like object."""
def save_bytes(self, bytesio: io.BytesIO) -> int:
"""Save pdf to file-like object and return byte size of the filled object."""
doc = self._make_doc()

pdf = _as_pdf_document(doc)
Expand Down Expand Up @@ -150,3 +150,5 @@ def save_bytes(self, bytesio: io.BytesIO) -> None:
out = JM_new_output_fileptr(bytesio)
mupdf.pdf_write_document(pdf, out, opts)
out.fz_close_output()

return bytesio.getbuffer().nbytes