Forum How do I...?

Can't get images into pdf

tharkun
I'm dong the following:
    
    <?php
    ob_start();
    ?>

    //setting up content with image paths like this:
    <img src="http://myurl/images/myimage.gif" />

    <?php
    $pageContent = ob_get_contents();

    $prince = new Prince_Wrapper($config->prince->exepath);
    $baseUrl = 'C:/wamp/www/project_webroot';
    $prince->setBaseURL($baseUrl);
    $prince->addStyleSheet($baseUrl . '/templates/print-minimal/css/pdf.css');
    
    ob_end_clean();

    $prince->convert_string_to_file($pageContent, 'c:/wamp/www/s-tool/file.pdf');
    ?>

The file is created, the css applied but no images showing. What am I doing wrong. I also tried a few other things including setting up a virtual host for the project. Nothing worked so far.
Thanks for your help!
mikeday
Try calling $prince->setLog('/tmp/prince.log'); and see if there are any warning messages about failing to load the images.
tharkun
I have a log set, just stripped it out for the post and there is nothing to help me there.
If I deliberately change the css path to something wrong, I see it in the log, otherwise I just get the usual 5 lines of a successfull run.
mikeday
So you are referencing images in your HTML, and Prince isn't giving any error or warning messages, but the images are not showing up in the PDF output? That's strange. What if you try converting the HTML from the command-line instead, does that work?
tharkun
Can't really test it, the page is dynamically generated. I could save the source as html file and put that into the webroot and then generate via command line. That should probably work. I'll try.
tharkun
If I do it as described in the last post via command line, it works. All picturs in the file.
Something with my paths must be wrong. How is that normally done?

I can replace the basePath of my pictures before sending the markup to prince but that doesn't seem to help either.
What's the normal best practice with image paths and prince?
mikeday
If Prince cannot resolve the image you really should be getting a warning message in the log. Is the image path an absolute HTTP URL, eg. "http://example.com/image.jpg" or a relative URL like "../image.jpg" or a semi-absolute path like "/images/image.jpg"?
tharkun
Could it be a CSS thing then? That the image is suppressed somehow? I had other such issues, tables where set to inline and all collapsed, etc.
mikeday
That could be a definite possibility, for example "display: none" applied to a parent element. However, you should be able to reproduce this from the command line with the same HTML and style sheets. Perhaps try a simpler document from PHP, with only one image?
tharkun
I setup a staging environment on the live server so I can test in the Unix environment. I get the pictures in now.
But everything in the document is a total mess. Things appear or don't seemingly at random, 70% of the text doesn't show at all, some pages are just white, some have a gray area somwhere, the images show all on top of each other etc. I can really not understand what's causing this. I use prince in another project and there I don't have any such problems.

Is prince reading in some default CSS from somewhere? Can it be some kind of incompatibility with the environment? Doctype?
mikeday
Sounds peculiar. Prince reads the default style sheets in /usr/lib/prince/style, but they shouldn't be causing this kind of mess. Are you able to send me (mikeday@yeslogic.com) a sample document to reproduce this behaviour?
tharkun
Indeed my results are getting stranger and stranger... (can der be a problem with the fonts too?)

This is what error acrobat reader gives me and how my text looks now, I realise one very strange thing, the text that is inserted from constants shows well... some encoding issue maybe?
prince-probblem-1.JPG
(ah sorry, typo in the filenname)

I'll send you the respective pdf to your email.
  1. prince-probblem-1.JPG136.5 kB
tharkun
Now there is also a second message:
prince-problem-2.JPG
  1. prince-problem-2.JPG23.3 kB
mikeday
The PDF is corrupted as it is intermixed with the HTML file used to create it.
tharkun
You don't know how glad I am that you're not watching the finals :) or that you're a multi-tasker like me. I trying to finish this task today because I'm going on a holliday.

Anyways, thanks for that feedback, it tells me a lot indeed but I don't know why this happens... is it possible that output buffering is disabled on a host... (just a retoric question, I'm going to check that out now.)
mikeday
Who said I'm not watching the finals? Looks like Murray is going to push the Federobot to a 4th set! :D

It looks as if some HTML is being emitted before you're capturing the output buffer, and again more is emitted after you finish generating the PDF file. Perhaps a header/footer that is produced before this PDF generation code is called?
tharkun
Yes, there is unwanted html and I hope once I've got rid of this my css and mangle-up problems will also be gone.
Well, Fed just broke back... hm. It seems the latest firmware of the Federobot is relatively bugfree again.
mikeday
Seems I spoke too soon about the 4th set! Best of luck with the PHP.
tharkun
Thanks a lot for your support, you made my day! It works now, after generating the whole page outside of my general architecture I can control finally what is being echoed.
Getting support from someone based in Melbourne on the final sunday of the AO, wow! I just hope that Roger is going to win the next three slams and then get bored, so others can have fun too. Well ok, he can do one more because 20 sounds better than 19... and maybe London Olympics 2012... but then retire as number one and watch the other guys battle it out on TV.