How to save a PDF which is displayed in the browser?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to save a PDF which is displayed in the browser?

Postby AndyB » Sun Apr 16, 2017 3:26 pm

Hi,

when a PDF is displayed in the browser, the user can save it.
Is there a way to programmatically save a PDF which is already loaded and displayed in the browser?

Thanks,
Andy
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: How to save a PDF which is displayed in the browser?

Postby Czarek » Mon Apr 17, 2017 12:20 am

Try calling CefBrowserHost::PrintToPDF.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How to save a PDF which is displayed in the browser?

Postby AndyB » Mon Apr 17, 2017 11:27 am

I knew the PrintToPDF function, but thought it's only for html to pdf.
It generally works fine, thank you!

However, i have one websites with frames, it looks like this:
Code: Select all
<html><head>
<title>Sample Title</title>
</head>
<frameset cols=0,*>
<frame name=FrmL resize>
<frame name=FrmR src=../sample.pdf resize>
</frameset>
</html>


PrintToPDF gives me a blank PDF in this case.
Is it possible to save the PDF in the "FrmR" frame?

Another question:
If i click on "Download" then the PDF flickers shortly, but no dialog appears and no file is in the download folder.
Do i need to implement something to make this working?
Anyway, it might be the best option for me if can catch the Download function of the PDF viewer to grab the PDF - Is this possible?

Thanks,
Andy
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: How to save a PDF which is displayed in the browser?

Postby Czarek » Mon Apr 17, 2017 12:09 pm

CefDownloadHandler is to handle file downloads.

Since you know PDF url (in the frame) you can just download it using CEF functions or other library. Or you could redirect browser to that url.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How to save a PDF which is displayed in the browser?

Postby AndyB » Mon Apr 17, 2017 5:18 pm

The users of my app are browsing a few web sites, searching for information and need a way to copy PDF's into the app's database.
Yes, i can directly download PDF's which i actually do for a few known URL's.
But URLs may change, sometimes a known web site contains new PDFs, my users discover new useful websites, and it may not always be possible to download a PDF directly by an URL.
Therefore i am looking for a general way to grab PDF's which works also for unknown URLs.

uuhps, i already implemented the IDownloadHandler which caused the mentioned flickering (i catch PDF downloads and display them in the browser).
downloadItem.ContentDisposition seems to be empty in OnBeforeDownload if the user clicks on Download in the PDF viewer, while it's for ex. "attachment; filename=sample.pdf" otherwise.
I don't know whether i can rely on just checking the ContentDisposition. Is there a way to know for sure if IDownloadHandler:OnBeforeDownload was triggered by a click on Download in the PDF viewer?

Thanks for your great help!
Andy
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm


Return to Support Forum

Who is online

Users browsing this forum: amaitland, Google [Bot] and 105 guests