I'm using HTML2PDF (http://html2pdf.fr/) to generate PDF files from a webpage. However, I'm having a kind of weird error: the generated file can be perfectly shown with the "Preview" Mac tool (or simply touching the space bar when the downloaded PDF file is selected), but when I try to open the file with the Adobe Acrobat Pro, the following error message appears:
Adobe reader could not open "file.pdf" because it is either not a support file type or because the file has been damaged (for example, it was sent as email attachment and was'nt correctly decoded).
Here is how I'm generating the PDF content and the PDF file itself:
$content = '<page backtop="12mm" backbottom="12mm" backleft="8mm" backright="8mm" style="font-size: 10pt;">
<h1>MyTitle</h1>
<br>
<table style="width: 100%;">
<tr>
<td style="width: 25%;"></td>
....
</tr>
</table>
</page>';
$html2pdf = Yii::app()->ePdf->HTML2PDF('P','A4','en',true,'utf-8');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($content);
$html2pdf->Output($outputname , EYiiPdf::OUTPUT_TO_DOWNLOAD );
Any idea on what can be happening? Maybe I'm missing something about the format or the file encoding? I've tried different encodings but nothing seems to solve the problem...
Thanks in advance for your time and effort! :)
Solved! After dealing with this a little bit more, I've decided to open the PDF file with a plain text editor, and I've found that the PHP page used to generate the file included by default a header and a footer (I'm using the Yii Framework), which resulted in "printing" the HTML header and footer code in the PDF file... Is anyone ever has the same problem I had, the way to solve it is to open the page's controller file (in 'protected/controllers/myPageController.php') and change the following line:
$this->render('index');
By this one:
$this->renderPartial('index');
Everything works as expected now! ^_^
Related
i am having problem when downloading file using Php script, Problem is when csv generated it contains document type HTML.
"Which is: HTML document (5.9 KB)"
I tried everything like changes Content type etc but issue still persist.
Please suggest,
Thanks in advance.
I'm using mpdf to create PDF files on the fly, and the files open fine in a browser but Adobe gives me an error:
Adobe Acrobat Reader DC could not open 'example-filename.pdf'
because it is either not a supported file type or because the file
has been damaged (for example, it was sent as an email attachment
and wasn't correctly decoded).
I looked at other questions about this (another mpdf + adobe error), and checked out the pdf in a text editor. I found that the first part of the file looked like this:
<!DOCTYPE html>
<head>
<title>
CapstoneDB
</title>
%PDF-1.4
%âãÏÓ
After I removed everything up to %PDF-1.4 (including the tab), the file opened fine in Adobe, which is great, except that I need to be able to get the generated pdfs to open in Adobe without manually fiddling with the code every time.
Here's my wrapper function that calls mpdf with the html and css:
include('../mpdf/mpdf.php');
function user_download_pdf($html, $css_file, $filename) {
$mpdf = new mPDF();
$stylesheet = file_get_contents($css_file);
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output($filename, "D");
}
I never feed mpdf a full html page, usually just an h3 and one or more tables. Maybe I need to be giving mpdf an entire html page, including <head>, <body>, etc? Is there any way to change mpdf configuration or the way I call mpdf in php that would get rid of the html junk at the beginning of the pdf file that's gunking everything up?
Place
ob_clean();
immediately before
$mpdf->Output();
Without this mpdf sometimes includes the website page HTML and not just the HTML that you want in the PDF, probably because headers have already been sent elsewhere in the code. That can mess up your PDF so Adobe won't open it.
I uploaded the .doc file using php code and saved it in a folder ,the path is stored in database.
When i tried to make a view of the doc file in a div ...a dialog box appears asking whether to save or openwith ..
I'm using wampserver ....I just tried like this
<iframe name="awindow" frameborder=2 width=580 height=440 src="www/siva_example/pdf/1_siva.doc"></iframe>
Any help regarding..
Is it possible to view .doc file in browser or i have to convert it to pdf format...
It's not possible to display a .doc[x] in HTML. You can try to convert the .doc[x] to HTML or to an image.
you can view doc file by adding this to your header at request time
<?php
header('Content-disposition: inline');
header('Content-type: application/msword');
// not sure if this is the correct MIME type
readfile('MyWordDocument.doc');
exit;
You could try using google docs for this, use the below code, it works perfectly for ppts, have not been able to test it for a doc yet
<iframe src="http://docs.google.com/gview?url=http://yourdomain.com/document.doc&embedded=true" style="width:550px; height:450px;" frameborder="0"></iframe>
Ofcourse you would have to update the url as per your program using PHP
Currently I am using the standard way to embed an pdf to the browser, however, the built-in pdf viewer for my target browser is not working as expected. I would like to force (Chrome, Firefox and IE8 (if possible, but IE9+ is also ok)) to use the adobe reader. The problem is , I can only change this option manually. Is there any way to change the option in HTML/ JS/ PHP ? Thanks.
<OBJECT data="YourFile.pdf" TYPE="application/x-pdf" TITLE="SamplePdf"
WIDTH=200 HEIGHT=100>
shree
</object>
I try to find the solution and someone suggested header, not working unfortunately e.g.
Content-Type: application/pdf
Content-Disposition: inline; filename.pdf
You can use Google PDF viewer to embed pdf files on to your website. Use this link https://docs.google.com/viewer
Example:
<iframe src="https://docs.google.com/viewer?url={HTTP PATH OF THE PDF FILE}&embedded=true" width="600" height="780" style="border: none;"></iframe>
https://docs.google.com/viewer?url=http://research.google.com/archive/bigtable-osdi06.pdf
Check out PDFObject which is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.
In your HTML, you could set up a div to display the PDFs:
<div id="pdfRenderer"></div>
Then, you can have Javascript code to embed a PDF in that div:
var pdf = new PDFObject({
url: "https://sample.pdf",
id: "pdfRendered",
pdfOpenParams: {
view: "FitH"
}
}).embed("pdfRenderer");
Cheers
Trick Chrome and Firefox (and maybe other browsers) into displaying the PDFs using the Adobe Reader plugin (for full PDF Open Parameters support among other benefits) by using one of the following 'Adobe PDF in XML Format' types in your embed code:
application/vnd.adobe.pdfxml
application/vnd.adobe.x-mars
This works fine as of my answer today and I'm hopeful it will continue to work fine. I'm using it currently with standard PDF files as a workaround for embedding PDF files in the browser that need to use the Adobe PDF plugin rather than the browser's built-in PDF rendering. Even though my PDF files are standard (non-XML) files, they appear to load just fine with this new application type parameter.
<OBJECT data="YourFile.pdf" TYPE="application/vnd.adobe.pdfxml" TITLE="SamplePdf"
WIDTH=200 HEIGHT=100>
shree
</object>
Im using http://www.ashberg.de/php-barcode/ scripts to generate a barcode. I now need to import the barcode into a PDF from html. (Im using html2pdf_v4.03 for html -> pdf)
<div style=" display:inline;"><img id='barcode' alt='barcode' src="scripts/barcode/barcode.php?mode=jpg" /></div>
works, but when I import it to PDF it errors. So I decided to try generate the barcode and save it to a dir as an img and refrence it in the html I then convert to PDF.
So I tried
file_put_contents('scripts/barcode.jpg', file_get_contents('scripts/barcode/barcode.php?mode=jpg'));
and I get failed to open stream: error
if i try
file_put_contents('scripts/barcode.jpg', file_get_contents('scripts/barcode/barcode.php'));
It runs but the image file it creates is not readable/ broken.
Please assist?
Write full url (http://domain.com/scripts/barcode/barcode.php) instead of scripts/barcode/barcode.php. Probably its opens local php file when you use file_get_contents()