Print HTMLViewer

I am trying to print multiple pdf’s which I retrieve using a url (eg: for each file using the HTMLViewer.

I can load the pdf in HTMLViewer with no problem. Printing from the HTMLViewer works. There is some offset when printed which seems to be related to the position of the HTMLViewer in the current window.

If possible, I would like to print all the PDF’s without showing the Print Dialog.

I tried to save the PDF’s in a file, but the file created is empty (0 kb) using the code below:

For i as Integer = 0 To SelectedRows.Ubound  //Items in a listbox selected to print
  If Left(Listbox1.CellTag(SelectedRows(i),1),6) = "https:" then  //CellTag contains the url of the PDF file
     Dim f as FolderItem = SpecialFolder.Temporary.Child("source"+Str(i)+".pdf")
    Dim url as String = Listbox1.CellTag(SelectedRows(i),1)
    Dim http As New HTTPSecureSocket
  End If

I also found that when looping through the HTMLViewer.print, looping through the list proceeds too fast to print more than one document. It seems that I would have to create a pause that waits for the document to complete printing, but I am not exactly sure how that is accomplished.

Any recommendations?

Solved this problem. I think the issue was setting a timeout for the http.Get command, like so:

http.Get(url, f, 10)

Then to print the file I used:

dim s as New Shell s.Execute "lpr " + f.ShellPath

Mac? Win? Linux?

That seems to be Mac…

I would recommend to look into NSPrintOperationMBS.printOperationWithView method in MBS Xojo MacCocoa Plugin.


[code]// print a HTMLViewer
dim n as NSPrintOperationMBS = NSPrintOperationMBS.printOperationWithView(HTMLViewer1)

n.showsPrintPanel = true
n.showsProgressPanel = true

this can work with or without dialogs. And in NSPrintInfoMBS class you can call SetSaveDestination to write to file.

Yes. This was on Mac.

I’ll keep an eye on those MBS plugins. They always seem to fill a void.