Open PDF in new tab (Javascript) when fetching data through curl

I have a question. I have a URL for Phantomjs that generates a PDF. But I want to create a PDF on the server.

<script> $("#generatePDF").click(function(){
        var fullLink = "<? echo $link ?>"
        $.ajax({
            type: "POST",
            url: "/php/ajax/generatepdf.php?",
            data: {link : fullLink}
        }).done( function(data){
            window.open(data);
        } );
    }); </script>

      

Here I am sending data to generatepdf.php file

Link creates PDF with Phantom.JS

Now I am doing the following in the generatepdf.php file

 $link = $_POST['link'];
 CurlConnect = curl_init();
 curl_setopt($CurlConnect, CURLOPT_URL, $link);
 curl_setopt($CurlConnect, CURLOPT_POST,   1);
 curl_setopt($CurlConnect, CURLOPT_RETURNTRANSFER, 0 );
 $Result = curl_exec($CurlConnect);
 echo $Result;

      

My question is, how can I open a PDF in a new tab with stuff from the Phantom.js result?

Hope you can understand my question.

Regards.

+3


source to share


2 answers


Ok, I have another solution. I just linked to a php page and the PHP page received PDF content. Plus I had to change the title to pdf attachment



+2


source


Instead of using CURL and all of this just click the $link

php file in a new tab. (If the file actually creates a PDF)



window.open('Link which generates the PDF');

0


source







All Articles