Open base64 encoded pdf file using javascript
-
Hello JS experts. I'm using below code to open base64 encoded pdf file using javascript. It works well with small pdf files below 1MB. But it doesn't work if the file size is greater than 2MB. Please let me know if you have a working code for similar scenario.
var base64 = "base64 content";
let pdfWindow = window.open("");
pdfWindow.document.write(""); -
Hello JS experts. I'm using below code to open base64 encoded pdf file using javascript. It works well with small pdf files below 1MB. But it doesn't work if the file size is greater than 2MB. Please let me know if you have a working code for similar scenario.
var base64 = "base64 content";
let pdfWindow = window.open("");
pdfWindow.document.write("");Are you sure it's the base64 string size? Think about this. If I were to put a 4 meg image of base64, it will display in a element. Perhaps it's when the PDF has 2 or more pages, or an image or something and the browser doesn't know how to handle it. Or how to handle it within a iFrame. I think you need to look at the PDF, and study how others are doing it, and perhaps come up with a new plan instead of just asking for code. Perhaps create a pdf object instead of using an iFrame or embed the object in the frame. [javascript - how to display base64 encoded pdf? - Stack Overflow](https://stackoverflow.com/questions/40674532/how-to-display-base64-encoded-pdf)
If it ain't broke don't fix it Discover my world at jkirkerx.com
-
Hello JS experts. I'm using below code to open base64 encoded pdf file using javascript. It works well with small pdf files below 1MB. But it doesn't work if the file size is greater than 2MB. Please let me know if you have a working code for similar scenario.
var base64 = "base64 content";
let pdfWindow = window.open("");
pdfWindow.document.write("");data:
URI limits vary by browser. It sounds like you're using Chrome, where the limit is 2MB. html - Data protocol URL size limitations - Stack Overflow[^] As suggested in that answer, you should use the blob API instead: URL.createObjectURL() - Web APIs | MDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Hello JS experts. I'm using below code to open base64 encoded pdf file using javascript. It works well with small pdf files below 1MB. But it doesn't work if the file size is greater than 2MB. Please let me know if you have a working code for similar scenario.
var base64 = "base64 content";
let pdfWindow = window.open("");
pdfWindow.document.write("");var objbuilder = ''; objbuilder += (''); objbuilder += (''); objbuilder += (''); Then either add to the existing page or open a new window: var win = window.open("","_blank","titlebar=yes"); win.document.title = "My Title"; win.document.write(''); win.document.write(objbuilder); win.document.write(''); layer = jQuery(win.document);
-
data:
URI limits vary by browser. It sounds like you're using Chrome, where the limit is 2MB. html - Data protocol URL size limitations - Stack Overflow[^] As suggested in that answer, you should use the blob API instead: URL.createObjectURL() - Web APIs | MDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I didn't know that. The Stack post is good info to know. You just got me thinking about my latest design. I just designed and coded my new image system on the back end of my experimental project, and used base64. In the front I use Image Url's to a static location. Like in my Mongo Document, I keep a copy of the image in base64. So I can drag and drop, or select an image, client script it to base64, and send that to the API for further image processing like square it up, flip it around (iPhone) and scale it down to 1024x1024, then write the base64 to a Mongo document, write it to the website and send the base64 back for preview. What's cool about this, is that I'm hosting in a Docker container with Kubernetes support, so I can spawn more website containers, and my .Net Core API's will rewrite the images requested from Mongo to the newly created spawned container. I'm just excited about it, because it's working pretty good so far and it's base64 talk. At 1024x1024, I'm within the limits.
If it ain't broke don't fix it Discover my world at jkirkerx.com