validate pdf in Selenium using chrome browser - google-chrome

When I click on a link in a page, a PDF opens. I need to validate the contents of this PDF file using Selenium in C#.
I'm able to handle this in Firefox 25(using pdf.js). In firefox, the contents of this pdf are displayed in html and hence, using isTextPresent, I am able to validate if the pdf contents are correct.
But, though Chrome opens the pdf in my browser, it does not show the pdf contents as separate elements. Is there any plugin/ setting change that can be done for me to view the pdf as html in Chrome browsewr

PDF.js is also available for Chrome - see PDF Viewer in the Chrome Web Store.
I suggest to load the PDF using the following URL: chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/content/web/viewer.html?file=<URL-encoded version of PDF file's location>.
The reason for explicitly putting the URL as shown before is that if the PDF url is visited before the extension is loaded, then the default PDF behavior is triggered (in Chromium, the file is downloaded, in Chrome, it's displayed using Chrome's built-in PDF Viewer).
After the PDF.js is loaded, you can directly type the URL for a PDF file in the omnibox, the extension automatically detects PDF files and renders the result (based on MIME-type).

Related

is it possible to make an hyperlink to only download a pdf file?

I have an hyperlink to a pdf form that can not be opened by the browser's pdf viewer. If clicked, the browser tries to show it but I get the error message like "it is necessary Acrobat Reader 8.x" etc. Is there a way to force an hyperlink to such pdf form file to only allow its downloading? In this way, the user could open it with his local Adobe Reader.
Let’s say you have a PDF that you want to let people download. The file will be like this:
Download Receipt
In most browsers, clicking on the link will open the file directly in the browser.
But, if you add the download attribute to the link, it will tell the browser to download the file instead.
<a href="/path/to/your/receipt.pdf" download>Download Receipt</a>
The download attribute works in all modern browsers, including MS Edge, but not Internet Explorer.
In the latest versions of Chrome, you cannot download cross-origin files (they have to be hosted on the same domain).
To make the hyperlink to download the pdf file when clicked, you should use download property inside the anchor tag. For example you can see the code below:
Download the pdf file
You can also give your own name to the downloadable pdf file in the download property that I provided as 'Document' in the code above.
Yes, it is possible. First download the file and then you'll see a link when it downloaded(it disappears quite quickly) just copy it and use:
hyperlink

Download pdf instead of auto opening in the browser react js

I'm trying to download a pdf file using a link in react and when clicking on the link the pdf is opening in the browser instead of download.
I have enabled a setting in the browser to download the pdf and that works but is there any way where we can do in the code without manually changing the browser setting?
I have tried this,
<a style={{textDecoration : "none"}}download href={url}>YES</a>
but in this also i have to enable the setting manually in the browser.
It is working fine for all the other file types execpt pdf which is opening instead of downloading.

How to load a PDF file embeded in an iFrame on electron browser

We have an app which launches Electron browser. In the Electron browser we load a third party website which has a link.
When we view this site in the Chrome or IE browsers, clicking on this link it renders a PDF in an iFrame but for electron browser it shows a save file dialogue. We want to display this PDF in the electron browser just the same way it works for Chrome and IE. As it is a third party website we don't have control over rendering or loading PDF file or we are not getting any events related with loading of this PDF.
For this scenario, if there is no way to display PDF in electron then it is OK to block it so the Save file dialogue will not show.(This app is actually in the KIOSK so we don't want to save a file if it doesn't render in browser.)
Thanks in advance for your comments!
Here is a discussion on an issue almost identical to yours. The answer does a decent job explaining why the download option is appearing. As for preventing the pdf from being downloaded, try using the <embed> tag as it detects compatibility. So embed the pdf using that tag and then load the html into the <iframe>. Here is some example code and description of how to set that up.

Save PDF form Chrome IFRAME

I am POSTING a form to an IFRAME (target) which returns a PDF (content-disposition=inline;filename="x.pdf").
This works with current Chrome and Firefox and the embedded PDF viewer.
The only problem is, that Chrome is not able to save the PDF (it tries to save x.html with no content) (with Ctrl+S and with the icon in the PDF toolbar).
Any ideas?
Actually, it is a limitation from native Chrome PDF Viewer. You cannot save PDF file when it is displayed from an iframe using Chrome PDF Viewer (plugin).
Using Adobe Reader plugin for Chrome works perfectly.
Cheers

Use Adobe reader instead of chrome pdf viewer to display a pdf

I'm outputting a pdf which has been made with scribus, and in all browsers except for chrome it outputs fine, however with chrome the letters are cut off and lower than usual. I found that disabling the chrome pdf viewer fixes the issue locally. But what about users who do not have it disabled? Is there some way I can make adobe reader show it instead of the chrome pdf viewer in my code?
Any help is appreciated,
Thanks
Edit: I can't make the user download the pdf as it is somewhat a preview before they send it in.
One option would be to use a Content-Disposition header to force the PDF to download as an attachment. When the user clicked on the downloaded file, it would then open in their registered PDF viewer rather than in Chrome.
I ended up flattening the pdf using the flatten option, it unified the result accross all browsers.