How to print and/or save a PDF?

Added by Vincenzo Romano 5 months ago

Hi all.
I am experimenting with WPdfImage class.
What I actually need is to have the PDF document to go to the client printing menu and to remain on the server local storage.
Accordingly to the example, I get a "download" event from the browser.
But, is there a way to have it sent to the browser's media="print"?
And what about having it as a local resource for storage on the server as a file?

TALIA!


Replies (7)

RE: How to print and/or save a PDF? - Added by Wim Dumon 5 months ago

Hey Vincenzo,

I don't know of a method that would immediately open the print dialog for a pdf file. A quick google search didn't yield much promissing results neither.

What you can do in Wt is:
  • save the pdf in some location on the server, and use a WFileResource (in combination with WAnchor) to make it available in one particular session
  • control if the pdf should be displayed in the browser, or in a helper application (WResource::setDispositionType)
  • suggest the filename for the file on the client (WResource::suggestFilename).
  • open the file in a new tab (WAnchor::setTarget)

Wim.

RE: How to print and/or save a PDF? - Added by Vincenzo Romano 5 months ago

I have found this but I am still far from a solution.

RE: How to print and/or save a PDF? - Added by Vincenzo Romano 3 months ago

I have also found this hint.
Maybe I am wrong, but this kind of things should be part of wt with two different paths.

1. The client knows how to print the document, so the print request should be on the client.
2. The server knows how to print the document, so the print request should be on the server.

I hope I'll get it done so I can publish some stuff here.

RE: How to print and/or save a PDF? - Added by Wim Dumon 3 months ago

Vincenzo,

I googled a bit more, and even a project dedicated to printing pdf files (http://printjs.crabbly.com/) can't make it work in firefox and edge. There's a long standing bug report for firefox here:

https://bugzilla.mozilla.org/show_bug.cgi?id=911444

Sorry, I don't know of a method that works.

If you want to print the pdf on a printer connected to the server, you can of course just do that - I don't think you need any specific Wt support there?

Wim.

RE: How to print and/or save a PDF? - Added by Vincenzo Romano 3 months ago

My situation is a mix.
60% of the times the printer to be used is local to the server, so your suggestion will get it covered. Good hint.

In the remaining 40% of the cases, the printer is local to the client and there's no way for my application to "reach" the printer.

Now, when I click the button on the linked example, the application sends the PDF to my client for download, not for display.
This can be OK, as far as i understand how it works.

My debugging "Console" says:

Resource interpreted as Document but transferred with MIME type application/pdf: "https://www.webtoolkit.eu/widgets/line.pdf?wtd=vnSsqKqsiWiVrpg2&request=resource&resource=ofx8rb&rand=22726".

while the "Network" debugger reports it as a "Document" (status is 200 and size is "194 B").

In this case I should "just" define "media=print" on the link and the PDF should pop into the printer dialog.

How does that example work?

RE: How to print and/or save a PDF? - Added by Wim Dumon 3 months ago

The example works by setting the disposition type of a WResource, you can define if the pdf is intended to be shown by a pdf viewer in the browser, or by an external application.

Now, with respect to 'media=print', I believe you're confusing CSS features with something you want to achieve, but cannot be achieved by using this feature.

Wim.

RE: How to print and/or save a PDF? - Added by Vincenzo Romano 3 months ago

For the media=print I think you are right.

(1-7/7)