Printing a Report

Hi everyone,

I have read the docs, which state system.report.executeReport() returns a byte array. The following code creates a document that cannot be viewed. Almost like it’s corrupt. System.file.writeFile() writes the report correctly so I don’t think the issue pertains to the returned datatype from system.report.executeReport() but I am not sure what to think at this point. Currently, I have the print service as Microsoft to PDF. I figured if it can’t do that it won’t print to a physical printer. Printing with the report viewer on a window works fine. I have a need to control this programmatically. How is the report viewer able to print this document? Can you help me understand what’s going wrong here?

`from javax.print import PrintService, PrintServiceLookup, SimpleDoc, DocFlavor
from org.python.core.util import StringUtil
overrides = {
"Serial Number":254210004
,"InterlockID":1885702
,"RTResultID":12346742
,"ILResultID":12346227
,"CBResultID":12346463

}

testReport = system.report.executeReport(path="Warranty Profile & Report Card",project="redacted",
parameters=overrides, fileType='pdf')
#system.file.writeFile("C:\Users\Ooops\OneDrive - redacted\Documents\RandomPDFTest.pdf", testReport)

doc = SimpleDoc(testReport,DocFlavor.BYTE_ARRAY.AUTOSENSE,None)

##defaultPrinter = PrintServiceLookup.lookupDefaultPrintService()
##print defaultPrinter
###defaultPrinter.createPrintJob().print(doc,None)

printers = list(PrintServiceLookup.lookupPrintServices(None,None))
pdfPrint = printers[9]
print pdfPrint
pdfPrint.createPrintJob().print(doc,None)`

Printers don't accept PDF bytes as a printer document. The report viewer (or PDF viewer) renders each page to a print job. :man_shrugging:

I think I need to change my approach and play with the ReportViewer component. This report is a warranty document that is unit specific. A user should be able to pass in the serial number and the report populates the relevant information. I keep running into walls trying to get this to work. It’s not throwing an error but something is clearly wrong with the print data that is being generated.

Update, the physical printer did print but my document is all over the place. I will report back if I can get this to work.

The PDF format has embedded Postscript format plus a bunch of additional metadata. The printer is probably interpreting what it can (the Postscript parts), and scrambling the rest.

System.report.executeReport() in my use case returns a PDF byte array right? Why doesn’t SimpleDoc(testReport,DocFlavor.BYTE_ARRAY.PDF,None) Work? What would it be autosensing to?
Currently, the header, tables, and images are all in their correct location. Its the texts that is not in the correct location. The text is correct but all over the place, I feel a mixture of frustration and amusement.

Here is the javadoc on docFlavors

You know you can also system.report.executeAndDistribute() and have the report action set up as "Print"? As long as you don't need to dynamically allocate the printer, this will work nicely.

I am not too sure if the gateway can see these printers. I can try though.

That would definitely limit the options.

Yeah, my work place loves VLAN’s. The gateway cannot access whatever network the printers are on. I think I am going to take a different approach. Very surprised my original implementation works about 70%. I don’t know where to go from here besides a different approach. There are no errors it seems like all systems think they’re doing the right thing but in reality the print data is getting screwed up somewhere.

You can write out the PDF bytes you receive as local PDF files and then try to pass them to your printer driver through a different local program:

Hi Paul, I am taking a different approach to what I need now. It was really close to working but the text was all over the place. The images and tables were perfect. Can you shed some light on my earlier question? It really seems like this should have worked.

System.report.executeReport() in my use case returns a PDF byte array right? Why doesn’t SimpleDoc(testReport,DocFlavor.BYTE_ARRAY.PDF,None) Work? What would it be autosensing to?
Currently, the header, tables, and images are all in their correct location. Its the texts that is not in the correct location. The text is correct but all over the place, I feel a mixture of frustration and amusement.

Here is the javadoc on docFlavors

I really couldn't tell you. There's quite a few layers of abstraction involved, and it's hard to tell where things are going wrong.

I can say:

It uses a very different code path. It still uses the javax.print API, but it passes a ton of flags into the printer job that it creates, ultimately creating a java.awt.print.Book that is passed into the job as a Pageable argument:
job.setPageable(book).

PDF rendering is never part of the process.

1 Like