Saving table to PDF

Hi guys, Have a good days.

Currently I’m trying to save the table data to pdf format. I’m able to saved it in pdf file but the pdf file cant open.
Below are my sample code to export table data to pdf format

fileName1 = "Audit_Log.pdf"
data1 = system.db.runNamedQuery("Login_Logout")
excelbytes1 = system.dataset.dataSetToHTML(1, data1, "Audit Log")
#excelbytes1 = system.file.readFileAsBytes(1, data1, "Audit Log")
system.perspective.download(fileName1, excelbytes1)

Thanks in advance.

You are converting a dataset to HTML, but trying to deliver that as a PDF. There’s no magic that will convert HTML to PDF for you.

Thanks Mr pturmel. I just notice that sorry for my mistake. May I know what is the best way to do this ?

The supported way to get a PDF is to define a report with a table containing your dataset, then execute your report to get the bytes to download.

3 Likes

It will not solve the problem in this post directly, but I’d like to leave an honorable mention for a piece of genuine magic: pandoc, which converts to/from a dizzying array of formats (admittedly, with limited degrees of success):
https://pandoc.org/MANUAL.html#

Hi Sir, do you have any example about what you’re saying ? I’m confusing because I had try what you mentioned but it cant work. Hope I can get your help. Much Appreciate

Hi Sir pturmel, I’m still facing the same problem which my download button cannot work. Can you please explain further for your answer or provide me any guidelines to do it. Much appreciate Sir. Thanks in advance.

The supported way is to use the Report module
https://docs.inductiveautomation.com/display/DOC80/Reporting