Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Open base64 encoded pdf file using javascript

Open base64 encoded pdf file using javascript

Scheduled Pinned Locked Moved JavaScript
javascript
5 Posts 4 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12831037
    wrote on last edited by
    #1

    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("");

    J Richard DeemingR P 3 Replies Last reply
    0
    • U User 12831037

      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("");

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • U User 12831037

        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("");

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        J 1 Reply Last reply
        0
        • U User 12831037

          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("");

          P Offline
          P Offline
          Parth Munjpara
          wrote on last edited by
          #4

          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);

          1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            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

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups