I am looking to automate "Save as PDF" of Chrome using selenium. AFAIK it is not supported by the Selenium out of the box. Therefore, i am trying to write my own. I am having an issue. Actually clicking on the Print button in my webpage opens a new window with printable area. I am trying to switch to this window using SwitchTo. But it is timing out always.
You can add the options.AddArgument("--kiosk-printing"); to have it automatically click the print button.
That is working for me but I have a problem setting the printer to Save as PDF. It is printing to the printer instead.
You could try to disable the Chrome PDF plugin and download promt window with desired capabilities. Something like this:
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability("download.default_directory","C:");
cap.setCapability("download.prompt_for_download","false");
cap.setCapability("directory_upgrade","true");
cap.setCapability("plugins.plugins_disabled","Chrome PDF Viewer");
WebDriver driver = new ChromeDriver(cap);
Related
I need to disable the option to "Save as PDF" in Chrome. If this option is selected, the user can then browse the file explorer, and we want to ensure we lock that down and have a single defined printer selection available. I have tried using the "PrintTypeDenyList" with no luck. I'm uncertain if it even works and can't find any other Chrome options through blogs online. https://chromeenterprise.google/policies/?policy=PrinterTypeDenyList
Has anyone been able to disable the Save as PDF print option in Chrome?
Thank you
When using the Microsoft Edge browser, by default when you open a PDF it will open the PDF in a new tab using the built-in PDF viewer. To avoid this, you can adjust the browser's settings: Toggle on the "Always open PDF files externally" option. This works great. However, it presents a separate issue. Our internal applications use embedded PDFs in iframes. When the external toggle is set to on, these PDFs will not show in the iframes. This doesn't happen in Chrome. Has anyone else experienced this and know a work around?
I've tried removing the type="application/pdf" from the iframe tag to no avail. I can't find anything else online.
It looks like an expected result because you have enabled the option Always open PDF files externally.
So MS Edge browser is giving you an option to download the PDF file and open it using the desired app.
You said this doesn't happen in Chrome browser.
If you enabled the Download PDF files instead of automatically opening them in Chrome option then you will notice the same result in the Chrome browser.
Output in the Chrome browser:
If you click on the Open button then it will download the PDF file.
I did not get any solution or a workaround for this issue.
If you think that there should be an option to load the file in an iframe if Always open PDF files externally option is enabled then I suggest you click on the Send Feedback button in the MS Edge browser and try to provide your feedback about it to the Microsoft.
I posted feedback suggesting that an exclusion/inclusion list be in included but the simplest way would be to treat the frame as part of the session. But this is not Microsoft it is the Chrome projects issue.
I have a web app with a chat that opens in a new popup window. Normally, in Chrome I can hit F12 and click the icon of a smart phone to toggle it. But in the popup window this icon does not appear. This is important for me since I need to throttle the connection of the popup in order to simulate a user disconnecting from the chat.
Thanks!
It doesn't seem to be currently possible. I've opened a ticket for you. Meanwhile you have couple of options:
open popup in a regular window (copy paste the url, or modify window.open call to open a new tab instead of a separate window),
create a Chrome extension that uses debugger API to send emulateNetworkConditions message to your popup window
or try hacking DevTools like so:
open DevTools (A) for your popup
focus on DevTools window and open another DevTools (B) for that window using a keyboard shortcut (F12/alt+cmd+J)
in the console of the DevTools B call WebInspector.overridesSupport.setEmulationEnabled(true) (to enable emulation) and then WebInspector.overridesSupport.settings.networkConditions.set({throughput: 1.5 * 1024, latency: 40}); (to enable network throttling)
Perhaps easier way as of today is to install chrome extension which will allow you to open preview in new tab instead of popup. There you can have the same icon to toggle to mobile. Below is the extension:
https://chrome.google.com/webstore/detail/tag-assistant-companion/jmekfmbnaedfebfnmakmokmlfpblbfdm?hl=en
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.
I have a link in a pdf-document (PDF1), which is embedded in a browser instance. Or let's say the Adobe Reader is embedded in a browser window.
In this pdf-document (PDF2) is a link to a servlet, which view opens another pdf-file.
Now the new pdf-document is opened in a embedded Adobe Reader in the same browser window. How can this document (PDF2) be opened in a new browser window with a new embedded Adobe Reader?
Does this depend on the editor tool used for the generation of the pdf-document?
PS: I am not creating the first one (PDF1), but I am faced with the question, how to open the second one (PDF2) in a new window, so the first document is not "lost" and has to be reopened again.
I think you can't do this without changing Acrobat Reader. What happens is this:
You download the first file.
IE notices "PDF" and embeds Acrobat Reader. The reader gets the URL as an argument. Despite the fact that AR renders the document inside of an IE window, AR is now in full control of the document. So when you click on a link, it's AR (and not IE) who processes the event and downloads the second document.
I suggest to try Foxit Reader or some other PDF reader which doesn't use a "single document" UI. Foxit uses tabs and can display several PDF documents.
They are faster, too and more comfortable to use.
[EDIT] Actually, AR calls the OS to handle the link. You can achieve the same effect by copy an URL into the clipboard and then click on the "Start" button and "Run...". Paste the URL into the dialog. Or open a command line prompt and paste the URL at the prompt.
The OS will start downloading the file, determine the type and then directly invoke the application which is registered for that type. IE does the same thing which has caused some of the security holes in the past (site offers IE some data which seems to be of type XXX but is in fact a virus. IE will call the OS to execute it and user wonders how he got infected).