JavaScript How to print a base64 pdf? print base64 image,print base64 pdf javascript,print base64 encoded

I receive a base64 pdf from the server which I want to print.

I have been trying the following:

$.ajax({
    type: "POST",
    url: url,
    data: blahblahblah,
    success: function(data) {
        var printWindow = window.open( "data:application/pdf;base64, " + data );
        printWindow.print();
    }
});

Sadly, this does not work in Chrome. I am receiving the following error:

SecurityError: Blocked a frame with origin "xxx" from accessing a frame with origin "null". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "data". Protocols must match.

Suggestions on how to work around this?

Answer:1

You can try to open your window and try to insert the pdf data as embed.

Here is an piece of code I've found and used fine (I changed to fit on your code, but not tested):

    $.ajax({
    type: "POST",
    url: url,
    data: blahblahblah,
    success: function(data) {

        var winparams = 'dependent=yes,locationbar=no,scrollbars=yes,menubar=yes,'+
            'resizable,screenX=50,screenY=50,width=850,height=1050';

        var htmlPop = '<embed width=100% height=100%'
                         + ' type="application/pdf"'
                         + ' src="data:application/pdf;base64,'
                         + escape(data)
                         + '"></embed>'; 

        var printWindow = window.open ("", "PDF", winparams);
        printWindow.document.write (htmlPop);
        printWindow.print();
    }
});

Hope it helps.

Answer:2

If I create an Object as follows: window.Something = { X: function() { // statements... } }; What is the best way to access this object without using this? Example: If I call the X ...

If I create an Object as follows: window.Something = { X: function() { // statements... } }; What is the best way to access this object without using this? Example: If I call the X ...

I need pathname (www.my-site.com/this-part/and-this-part/etc/) in JS/jQuery but I need it as string not as object. In other words I need $_SERVER['REQUEST_URI']; in JS/jQuery. I've tried: var ...

I need pathname (www.my-site.com/this-part/and-this-part/etc/) in JS/jQuery but I need it as string not as object. In other words I need $_SERVER['REQUEST_URI']; in JS/jQuery. I've tried: var ...

I have a web application that uses ExtJS 4 that incorporates a Ext.grid.EditorGridPanel. One of the columns of the Ext.grid.EditorGridPanel has a combobox editor that I would like to disable ...

I have a web application that uses ExtJS 4 that incorporates a Ext.grid.EditorGridPanel. One of the columns of the Ext.grid.EditorGridPanel has a combobox editor that I would like to disable ...

I have drawn a complex path in my browser (Firefox) as a background, using Javascript-generated SVG elements and attributes, and would like to superimpose icons that consist of multiple SVG shapes. ...

I have drawn a complex path in my browser (Firefox) as a background, using Javascript-generated SVG elements and attributes, and would like to superimpose icons that consist of multiple SVG shapes. ...

  1. javascript generate svg
  2. javascript generate svg image
  3. javascript generate svg path
  4. svg generator js
  5. generate png from svg javascript
  6. generate svg using javascript