|
-
Aug 31st, 2004, 09:34 AM
#1
Thread Starter
Fanatic Member
PDF file does not render in browser with PDFLib *RESOLVED*
Hello;
I am trying to teach myself PHP and its functions with respect to PDF files. I have successfully installed PDFLib, but each time I try an example that should render the newly created PDF file to the browser, it displays gobbly-gook. I know the library is being accessed successfully - I am using PDFLib 6 with PHP 4.3. (Apache server running under Windows 2000) The following is source code with output:
Code:
<?php
$radius = 200;
$margin = 20;
$pagecount = 10;
$pdf = pdf_new();
if (!pdf_open_file($pdf, "")) {
echo error;
exit;
};
pdf_set_parameter($pdf, "warning", "true");
pdf_set_info($pdf, "Creator", "pdf_clock.php");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Analog Clock");
while ($pagecount-- > 0) {
pdf_begin_page($pdf, 2 * ($radius + $margin), 2 * ($radius + $margin));
pdf_set_parameter($pdf, "transition", "wipe");
pdf_set_value($pdf, "duration", 0.5);
pdf_translate($pdf, $radius + $margin, $radius + $margin);
pdf_save($pdf);
pdf_setcolor($pdf, 0.0, 0.0, 1.0);
/* minute strokes */
pdf_setlinewidth($pdf, 2.0);
for ($alpha = 0; $alpha < 360; $alpha += 6) {
pdf_rotate($pdf, 6.0);
pdf_moveto($pdf, $radius, 0.0);
pdf_lineto($pdf, $radius-$margin/3, 0.0);
pdf_stroke($pdf);
}
pdf_restore($pdf);
pdf_save($pdf);
/* 5 minute strokes */
pdf_setlinewidth($pdf, 3.0);
for ($alpha = 0; $alpha < 360; $alpha += 30) {
pdf_rotate($pdf, 30.0);
pdf_moveto($pdf, $radius, 0.0);
pdf_lineto($pdf, $radius-$margin, 0.0);
pdf_stroke($pdf);
}
$ltime = getdate();
/* draw hour hand */
pdf_save($pdf);
pdf_rotate($pdf,-(($ltime['minutes']/60.0)+$ltime['hours']-3.0)*30.0);
pdf_moveto($pdf, -$radius/10, -$radius/20);
pdf_lineto($pdf, $radius/2, 0.0);
pdf_lineto($pdf, -$radius/10, $radius/20);
pdf_closepath($pdf);
pdf_fill($pdf);
pdf_restore($pdf);
/* draw minute hand */
pdf_save($pdf);
pdf_rotate($pdf,-(($ltime['seconds']/60.0)+$ltime['minutes']-15.0)*6.0);
pdf_moveto($pdf, -$radius/10, -$radius/20);
pdf_lineto($pdf, $radius * 0.8, 0.0);
pdf_lineto($pdf, -$radius/10, $radius/20);
pdf_closepath($pdf);
pdf_fill($pdf);
pdf_restore($pdf);
/* draw second hand */
pdf_setcolor($pdf, 1.0, 0.0, 0.0);
pdf_setlinewidth($pdf, 2);
pdf_save($pdf);
pdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
pdf_moveto($pdf, -$radius/5, 0.0);
pdf_lineto($pdf, $radius, 0.0);
pdf_stroke($pdf);
pdf_restore($pdf);
/* draw little circle at center */
pdf_circle($pdf, 0, 0, $radius/30);
pdf_fill($pdf);
pdf_restore($pdf);
pdf_end_page($pdf);
# to see some difference
sleep(1);
}
pdf_close($pdf);
print("<h1>test 3</h1>");
$buf = pdf_get_buffer($pdf);
$len = strlen($buf);
header("Content-type: application/pdf");
//header("Content-Length: $len");
header("Accept-Ranges: bytes");
header("Content-Disposition: inline; filename=foo.pdf");
print $buf;
pdf_delete($pdf);
?>
and some of the output that shows in the browser:
%PDF-1.5 %äãÏÒ 1 0 obj [/PDF/ImageB/ImageC/ImageI/Text] endobj 5 0 obj <> stream xœ3P0€ÃC.§€ endstream endobj 6 0 obj 15 endobj 7 0 obj <> stream xœ5»q1 CsUÁHð#±—`ÜÅn߬ v€áCÍ.Qi~s•DOù±a*¿cÏ>ã™~Fe÷Ù-®¾Ý A†ä¤2•bÙò=²pw]’¡Ü…$ÀôÞ‰²Kt_×a®ËFmvŸ Œ>pÙ»l O/,EÕ‡mÑ—ø¨±Mw¦ý¨gqÿ´)ÁÞEïõVq)ÞvÜ{„òçÁK°_˜í+úŸ[®G_ãkü†V@º endstream endobj 8 0 obj 180 endobj 9 0 obj <> stream xœMŽÍqCAƒïT¡<³ ö¯Ž”ðrÈÁ>§ýˆµßLNúè}£al<"=ˆÞ&¾Ý¼á×F _Ví˜ýCÔZYKÒËbŒCárÌ€¯ŽôÔÄ=E™M³%ߺk[AO»?‘Yõ¤ |á1T_¨á%—%YPÏy Üï^öc\ûø^‡œ äÀ5³D«WµO쎊òæõ¶(¸?ñŒ<±©ûlyô2Žxwt›=q§Uò—ý°AK endstream endobj 10 0 obj 183 endobj 11 0 obj <> stream xœMÁ0ÿ©‚œ \H KЇ}Û¾Ž3¾vCGÜC¦Àå¢*+B¦Üuè”÷`yÊkTùǺ~lý3ŸV†¤¹@‹[,£y ´q²ÃÌŒuJLÉo¶énÞ†¥µa±H ž/aÒa&Çí[ÉëGïbüÏ«MÙÓšo¾ Ü$w‰²Eš†^‘ç‰ ‹Ÿ°\M¦r¯2 H“<xFÌ; endstream endobj 12 0 obj 169 endobj 13 0 obj <> stream xœMޱ1 sU¡ldÙuPÂ|1ís¶á!ðìάµhçCº&ºÞ«Ô¢/™ÙSvºÌ;_)¬¬9X<¤F.¡-m"Ì)>R\õ%F'Y\R3»¸ ÿÙþ=ÛŸÆÇZ 5OmpEÁâ!˜ÍLœW{iÁæ”›¼¿‰.û endstream endobj 14 0 obj 130 endobj 15 0 obj <> stream xœ323S0P0³†–æ æÆ )†\† å\`Á\.0ŒIç€$à •ÁÌðe ¼ endstream endobj 16 0 obj 53 endobj 17 0 obj <> stream xœEM±Ä0ë5#XvŒÍÁ)Rü×Y?@.—¤’¨ªR¤o¾*› ª‹\HñµÙËfŽ‘F¶'°0-‰'t2Á+º©øµ+Ó¸Á¢0 ï‹…´‘o7ŸÔ>RNì¸QD"– endstream endobj 18 0 obj 109 endobj 19 0 obj <> stream xœ=»‘1 CsV> stream xœ=Á €0 ÿ™Â ÕQ£ÂŒP|úf}âHð²e; }`£ÃÙÀp\´teܰŒ~T¼lïe2'C2¦fÈN ¥Ó8úOÍ^Róú’çêEûðÓn;íš¡›
It's as is the pdf_get_buffer method is not doing what it should (??? - just a guess)
I have been at this for over a day now and am completely perplexed. The above code should show a clock - and every article I have read shows the same code. Browser is IE, and at this point I am going to install Netscape to see if there is any difference. Any comments from folks out there with experience with PDF's are most welcome! Thanks much.
****UPDATE: I have successfully rendered the above code in Netscape 7.2 so this must be a browser issue. If anyone knows what is needed to satisfy IE's requirements to get this thing to work, please tell!!
Last edited by ahara; Aug 31st, 2004 at 11:14 AM.
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
Aug 31st, 2004, 11:13 AM
#2
Thread Starter
Fanatic Member
found the problem....the PHP header method has problems with IE....(known bug) I need to download SP 2 (should have done so already anyway )....works fine with Netscape though!!
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|