Bkeeney Shorts for Web

I am using Bkeeney Shorts to render a report in a Xojo Web App, and it works well. It displays as expected and I can download PDF, but for this application, I need to be able to print directly to a printer. Using the .print command on the HTMLviewer only prints the first page and I’m having a tough go at getting it to print all pages of the report. I could, of course, loop through and print each page individually, but that becomes a non-starter when we are looking at reports that are hundreds of pages long.

Does anyone have any experience pulling this off?

Does creating the report as a PDF and displaying the PDF in the WebHTMLViewer work for printing all the pages at once?

I tried to use a slight modification of the Handle_Download Method to generate the pdf. It generates and displays, but when the print dialog pops up, it only sends the first page to the printer. I’m sure I’m missing something, but I’m not sure what.

Here’s what I’m using

[code]Public Sub Handle_Print(name as String = “Report”)
If m_oDoc Is Nil Then
Return
End If

Dim fTmp As FolderItem = GetTemporaryFolderItem
RunPDFReport(name + “.pdf”, m_oDoc, fTmp)
If fTmp = Nil Then Return

wf = WebFile.open(fTmp)
wf.Filename = name + “.pdf”
wf.MIMEType = “application/pdf”

ReportViewer.ReportHTMLViewer.URL = wf.url
ReportViewer.ReportHTMLViewer.Print

End Sub[/code]

I’ve been playing with my methods more and it seems that a major part of the problem is that the HTMLViewer does not update before I call print. I’ve broken it out into a calling method and a sub-method (for lack of a better term) but this still seems to be the case. If I break it out into two buttons, first loading the PDF and then a button that just calls the print command, it’ll work (assuming I’m not using Firefox). I know UI doesn’t update until after the method ends, but am I missing something? Can I put that all into one method? The only other thing I can think of is instantiating a timer that waits 1 second and then calls the print command, but something about that feels like it’s clunky.

This is the calling method:

Public Sub Handle_Print(name as String = "Report") LoadPDF( name ) ReportViewer.ReportHTMLViewer.Print End Sub

[code]Private Sub LoadPDF(name as String = “Report”)
If m_oDoc Is Nil Then
Return
End If

Dim oView As New BKS_Shorts.View
oView.ViewLeft = 0
oView.ViewTop = 0
oView.Scale = 1.0

Dim o As New BKS_ShortsDynaPDF.Renderer

m_oDoc.Render(o, oView)

wf = New Webfile
wf.Data = o.m_sBuffer
wf.Filename = name + “.pdf”
wf.MIMEType = “application/pdf”

ReportViewer.ReportHTMLViewer.URL = wf.url
End Sub
[/code]

Dunno
It seems to me that once you have generated the .pdf, the viewer should have the option to view or print from their machine, not from your end. Different operating systems all handle this differently, of course. I am not into web apps (yet), but is there a way to show the .pdf on the screen? If that is possible, then it is the user’s problem to print it to a local printer.
Just my 2 cents worth.
Good luck
Phil

[quote=399409:@Philip Cumpston]Dunno
It seems to me that once you have generated the .pdf, the viewer should have the option to view or print from their machine, not from your end.[/quote]
So, it displays the report in HTML, then to print it must generate a pdf output. The reason for viewing in HTML is due to Firefox’s PDF display behavior, but at this time they will have to click “Print Preview” and then “Print” to get a printed copy of the report unless I come across some other way to handle it.

I know there are users that generate the PDF and display in the browser. But I think this implementation varies by browser and I actually haven’t done it myself.

I was able to do so without issue in Google Chrome, but we decided to stick with HTML for browser viewing because Firefox handles PDFs strangely. If you have certain plug-ins it displays no problem (although some of the control of the HTMLViewer is lost) and if you don’t have any it attempts to download the PDF. There is this solution which is quite interesting, but the timeline on my current project doesn’t allow for me to explore implementation. I imagine this could be made into a plug-in or module of some sort.

The way the HTML renderer works is one page at a time just as it does for output to graphics. PDF is a nice collection of individual pages in one document, but suffers from not being usable in every instance.

You might attempt to modify the HTML generation example to generate every page and using the CSS page-break property (coverage chart) to try to tell the browser what a page is when printing. There is unfortunately not an existing example at this time, but I wouldn’t think it’s too complicated to implement.

I had toyed with this idea but held off due to my lack of CSS experience. I will spend some time on it in my downtime.