Extract a separate function from tostream()
This commit is contained in:
parent
316629fa40
commit
c1c77a7453
1 changed files with 8 additions and 8 deletions
|
@ -1075,7 +1075,7 @@ class pdfdoc(object):
|
||||||
self.tostream(stream)
|
self.tostream(stream)
|
||||||
return stream.getvalue()
|
return stream.getvalue()
|
||||||
|
|
||||||
def tostream(self, outputstream=None, return_engine_doc=False):
|
def todoc(self):
|
||||||
if self.engine == Engine.pikepdf:
|
if self.engine == Engine.pikepdf:
|
||||||
PdfArray = pikepdf.Array
|
PdfArray = pikepdf.Array
|
||||||
PdfDict = pikepdf.Dictionary
|
PdfDict = pikepdf.Dictionary
|
||||||
|
@ -1267,12 +1267,11 @@ 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
|
return self.writer, self.output_version
|
||||||
|
|
||||||
# now write out the PDF
|
def tostream(self, outputstream):
|
||||||
if outputstream is None:
|
# write out the PDF
|
||||||
raise TypeError("pdfdoc.tostream() requires outputstream unless return_engine_doc is True.")
|
self.todoc() # finalize self.writer
|
||||||
if self.engine == Engine.pikepdf:
|
if self.engine == Engine.pikepdf:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if pikepdf.__version__ >= "6.2.0":
|
if pikepdf.__version__ >= "6.2.0":
|
||||||
|
@ -1281,6 +1280,7 @@ class pdfdoc(object):
|
||||||
outputstream, min_version=self.output_version, linearize=True, **kwargs
|
outputstream, min_version=self.output_version, linearize=True, **kwargs
|
||||||
)
|
)
|
||||||
elif self.engine == Engine.pdfrw:
|
elif self.engine == Engine.pdfrw:
|
||||||
|
from pdfrw import PdfName, PdfArray
|
||||||
self.writer.trailer.Info = self.writer.docinfo
|
self.writer.trailer.Info = self.writer.docinfo
|
||||||
# setting the version attribute of the pdfrw PdfWriter object will
|
# setting the version attribute of the pdfrw PdfWriter object will
|
||||||
# influence the behaviour of the write() function
|
# influence the behaviour of the write() function
|
||||||
|
@ -2803,11 +2803,11 @@ def convert(*images, **kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
if kwargs["outputstream"]:
|
if kwargs["outputstream"]:
|
||||||
pdf.tostream(outputstream=kwargs["outputstream"])
|
pdf.tostream(kwargs["outputstream"])
|
||||||
return
|
return
|
||||||
|
|
||||||
if kwargs["return_engine_doc"]:
|
if kwargs["return_engine_doc"]:
|
||||||
return pdf.tostream(return_engine_doc=True)
|
return pdf.todoc()
|
||||||
|
|
||||||
return pdf.tostring()
|
return pdf.tostring()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue