3

I have a question. I have a url for Phantomjs which generates a PDF. But I want to generate the PDF on Serverside.

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

This is where I send the data to the generatepdf.php

The link generates a PDF with Phantom.JS

Now I do the following in the generatepdf.php

 $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: How can I open a PDF in a new tab with the stuff from the phantom.js result?

I hope you understand my question.

Best Regards.

4
  • What library or tool are you using in generatepdf.php to generate PDF ??? Commented May 22, 2015 at 12:04
  • $link contains a url which generates a PDF Commented May 22, 2015 at 12:07
  • Do you have to make a POST request to get the pdf? Commented May 22, 2015 at 12:14
  • You mean in the javascript code? Commented May 22, 2015 at 12:24

2 Answers 2

2

Ok i got another solution. I just linked to the php page and the PHP page got the PDF content. Plus I had to change the header to application pdf

Sign up to request clarification or add additional context in comments.

Comments

0

Instead using CURL and all that stuff simply hit the $link of php file in new tab.. (If the file is actually generating PDF)

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

4 Comments

Yeah thats what I was doing before but I want to generate the PDF on serverside. So I give the link to php and there it should be generated and given back to javascript
It depends on the logic. What are you using in php for PDF? are you using TCPDF or MPDF like libraries?
Its just a URL to phantom.js
Then I guess you need to store generated PDF somewhere on the server and same hit the `path' of the stored PDF, :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.