This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Shrunk PDF from URL API

jason.rudland wrote on 2011-03-10:
Hi,

I'm trying to format a PDF generated from a URL via the API. The API is called form a PHP script (below). At first it generated the PDF fine, but with no margins (horiz or vert), so I added the page height, width to A4 dimentions, and margins to 1 inch.

Now the PDFs it creates have the margins, but has scaled down the pages so they appear as a long thin column.

Here's a link to a generated PDF.

Can anyone help with what's wrong?

Thanks

Jason


require 'pdfcrowd.php';
function savePDF($site_url)
{
try
{
$client = new Pdfcrowd("j************d", "c*****************************0");
$siteFilename="saved-reports/" . $site_url . ".pdf";

$client->setPageHeight("297mm");
$client->setPageWidth("210mm");
$client->setHorizontalMargin("1in");
$client->setVerticalMargin("1in");
$client->setFooterText("Get Me In Google!");
// $client->setAuthor("Jason Rudland");
$client->convertURI(curPageURL(), fopen($siteFilename, 'wb'));

// echo "remaining tokens: " . $client->numTokens();


}
catch(PdfcrowdException $e)
{
echo $e->getMessage();
}
}
support wrote on 2011-03-10:
I checked the source URL with the W3C Markup Validation Service and it shows 85 errors.

It seems that there is some tag mismatch in the page as it reports (among others):

Line 304, Column 7: end tag for "HEAD" which is not finished
Line 426, Column 143: end tag for element "STRONG" which is not open
Line 437, Column 7: end tag for "DIV" omitted, but its declaration does not permit this


These errors may confuse the service which in turn generates a shrunk PDF file. Please, try to fix the most outstanding errors in your page and let us know if it helps.
jason.rudland wrote on 2011-03-11:
I fixed all the errors, and it now validates HTML & CSS. But the problem remains.
support wrote on 2011-03-11:
The cta1, cta2 and cta3 divs are causing the problem. If you disable CSS rules for these ids then the margins in the generated PDF looks fine.

If you inspect e.g. the cta1 div in Chrome, you will see that it is 800px wide and that it starts at position 250 - thats the reason for the wide right margin in the created PDF.

You can try to refactor these elements and position them using e.g. text-aling:center instead.

Hope this helps.
jason.rudland wrote on 2011-03-11:
That worked - thanks for your help!