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

No margin on first page only & default left margin larger than right

support_nztcl wrote on 2018-10-11:
I want to create a cover page with a full size background image. But then for the rest of the document, have margins set on the pages. Is there a method for that?

Also, I am seeing my left margin coming in much more than the right. I am doing the following set up before conversion:
$client = new \Pdfcrowd\HtmlToPdfClient("username", "apikey");

$client -> setFooterHtml($footerHtml);
$client -> setExcludeFooterOnPages("1");
$client -> setOrientation("landscape");
$client -> setPageDimensions("210mm","297mm");
$client -> setPageMargins("5mm", "5mm", "5mm", "5mm");

$client -> convertUrlToFile("", "example.pdf");

Is it potentially the html causing the left margin to come in more than the right?
support wrote on 2018-10-12:
Margins are applied to all pages. A cover page with no margins can be achieved by few ways:

Solution 1. The easiest way is to run 2 phases - convert HTML to PDF and afterwards join a cover page with the PDF.

// create the API clients
$html_to_pdf_client = new \Pdfcrowd\HtmlToPdfClient("your_username", "your_apikey");
$pdf_to_pdf_client = new \Pdfcrowd\PdfToPdfClient("your_username", "your_apikey");

// run the conversion for a cover page
$cover = $html_to_pdf_client->convertFile("conver.html");
// if it's always the same, you can create it just once and use a local file

// run the conversion for a content of document
$document = $html_to_pdf_client->convertFile("document.html");

// join cover page and document

Solution 2: Let's say that your final PDF has maximum 10 pages. Let your document HTML to have 1st page empty (e.g. with CSS page break rules). Create a cover page PDF with 1 cover page and 9 empty pages (e.g. with <div style='height: 7000'>). Use the PDF with setMultipageWatermark($coverPdf).

Solution 3: Quite complicated solution is to update your HTML to define margins inside (e.g. with fixed positions or dummy HTML elements) and use $client->setNoMargins(true)

I'd prefer 1st solution because it's the most flexible and can combine any type of PDFs.

Please feel free to contact us for further assistance.