I'm using the FPDF library to generate a PDF file.
Each page in the file is 100mm x 100mm with a 10mm margin on all sides.
The text that displays on each page varies (but should always ever be a maximum of 200 words).
I really want the text to display so it's centered perfectly in the middle of the page.
At the moment, I can get the text to be centre-aligned but am struggling to position it so it sits in the middle of the page every time. This is my code so far:
$pdf->AddPage();
$pdf->SetMargins($card_margin,$card_margin,$card_margin);
$pdf->SetAutoPageBreak(true,$card_margin);
$pdf->SetFont('Avenir','','10');
$pdf->SetAutoPageBreak(false);
$pdf->MultiCell(80,5,$text_to_print,0,'C');
$pdf->SetFont('Alex Brush','','13');
$pdf->MultiCell(80,10,$signee_text_to_print,0,'C');
And this is a screenshot of a PDF page that is produced from the above code:
Any ideas or suggestions would be greatly appreciated!
Use SetY before your call to MultiCell to "push down" where the text starts on the page. Since you indicate that it will never be more than 200 characters you should be able to estimate the height and used a fixed value for X which will get you very close to the center vertically every time.
$pdf->SetAutoPageBreak(false);
$pdf->SetY(100); // for example ... value will need to be changed of course
$pdf->MultiCell(80,5,$text_to_print,0,'C');
Related
I have to generate a PDF document that could take more than one page. Each page has a html table (that has a variable length), and a QR code at the bottom of the page.
The QR code will be at the bottom of every page of the document, but, if that is too difficult to achieve, I can have it only in first page.
I have the problem that the text of the html table is printing over the QR code. I tried using $pdf->setPageRegions without any positive result, because the coordinates used to define the position of QRCode and for setRegions are in different units.
How can I achieve this?
I use maphilight jquery plugin with hover and onclick features. Which works fine.
Is there a way to draw a rectangle by default on the areamap image at a predefined position and size? So without to hover or click on it, just draw a rectangle right after the page is loaded.
I would like to use this solution with PHP+mySQL search. So when someone searches and finds the desired objec on a page (as a part on an areamap, and I know the position of it), clicking on the result link, I would like to load the page that has this shape and would like to be highlighted or drawn around with a rectangle as long as the person click/hover on another area on the same page. Or if this is not possible, then just drawing the rectangle on the desired position.
Is there a way to accomplish this?
The searching and lauching mechanism is not an issue now... I'll do it somehow. I just need the solution to draw the rectangle on areamap.
I tried using CSS "z-index", canvas and even SVG but the rectangle was always drawn after the area map, so at the bottom of my page and not on the areamap :(
Can anyone help me? Thank you.
your rectangle also needs to have position:absolute css style, e.g.,
$('div.map').append('<div style="position:absolute;left:100px;top:100px;
height:10px;width:10px;background-color:#f00;z-index:1;"></div>');
I am writing a code in php 5 to generate a pdf file which will have the images.I am displaying full length images.The image gets cut as soon as it reaches the end of the page(i.e. bottom of the pdf page).I want the image to continue being displayed from the next page.So that the complete images is visible even if it is larger than the size of the pdf page.Is it possible?If so please help!!
I'm not sure if it can be done using fdpf alone. The Image() function does not support partial images; so you need to find a way to split the image beforehand (using GD or something similar.)
In short, you need to find out how much of the image to print per page (ie. how high is the printable area of the PDF page, excluding header, footer etc.), and then create a temporary image consisting of the correct clipping of the image. This is what you add with the Image() function.
If using GD, here is how to copy a portion of an image into another image:
GD imagecopy() function
I am using TCPDF to create PDFs with PHP. Everything works very nice, except when text would be placed where the footer resides. In my example, the text is shown only half, the rest is behind the footer. Is there an option which defines to put it on the next page?
Besides that, my PDFs differ from print to print, some have 1 page, some 2 or more. Is it possible to say that a specific text should only be placed on the page when it fits completely? if not, it should go to the next page.
I already have this in my code, but it doesnt help, the text is still cut.
$pdf->SetAutoPageBreak(true, 25);
I am creating the PDF by creating a huge HTML string and print that to the PDF using writeHTML. This is how it looks, the bold text on top should go to the next page, its hidden behind the footer.
Thanks!
I know that the question I have is quite complex, and I really hope someone can help me. I have created an image gallery qih jquery and php. Firstly I am grabbing all the image names from a MySql database, then taking them from the server folder and resizing them with php. It creates the thumbnails, then I created a pop up window with jquery which shows the image in large. After that I place a previous and next button and told jquery to grab the array of image results from php and echo them into the jquery using json. Then it goes through the array to create the next and previous effect. I then centered each individual image when the next and previous button were clicked. When you load the first and second picture it is not centered and it goes to the right. I CAN NOT figure out why this is happening. I really need some help here. There is too much code to post here so I am giving you the website and you can see pretty much everything in the source code. Remember that I am using php so if you are wondering how it is iterating through the pictures that why. Thanks if anyone can help me at all.
http://www.oceanphotostudio.com/test/collection/before-and-after.php
The reason it's getting offset is that the margins that center the popup div are being calculated before the image is loaded. Notice that on the first click, it will have margins of -37px and -30px. After one image is loaded, calling another one will use the width and height of the last image that was loaded in, which is why you can get unpredictable results.
Take a look at JQuery's load event handler for information on how to create a callback to resize after the image has been set to load, rather than before.
Your description totally overcomplicates the issue. Browser could care less how you generate the array or html on server, or what language it is
Your position problem is a simple css issue. You've set the top and left of your popup to 50%. This means top left corner of popup will start at dead center of page, and go right and down from there.
Use a browser console to inspect the html elements and the css rules that apply to them and adjust accordingly. WIthin the console you can make live edits to see impact of the adjustments in real time