How to set the title of a pdf file in browser? - node.js

I am using nodejs server to serve static files. When the pdf file is served, the browser displays the title as URL of the pdf path.
127.0.0.1:8080/docs/sample
How can I set this to a custom title say "Sample"
I have tried following things but no luck :
res.setHeader('Content-Disposition', 'inline;filename="sample.pdf"');
Setting meta tag of pdf file as "sample"
Any help will be much appreciated.

If you're using a static file server, then yes you are serving it as a download. Modern browsers often contain a built-in PDF viewing plugin, so instead of asking the user where to save the file, the browser will instead just display the PDF right in a browser tab. It still downloaded it, it just saved it to some temporary cache on your machine in that case.
What I'm getting at is that you cannot control the browser title in that case because it's just the browser trying to be nice and make things convenient for the user. The PDF file itself would have no idea if it was being displayed in the browser's built-in viewer or in Adobe Reader on the desktop. There are no HTTP headers you could send down to set the title either because browsers expect page titles to be set from HTML or JavaScript running on an actual web page.
Now, if you were to embed the PDF file in an HTML page with some kind of PDF viewer then you could control the page title with a simple <title>some title</title> tag or calling document.title = 'some title'; from JavaScript. That works because the browser is rendering an actual web page that you control, and that page just happens to have an embedded PDF viewer on it.
Here's an example of an embeddable PDF viewer. http://pdfobject.com/

//hack alert
You could trick the browser by setting the last fragment of the url to whatever you like . i.e. change sample in your example to the desired title.
(tested in chrome 58.0.3029.110)
HTH

Related

Download dynamically generated pdf from using selenium

So I'm trying to download pdf files from an ancient internal web system. I put in a request and based on my request parameters, it generates a new pdf and shows it in a new window. Since the pdfs are generated dynamically, there is no real url I could download.
I'm trying to figure out how I would download the file after it has generated and opened up in the new window.
The pertinent part of the page's source seems to be this:
<body onload="document.FormForDownload.submit();">
<form name="FormForDownload" method="get" action="./download.pdf" target="iframePDF">
<iframe name="iframePDF"></iframe>
</form>
</body>
I'm open to using the requests library or urllib or anything people suggest. ANy ideas? Working in python btw.
If I suppress chrome's own PDF viewer to get it to automatically download the pdf, I get a page that looks like this:
Clicking the open button will give me this page:
This is because the url generated is one time use only, to generate the url again, I have to request the pdf again.

Displayed Encrypt Page in SWT Browser

I am using SWT Browser to display html pages. These HTML pages are stored in a folder. By this anybody can copy the data easily, which I want to protect. For this I have encrypted the HTML pages.
How to decrypt these HTML pages during Backward and Forward activity ? Also while displaying them in the browser by using setUrl("url") method -
htmlBrowser.setUrl(url String);

CF and PDF in secure environment

I'm using CF9. My problem pertains to an admin application that sets session variables at login to identify the user and user permissions. Depending on the user level, certain pages are allowed for viewing and other pages are not allowed. (I'll refer to this as my 'security framework'. This is wrapped around everything in the root.)
This security framework consists of a cfif statement at the top of the CFM page and a closing cfelse and (</)cfif at the bottom of the page. Everything between this opening cfif and closing cfif displays if the user has that level permission - standard stuff.
Certain users can upload PDF files, no problem here. PDF files are uploaded to a folder outside of the root and then moved and renamed to folders inside the root.
When uploading, the user chooses categories and subcategories etc. and these variables are inserted in a SQL database during the upload process. Therefore, I have filePaths and fileNames, etc. to set up dynamic links on a page for a user to click and load the PDF (password protected) in the browser.
I have the dynamic link pointing to a ShowThisPDF.cfm? with URL variables filePath= #filePath# & fileName = #fileName#. I've set up the ShowThisPDF.cfm with the security framework at the top and bottom of the page and am trying to copy the uploaded PDF into this page so that the PDF will display in the browser.
I've tried many ways to do this with cfdocument and cfpdf and cfcontent, etc. When I read the error that this is throwing, it does look like it is reaching the uploaded file but I get an "access denied" every time, due to the security framework I suppose.
On a side note, elsewhere in this application I can create a PDF from my cf pages with cfdocument with the security framework wrapped around the page and this works perfectly - displaying the PDF in the browser. My problem is in loading an existing PDF into a CFM page that has the security framework - which should allow the PDF to load.
Anyone have an idea as to how I can accomplish the above? I hate to try and bypass my security and it seems logical to "copy" the uploaded PDF into a CFM page that wraps the PDF in the security framework and then display the PDF in the browser.
Agree with Dan - I had similar issue. So I ended up doing https: with a windows login and also a ColdFusion Login to Web Application. At end of day - they need 2 logins to get into the system - then they can see the pdf files etc or what they need.

HTML to PDF (Using Google chrome API)?

I have some documents in HTML and i need it to be printed/generated on server (no UI, automated, linux based).
I'm very satisfied with Google Chrome "html to pdf" of the documents but i'm wondering is it possible to use that "component" of "html to pdf" printing engine from Google Chrome Browser somehow for this purpose?
Actually i found the solution:
First one wkhtmltopdf http://code.google.com/p/wkhtmltopdf/
And at the end i realized that mpdf (php lib) can help me too :)
If you needed an HTTP API service to convert HTML to PDF from an URL you may want to check this answer that I wrote that explains how to do it.
Example:
https://dhtml2pdf.herokuapp.com/api.php?url=https://www.github.com&result_type=show
shows in the browser the PDF generated of the site https://www.github.com.
See the project in Github.
Hope it helps.

chrome.browserAction.setPopup() - local html files only?

I would like to modify my extension's popup dynamically (at run-time). And want to specify a custom popup HTML file that's loaded from my server.
In Firefox, I can easily accomplish this with XUL overlays which I can specify at run-time.
And document.loadOverlay() does allow me to specify a 'remote' URL for the overlay.
Is the same possible in Chrome?
I've been playing with chrome.browserAction.setPopup( details ) API, but it seems that the details.popup param must specify a local file, and not a remote URL.
I have answered this exact same question on the Chromium-Extensions mailinglist.
There is no API to load external popups but you can do that with plain JavaScript. What you could do (I have done that in the past):
Use an iframe + extension messaging within the popup. The iframe
points to some external url not hosted in the extension.
Use templates (jQuery templates example), load those template files to
your background page, and just use them to construct your popup.
Download the html contents using XHR and load them within the popup
by constructing the DOM.
I usually use the template approach, but I use the popup iframe approach when I want to manage the entire popup in the server side so I don't have to push updates to the extension gallery. I am not a fan of downloading the HTML contents, templating seems safer.
Hope this helped!

Resources