diff --git a/history.txt b/history.txt index 2b25cd8..65c6eb5 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,5 @@ ++ Allow to save result to file-like object. + 17.04.2025 ver.1.7 ------------------ diff --git a/markdown_pdf/__init__.py b/markdown_pdf/__init__.py index e234577..335bc60 100644 --- a/markdown_pdf/__init__.py +++ b/markdown_pdf/__init__.py @@ -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) @@ -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