Forum


Replies: 4   Views: 3127
Convert to pdf and view it in the browser instead of download
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by davelavinsky  · 04-11-2016 - 16:18

I'm concerned if people don't have Adobe on their computers. I think they are very, very likely to have the Adobe web plugin that allows them to see PDF files in their browser. So, is it possible to code it so that the PDF file opens in a new window in their web browser?

Right now, I have this which downloads.

$docx->enableCompatibilityMode();
$docx->createDocx("temp/".$ID);
$docx->transformDocument("temp/$ID.docx", "temp/$ID.pdf");

header('Content-type:application/pdf');
header('Content-Disposition:attachment;filename="'.$bp->Name.'.pdf"');
readfile("temp/$ID.pdf");

 

Posted by admin  · 05-11-2016 - 10:12

Hello,

Almost all browsers (Chrome, Firefox, Edge) include an internal PDF viewer. And if you install other PDF reader (such as Adobe or Foxit), they install a browser plugin in the browsers.

Regards.

Posted by davelavinsky  · 07-11-2016 - 10:35

I think you miread my question.

How can I code it in such a way that the browser's pdf reader fires up and views the resultant PDF instead of downloading it ?

Posted by admin  · 07-11-2016 - 10:54

Hello,

You can use this header:

Content-Disposition: inline; filename="filename.pdf"

Or if you set it as a link tag all browsers should open it instead of download the file.

Regards.

Posted by davelavinsky  · 07-11-2016 - 17:02

This did the trick. Thanks for your continued support.