The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

fpdf - various help needed

I have FPDF working fine using information from a database and have finally got more than one image to display per page (one per product).

The problem I initially had with the images was lining them up with the relvant product information and not overlapping. I have resolved this by calculating Y and placing the images accordingly. However, as I don't know how much text there is going to be per product, the image placement is now causing other problems that I cannot work out how to resolve:

1. If an image's height is more than the height of the content text then it overlaps with the next product heading.

2. It appears that my calculation of GetY() and SetY() is now causing a product's text to overlap the product above if it is more than the Y height I have set.

3. I also need to find out how to calculate the total height of all a product's information (hopefully related to the image problem above) so that if it is going to overlap 2 pages I can force a page break before the product heading.

$pdf->PrintPage(stripslashes($catRow['subcatname']),stripslashes($catRow['catname']));// $row['foo'] would be whatever value holds the subcat name // that you use to print the subcat name to the pdf // looks like its probably $catRow['subcatname']if ($catRow['catname'] != $current) {// this conditional will only be true when the subcat is not the same // as it was on the previous iteration of the loop

// print the value to the pdf$pdf->TOC_Entry2(stripslashes($catRow['catname']), 0, 0);

// we are updating the var since the subcat just changed$current = $catRow['catname']; } else {// we do nothing here. the subcat was the same value // on the last iteration so we dont print it}$pdf->TOC_Entry(stripslashes($catRow['subcatname']), 1, 1);$catid=$catRow['subcatid']; }$objproduct = new product;$objproduct->catid=$catid;$objproduct->search();

1. I'll try to explain: before writing any description of the product, you store Y position into a variable ($y_init). Now you start writing text. At the end of writing you store the current Y into another variable ($y_text) and you reset Y to initial position ($y_init) and show the image. After image is displayed you get Y again ($y_image) and you compare Y position after text was written and after image had been displayed. If Y from text is greater then set new Y to that Y. The code will explain better.

Thank you for your help. I have got the product information to stop overlapping now, but I can't get the Y value of the bottom of the image to puch down the next product in the page if the current products details are not as tall as the image. Therefore the images are getting cut off if this is the case and the next product is still overlapping the image.

I have tried your code in various ways and what is below is the best at the moment. I have tried many ways to calculate if the $x_image is greater than the $x_text as well but this doesn't seem to work either.

I have also tried calcualting the Y value for all of the text buand puting the image after, but this just pushes the image down below the relevant product information and the images overlap with each other. It seems to me that if I could just get the calculation for the Y co-ordinate at the bottom of the image to work as needed, all would be resolved.

chilli11, I attach an image that shows you how I imagined it will look when I posted that code. From the code you posted I see that you can have more than one image for every article. If you can post a sketch of how the pdf will look it would be more usefull.

Sorry for the delay in responding but I was waiting for your attachment to be authorised and then I forgot yesterday.

Anyway, that is nearly what I am trying for but I can see where the problem is coming from now in that above each section of text with an image is the product name. I have modifed your image quickly to show you how it is laid out with the header and hopefully this will help.

$pdf->SetY($y_init); // now you go back to the Y where you started printing text (description, details about product)
/*
You must set the corresponding x;
You display image here.
*/
$y_image = $pdf->GetY(); // this is the Y where image ended
if ($y_text>$y_image) $pdf->SetY($y_text); // if the Y where text ended printing > Y of image where ended printing then set current Y to text Y
/*
Continue to generate PDF.
*/

I hope I was clear enough and this helps you. If something goes wrong post a link to a pdf.

Thanks, I am not too sure about setting the corresponding X value but this is obviously key (as I have already tried the set Y and get Y in those positions in the code) and I will keep trying to see if I can work it out, thank you.

Thanks, I am not too sure about setting the corresponding X value but this is obviously key (as I have already tried the set Y and get Y in those positions in the code) and I will keep trying to see if I can work it out, thank you.

fpdf problem

Hi
is there anyone who can help me ?
My problem is that i am not able to print a page written in fpdf+asp
in LANDSCAPE.
I know the addpage() command but it does not work.
I am sure is my fall.
Is there anyone who can make me see an example ?
Thank you
Mauro
here is what i did !
It works but the page is always Portrait

I am hoping I can still get some help on this as no matter where or how I calculate and get the X value, I cannot resolve the problem of the images overlapping with the product below if it's text takes up less height.

I am hoping I can still get some help on this as no matter where or how I calculate and get the X value, I cannot resolve the problem of the images overlapping with the product below if it's text takes up less height.

I looked over the code and I found that after you insert the image in the pdf is possible that the y position will not change. I didn't try that, but you can. Print both y_text and y_image and see if are different. If are not different than you can sum the y_text and image height and voila... you found y_image and now you check:

I also cannot owrk out how to calculate if a products details and / or image are going to overlap the bottom of a page and if so force it onto the next page.

Can anyone help please.

Look into the fPDF source code. You will manage to make a function that will calculate how much space (height) is until you reach the bottom of the page. You already know current position and you have the y where bottom starts and you find how much space you have on the page.