Forum How do I...?

Dynamic image not show on pdf

cristianq9
Hello,

I use princexml to generate PDF from html.

I have some graph images that are dynamic generated on-fly. When I generate PDF sometimes that images not load in PDF, some load.. I think it's related to timeload of images.

In my html I try to fix by adding:

<link rel="preload" as="image" href="{$fpimg}" />

or

#preloadedImages{
width: 0px;
height: 0px;
display: inline;
background-image: url({$fpimg});
background-image: url();

}

or

var errcnt = 0;
$("img").error(function () {
if(errcnt < 3){
src = $(this).attr("src");
$(this).attr("src", src);

$(this).addClass( "redborder" );

errcnt++;
}else{}
});

but none of these fix this issue.

Please advice.


mikeday
Are you seeing any warning messages in the Prince output log?
cristianq9
Hello,

yes, now I see that I get warning: Unknown image MIME type text/html.

Images are generated by php and code looks like this:

header('Content-Type: image/png');
imagepng($mergedImage);
imagedestroy($mergedImage);
exit();

I managed to fix this issue by downloading copy of images to server and all works ok now, but I need to know exactly if there is an problem with loading dynamic images.

Here is an example of image that give error: https://www.floorplantool.com/421/account.php?todo=image&id=17372
mikeday
It works for me when I try it here, but possibly the server is occasionally overloaded or redirects to a login page of some kind.
cristianq9
Hello,
yes, where there are more images and server is loaded sometimes it takes longer to generate image. it there any way I can force prince to wait longer for images? I try with --http-timeout=10 but this not does the trick.
mikeday
Perhaps when the server is overloaded it does not return the PNG but redirects to a HTML page instead; you could try this by accessing the URL via a browser at this time.
cristianq9
no, it always return the png, but if I have 4 or more images in html server is loading slow one by one.
I am 100% that server return png every time because if I test html I always get images.

I have an license and I am in 12 months of free support, can I get somehow in touch with you to help me with this issue ?

Thx.

Edited by cristianq9

mikeday
Sure, you can email me at mikeday@yeslogic.com.

One thing to try would be the --no-parallel-downloads option, which will slow down Prince by making it retrieve images one at a time, hitting the server less hard.
cristianq9
Hello,

Adding --no-parallel-downloads option did the trick. All works ok now. It generate pdf slower but all images are showing.

Thank you very much.