convert(): add option to return the engine document handle

This commit is contained in:
mara004 2024-08-26 13:26:55 +02:00
parent 819b366bf5
commit be313aa793

View file

@ -1075,7 +1075,7 @@ class pdfdoc(object):
self.tostream(stream) self.tostream(stream)
return stream.getvalue() return stream.getvalue()
def tostream(self, outputstream): def tostream(self, outputstream, return_engine_doc=False):
if self.engine == Engine.pikepdf: if self.engine == Engine.pikepdf:
PdfArray = pikepdf.Array PdfArray = pikepdf.Array
PdfDict = pikepdf.Dictionary PdfDict = pikepdf.Dictionary
@ -1267,6 +1267,9 @@ class pdfdoc(object):
self.writer.addobj(metadata) self.writer.addobj(metadata)
self.writer.addobj(iccstream) self.writer.addobj(iccstream)
if return_engine_doc:
return self.writer, self.output_version
# now write out the PDF # now write out the PDF
if self.engine == Engine.pikepdf: if self.engine == Engine.pikepdf:
kwargs = {} kwargs = {}
@ -2634,6 +2637,7 @@ def convert(*images, **kwargs):
viewer_center_window=False, viewer_center_window=False,
viewer_fullscreen=False, viewer_fullscreen=False,
outputstream=None, outputstream=None,
return_engine_doc=False,
first_frame_only=False, first_frame_only=False,
allow_oversized=True, allow_oversized=True,
cropborder=None, cropborder=None,
@ -2800,6 +2804,9 @@ def convert(*images, **kwargs):
pdf.tostream(kwargs["outputstream"]) pdf.tostream(kwargs["outputstream"])
return return
if kwargs["return_engine_doc"]:
return pdf.tostream(None, return_engine_doc=True)
return pdf.tostring() return pdf.tostring()