3 Replies - 6963 Views - Last Post: 17 August 2011 - 08:00 AM Rate Topic: -----

#1 violent   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 27-February 09

[AJAX/PHP] Printing a PDF from a server response

Posted 15 August 2011 - 11:36 AM

Hey,

I can't seem to find a straight answer about this being possible. So far I know that its possible to create a PDF in PHP with HTML code. This raises a few questions though. In PHP, can I apply CSS to the HTML code before it is converted to PDF (the PDF will contain the CSS formatted HTML). Also, can I receive the PDF in a HTTP Request by using print/echo in PHP? Also, can I insert new page indicators in the PDF (HTML code?) so that when I physically print the PDF "it" knows where to create a new page? I would use javascript to print the PDF to another tab or popup.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: [AJAX/PHP] Printing a PDF from a server response

#2 codeprada   User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 963
  • View blog
  • Posts: 2,382
  • Joined: 15-February 11

Re: [AJAX/PHP] Printing a PDF from a server response

Posted 15 August 2011 - 02:49 PM

PDF does not recognize CSS styles. PDF has it's own way of creating styles. I'm not sure if the class, framework or what not you're using automatically does it for you. I'm currently looking at dompdf that handles things like that.

Pertaining to you receiving the PDF file in a HTTP request, if you mean sending a Content-Type header telling the browser that it should use it's native PDF application to view the PDF file then yes. Other than that I'm not sure what you mean.

Inserting new page indicators...You'll have to read the documentation and determine how a new page is determined.

Printing the PDF...The native PDF application on the client's computer will handle that.
Was This Post Helpful? 2
  • +
  • -

#3 violent   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 27-February 09

Re: [AJAX/PHP] Printing a PDF from a server response

Posted 16 August 2011 - 05:44 AM

Thanks! I'll report back if I run into any problems.
Was This Post Helpful? 0
  • +
  • -

#4 violent   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 27-February 09

Re: [AJAX/PHP] Printing a PDF from a server response

Posted 17 August 2011 - 08:00 AM

Ok, I have one problem. I'm trying to receive the pdf file in an XMLHttpRequest but I don't know how this works with files.

Using this in javascript:
httpRequest.onreadystatechange = alertContents;
httpRequest.open('POST', url);
httpRequest.setRequestHeader('Content-Type', 'application/pdf'); //is this correct?
httpRequest.send('selectedDate=' + selectedDate);



How do I receive the response from this in php:
$htmltest = '<!doctype html><head><style type="text/css">
	     .break{page-break-after: always;}
	     </style></head><body>
	     <h1>page1</h1>
	     <table><tr><td>ddddddddddddddddddddddddddddddddd</td><td>ggggggggggggggggggggggggggggg</td></tr></table>
	     <div class="break"></div>
	     <h1>page2</h1>
	     <table><tr><td>ddddddddddddddddddddddddddddddddd</td><td>ggggggggggggggggggggggggggggg</td></tr></table>
             </body></html>';

$dompdf = new DOMPDF();
$dompdf->load_html($htmltest);
$dompdf->render();
$dompdf->stream("sample.pdf");



I know that for a normal text php print/echo it would be inserted in httpRequest.responseText but how does this work files (pdf)?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1