Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
hallo, I have one problem when I make a report with PHP. I want to convert the report to PDF with fpdf.
when I running it, my report had been display with the correct data from database, but above the report appears this error :
 
%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream xœ3Rðâ2Ð35W(çr QÐw3T04Ô30PISp á1 Ò¹ €¤P‘…ž±©‚…±ž¡©BHŠ‚Fbv©Brf^I¢Bvbn©¦BHPŸB Ä0#K„Y`cd ©ó!&›êYX€l71›l¨oˆfªÛA-) endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 2 0 obj <> >> endobj 8 0 obj << /Producer (FPDF 1.52) /Creator (HTML2FPDF >> http://html2fpdf.sf.net) /CreationDate (D:20130321095643) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000000282 00000 n 0000000670 00000 n 0000000009 00000 n 0000000087 00000 n 0000000369 00000 n 0000000465 00000 n 0000000566 00000 n 0000000778 00000 n 0000000902 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1005 %%EOF
 
is anyone that can help me?
anyone who knows the answer, please help me..:(
Posted 20-Mar-13 23:07pm
Comments
enhzflep at 21-Mar-13 7:57am
   
Might I ask how you propose we would fix unseen code?
Why not provide the code that generates the above? Surely readers will be in a better position to give you an answer than is currently the case.
I suspect it may be a result of character/character sets used. I also note that your pdf doesn't appear to contain the 'contains binary content' flag, though I can't remember if that was a part of the spec for PDF v1.3, nor can I remember what fPdf's approach is 0 whether it's staticm or adapts to the content - IIRC, a pdf that uses flate compression should signify that it contains binary data (i.e, the file isn't comprised only of the first 128 chars - it uses the full 8bits of each char)
 
I ended up hating fpdf so much that I rewrote a workable before ported it to C++. (I couldn't work out how to, or indeed if you could add (a) bookmarks (b) file attachments.
 
In any case, it's a pretty weird output - objects out of order, streams found without attributes. Oi Vey!
 
Here's a 'binary content included' header:
25 50 44 46 2D 31 2E 34 0A 00 78 30 31 00 78 30 32 00 78 30 34 00 78 30 33 0A
 
Or in human form (. stands in for non-printable 00 character, ◙ stands in for 0A)
%PDF-1.4◙.x01.x02.x04.x03◙
 
And an example of a correct stream:
38 20 30 20 6F 62 6A 0A 3C 3C 2F 4C 65 6E 67 74 68 20 34 37 2F 46 69 6C 74 65 72 5B 2F 46 6C 61 74 65 44 65 63 6F 64 65 5D 3E 3E 0A 73 74 72 65 61 6D 0A 48 89 33 34 D0 33 50 30 04 11 B9 5C A6 16 A6 30 4E 0E 57 30 32 17 26 67 61 6C 04 54 81 90 84 F0 73 B9 C0 06 20 24 91 B8 50 39 B0 08 48 1F 00 0A 65 6E 64 73 74 72 65 61 6D 0A 65 6E 64 6F 62 6A 0A
 
Again, in a form we're more familiar with:
8 0 obj
<</Length 47/Filter[/FlateDecode]>>
stream
H‰34Ð3P0¹\¦¦0NW02&galT„ðs¹À $‘¸P9°H
endstream
endobj
Witrotus at 23-Mar-13 0:25am
   
ok. sorry that i didn't show the code before.
this is the simple code that i had tried:
 
require('./html2fpdf/html2fpdf.php');
$html = "<table>";
$html .= "<tr valign='top'>";
$html .= "<td>example</td>";
$html .= "<td>Name</td>";
$html .= "<td>Score</td>";
$html .= "</tr>";
$html .= "</table>";

$pdf=new HTML2FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','I',34);
$strContent = $html;
$pdf->WriteHTML($strContent);
$pdf->Output("sample1.pdf","I");
echo $html;
?>
 
i hope you can help me.
enhzflep at 23-Mar-13 20:03pm
   
I'll sure sse what I can do.
It turns out that I used to use CezPdf, not fpdf as I had earlier thought. When I tried your example, I realized I needed to get HTML2FPDF. I can't seem to find it. Got a link?
enhzflep at 23-Mar-13 23:14pm
   
Actually, I just found the html2fpdf site (http://html2fpdf.sourceforge.net/) it looks like it's worth giving a miss - the site itself doesn't even work properly. I'd be inclined to try out html2pdf (note the missing f).
Witrotus at 24-Mar-13 21:24pm
   
dear ehnzflep, finally i got the answer of my question above hehehe :D
thanks for your will to help :')
 
but another problems are coming :(
i wanna ask you. hmm do you have a reference how to change font size in pdf ?
i had tried many ways. but it doesn't work :(
enhzflep at 24-Mar-13 21:36pm
   
No worries Witrotus.
 
I'm afraid that I don't. The mechanism used to create the pdf will dictate the method used to change the font/size of the text.
 
For instance, I use the following code when adding a new text object to a page:
(it's very low-level code)
As you may notice, the font-size is specified by way of a graphics command to the reader program, i.e the (sub) string "/F1 10 Tf" Instructs the reader to use the resource named as 'F1' as the font and to use 10 as the size (each unit is 1/72 of an inch)
 
I assume you're using a package of some kind to generate the pdf, if this is the case, you'll need to look up the documentation for it, as the way of setting the font-size will be entirely package-dependant.
 
Good-luck. :)
 

function createTextString($str, $xPos, $yPos, $size=12)
{
$mResult = sprintf("%1.1f %1.1f %1.1f rg\nBT\n/F1 %d Tf\n%d %d Td\n(%s) Tj\nET\n", 0,0,0, $size, $xPos, $yPos, $str);
return $mResult;
}
 
function addText($str, $xPos, $yPos, $size=24)
{
// step 1. Create the stream and add it to the object list
$mStream = new pdfStreamObj;
 
$mData = $this->createTextString($str, $xPos, $yPos, $size);
$this->curTextSize = $size;
 
$mStream->setData(new mStr($mData) );
$mStream->setOutputType("flate");
$objNum = $this->addObj($mStream);
 
// step 2. locate and update the page contents
$this->pageContentsArray->addItem( new mStr(sprintf("%d 0 R",$objNum) ) );
 
return $objNum;
}
Witrotus at 25-Mar-13 21:29pm
   
thanks for your advice i change html2fpdf to html2pdf and it more flexible to edit as i want :D
 
gomawo enhzflep.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100