Skip to content

Commit

Permalink
Add pdf_bytes
Browse files Browse the repository at this point in the history
Returns pdf as ByteArray
  • Loading branch information
EduardoSFReis committed Dec 16, 2024
1 parent f2b2c00 commit 69f8e92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pyreportjasper/pyreportjasper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class PyReportJasper:
'csv_meta',
'ods',
'pptx',
'jrprint'
'jrprint',
'pdf_bytes'
)

METHODS = ('GET', 'POST', 'PUT')
Expand Down Expand Up @@ -164,6 +165,7 @@ def process_report(self):
try:
formats_functions = {
'pdf': report.export_pdf,
'pdf_bytes': report.export_pdf_bytes,
'html': report.export_html,
'rtf': report.export_rtf,
'docx': report.export_docx,
Expand All @@ -181,7 +183,7 @@ def process_report(self):
for f in self.config.outputFormats:
export_function = formats_functions.get(f)
if export_function:
export_function()
data = export_function()
else:
raise NameError("Error output format {} not implemented!".format(f))
except Exception as ex:
Expand All @@ -192,7 +194,7 @@ def process_report(self):
error = NameError('Error: not a file: {}'.format(self.config.input))
if error:
raise error
return True
return data

def list_report_params(self):
report = Report(self.config, self.config.input)
Expand Down
5 changes: 5 additions & 0 deletions pyreportjasper/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ def fetch_pdf_report(self):
res = self.String(output_stream_pdf.toByteArray(), 'UTF-8')
return bytes(str(res), 'UTF-8')

def export_pdf_bytes(self):
output_stream_pdf = self.get_output_stream_pdf()
pdf_bytes = output_stream_pdf.toByteArray()
return pdf_bytes

def export_pdf(self):
output_stream = self.get_output_stream('.pdf')
output_stream_pdf = self.get_output_stream_pdf()
Expand Down

0 comments on commit 69f8e92

Please sign in to comment.