base64 pdf is not showing in IE 11 browser [duplicate] - angularjs

I receive (from a webservice I don't manage) a string with the content of a pdf file.
On client's side, I use this function:
window.open('data:application/pdf;base64,'+encodeURI(TheStringWithThePdfContent));
As usual, it works in every browser but IE (11 in my case), which shows an alert with the message: "Do you want to allow this website to open an app on your computer?"
If I say no, an empty white page is opened.
If I say yes, it tries to open a "data" file (as it reads from the protocol in window.open, I guess) and, as it doesn't find any application to do that, sends me to the Microsoft application store, which just suggests me to download "iMusic"
Completely useless, of course.
I've changed all the Internet Options I've guessed could help, none works.
Any suggestion?
Thanks in advance,

I found the solution and I want to share anyone who has the same problem. You can see the demo here :
https://jsfiddle.net/quangminh_ln/hy36tnt6/
'use strict';
var data = "...Your PDF base64 string...";
var fileName = "your_file_name";
if (window.navigator && window.navigator.msSaveOrOpenBlob) { // IE workaround
var byteCharacters = atob(data);
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {type: 'application/pdf'});
window.navigator.msSaveOrOpenBlob(blob, fileName);
}
else { // much easier if not IE
window.open("data:application/pdf;base64, " + data, '', "height=600,width=800");
}
The link that I saw for my solution : https://viethoblog.wordpress.com/2016/08/30/loaddisplay-pdf-from-base64-string-bonus-ie-workaround/

Update Reader or Acrobat
Adobe releases free security updates quarterly. Make sure you update your version of Reader or Acrobat to the latest release. The updates often include fixes to common problems. Download the latest free update.
Open Reader or Acrobat.
Choose Help > Check for Updates.
Acrobat 9 and earlier: If a new update is available it installs automatically.
Acrobat X and XI: Click Update and then click Install.
Acrobat DC: Continue to the next step.
Check for updates
When the Updater dialog box appears, click Download.
Update Acrobat
After download is complete, click the Acrobat install icon. In the Acrobat Updater window, click Install.
Update is Ready
After installation is complete, restart your computer and test the PDF again to see if you can view it.
PDF solutions
Refresh or reload the page
Often, just refreshing the page in your browser allows the PDF to load fully.
Hold down the Shift key and press the Refresh or Reload button in the browser.
Try to view a different PDF
Try viewing a different PDF. For example, see if this sample form displays in your browser. If Acrobat or Reader can open the sample form, then the other PDF could be damaged or the web server could be having problems. If possible, contact the individual or company who manages the website.
Try to view a PDF on your hard drive
Determine if your web browser can open a PDF from your local hard drive rather than from the web. For this test, you need a PDF saved on your computer.
In your web browser, do one of the following:
Mac OS: Choose File > Open (or Open File).
Windows: Press Control+O.
Click Browse.
(Windows only) From the Files Of Type menu, choose All Files.
Choose all files
Locate a PDF on your computer, select it, and then click Open.
If the PDF opens, the website you were viewing could have a problem. Contact the individual or company who manages the website.

Related

How to open a generated file on Vaadin Flow?

On my app I want to open a generated PDF with PdfBox on a new tab, I have seen a couple of documentations but they are for old version of Vaadin or won't work in my case. I don't want to save it on the server or attach the file to any link or button, I want to write a method to automatically open it on a new tab.
PdfBox gives an option to save the file on an OutputStream, is there any way to open that OutputStream file on a new tab? Or at least download it without attaching it to an Anchor widget like Flow Viritin does?
The problem lies in the fact that because you don't want to save the file on the server, you cannot then have a direct url of said file to link to. You also cannot pass the pdf file as parameter to another View.
The solution is to store the pdf in the VaadinSession (as byte[] is probably easiest), and when the user then opens another tab by clicking a certain anchor/routerlink, that view will read the pdf from the VaadinSession and add the it to the view. (How to display pdf with Vaadin 14). Please remember to remove the pdf again from the VaadinSession :)

Access GM_getValue outside of script

Basically the question title. It would greatly benefit me. I want to be able to access GM_getValue outside of my userscript for debugging purposes, or, at the very least, the values and names themselves.
I am in Chrome on Windows 10.
Latest Tampermonkey beta (and eventually normal Tampermonkey) displays the GM values in its dashboard script editor in Storage tab.
Visual method: use Storage Area Explorer extension:
Open the Tampermonkey dashboard page and invoke devtools by F12 or CtrlShifti
In Storage Area Explorer panel scroll to the bottom to find the #uid# of your script by name, then find its data in #st# key with that UID:
Dumping in the console:
One-time setup: add a new code snippet in devtools - Sources - Snippets subpanel and save it:
function dumpGM_data(scriptName) {
chrome.storage.local.get(null, data => {
const UID = Object.keys(data).find(k => k.startsWith('#uid#') &&
data[k].value == scriptName);
if (UID)
console.log(data[UID.replace('#uid', '#st')].value.data);
});
}
Open the Tampermonkey dashboard page and invoke devtools by F12 or CtrlShifti
open and run that snippet: CtrlEnter - it'll be usable until you close the dashboard page
invoke it in the console:
dumpGM_data('SE Preview on hover')
Inspect/dump/edit the database file directly:
Use any LevelDB tool you can find (or compile one yourself) on the ldb database file under Chrome user profile directory in Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo or Local Extension Settings/gcalenpjmijncebpfijmoaglllgpjagf for Tampermonkey beta.

How to get file download complete status using selenium web driver c#

I am writing a automation script using selenium web driver for downloading multiple files one by one from a web site in Mozilla fire fox. I have downloaded first file successfully and next time I need to wait for download to complete. Can anybody help how to identify an ongoing download is completed using c# selenium web driver.? Since I am not getting the download complete status, I am unable to continue downloading next file.
Assuming you are testing file downloading in Firefox as you mentioned. Here is an approach to achieve what you want.
Open new window/tab in Firefox and navigate to 'about:downloads' directly.
i.e. driver.Navigate().GoToUrl("about:downloads");
You will get the list of downloads (i.e. already downloaded files and the file which is being downloaded currently.)
You will have to switch between your site tab and downloads tab.
Now on downloads tab, looking at HTML, you can easily find out in progress download using state or status attributes.
For example, for the first file in the list, if state="0" and/or status
contains the text 'remaining', it means downloading is in progress
So you can wait till state becomes state = 1 and/or status does not contain >the text 'remaining'
Refer the attached screen shot.
The explanation I gave here looks very high level, but I am sure this approach will work. It is simple too.
Let me know if you have any queries on this.

Access Specific PDF Page in WPF WebBrowser Control

I have a webbrowser control in my application that is used to display pdf files that have been created in iTextSharp and are stored locally on the hard drive.
I would like to be able to navigate the file (next, previous, first, last, toc) from my application rather than using the inbuilt nav of the reader in the browser.
I have seen that you can navigate to specific pages by using
Browser.Navigate("filename.pdf#page=?);
This works the first time but when trying to navigate to a different page, it makes the browser disappear completely with no errors. However, I can reload the file without problem if I don't have the #page=? suffix on the file url though. Any ideas on this?
Alternatively, is there anyway in iTextSharp of adding something to the file to allow for it to be navigated from an external command?
All the official parameters that can be used to navigate through a PDF using parameters in the query string after the ? character are listed in a document published by Adobe: Parameters for Opening PDF Files
You already mentioned the page parameter. Another option could be using named destinations: nameddest=destination. In this case, you need to add the anchor with name destination to the file using iTextSharp.
Note that not all viewers implement these parameters. Adobe supports them in Adobe Reader and in the Adobe Reader plug-in, but there is no guarantee that they will work in pdf.js (Firefox), Pdfium (Google Chrome),... If your browser disappears when using an open parameter, you may have hit a bug in the browser or the viewer plug-in that causes the browser to crash. iTextSharp nor iText can crash a browser ;-)
There are no other ways you can navigate a PDF from an external application. The only thing you can do, is to add JavaScript to the PDF so that it always opens at the same page. This is done using an open action. I don't think this solves your problem as it would mean that you have to change the PDF file every time you want it to open at a different page.

IE6 closes new browser window when I set iframe's source to a file download service

In our application, we have a download flow that works as follows:
On main application page has a link showing file name to download. Target of this link is _blank.
User clicks this link. We open a new window.
The new window shows a wait message, makes an ajax call first to verify the file details from server (we have server implementations for this).
There is a hidden iframe in new window. After verification of file details, I set the file download url as the source of iframe so download request is sent via iframe.
When file response is received, IE6 suddenly shows a yellow bar at the top and then closes this new window forcefully. I do not see any file save dialog.
This works fine in IE7 and IE8, although I see the yellow security bar here too but window does not close, so I can start a manual download.
Can anyone help me on this? Is this a bug in IE6 that was resolved in IE 7/8?
Best regards,
Nadeem
I got it. Actually this is a bug of IE6 and you could get more info about it here: http://support.microsoft.com/kb/896017.
Regards,
Nadeem Ullah

Resources