ScreenshotNeo

BlogHTML to image & PDF

How to Set Page Size and Margins in PDFCrowd HTML to PDF Conversions

Set PDFCrowd page size, orientation, and margins with HTTP API examples, then troubleshoot scaling, clipping, and extra whitespace.

By the ScreenshotNeo team4 October 20267 min read

Set PDFCrowd’s page_size to a supported preset such as A4 or Letter, or define page_width and page_height with units. Set margin_top, margin_right, margin_bottom, and margin_left separately when you need predictable whitespace. The documented defaults are A4 and 0.4 inches per margin. For edge-to-edge output, use no_margins=true and remove any page-level CSS spacing that remains.

1. Make a conversion with explicit page settings

This cURL example posts a URL to PDFCrowd’s HTTP API, saves the response as a PDF, and specifies Letter landscape with half-inch margins on each side. Replace the credentials and input URL with values for your account and document.

curl -f -s -S \
  -u 'USERNAME:API_KEY' \
  -o output.pdf \
  -F url=https://example.com/ \
  -F page_size=Letter \
  -F orientation=landscape \
  -F margin_top=0.5in \
  -F margin_right=0.5in \
  -F margin_bottom=0.5in \
  -F margin_left=0.5in \
  https://api.pdfcrowd.com/convert/24.04/

Use -f so cURL returns a failure status for HTTP error responses, and -S to show an error message when silent mode is enabled. This example follows the documented HTTP API endpoint and layout fields; it does not imply a conversion was run. See PDFCrowd’s API reference for the complete request options.

2. Choose preset or custom page dimensions

Preset paper sizes

Set page_size to one of the documented presets: A0, A1, A2, A3, A4, A5, A6, or Letter. A4 is the default. Presets are the simplest choice when the PDF must match a standard paper size.

Custom dimensions

For a nonstandard canvas, provide page_width and page_height. Dimensions accept in, mm, cm, px, and pt. The documented default dimensions are 8.27in by 11.7in. PDFCrowd describes 200in as a safe maximum because larger pages might not open in some PDF viewers.

curl -f -s -S \
  -u 'USERNAME:API_KEY' \
  -o custom.pdf \
  -F url=https://example.com/ \
  -F page_width=210mm \
  -F page_height=297mm \
  -F margin_top=12mm \
  -F margin_right=10mm \
  -F margin_bottom=12mm \
  -F margin_left=10mm \
  https://api.pdfcrowd.com/convert/24.04/

Do not combine a preset with custom dimensions unless the API documentation for your chosen converter version defines which takes precedence. Pick one sizing method so the intended physical size is unambiguous.

3. Set margins, orientation, and page height

Need Setting Notes
Standard page page_size=A4 or Letter A4 is the default preset.
Custom page page_width, page_height Use supported units; keep dimensions within viewer-friendly limits.
Consistent printable area All four margin_* fields Each otherwise defaults to 0.4in.
Wide output orientation=landscape Portrait is the default.
Edge-to-edge page no_margins=true CSS margins and padding can still create whitespace.
One tall page page_height=-1 For content where page breaks are unwanted, such as a web page or infographic.

Margins are independent. Set all four when consistent whitespace matters, or adjust only the sides that need different spacing. Each accepts the supported dimension units. For a zero-margin request, use this form:

curl -f -s -S \
  -u 'USERNAME:API_KEY' \
  -o full-bleed.pdf \
  -F url=https://example.com/ \
  -F page_size=A4 \
  -F no_margins=true \
  https://api.pdfcrowd.com/convert/24.04/

PDF page margins and HTML layout spacing are separate. If the document itself has outer padding or margin, removing the PDF margins will not remove those CSS gaps.

4. Diagnose fitting, scaling, and leftover whitespace

Page dimensions determine the physical sheet. content_fit_mode determines how rendered HTML is fitted into the printable area; it is documented for converter version 24.04 and later. Its listed values are:

  • auto (default)
  • smart-scaling
  • no-scaling
  • viewport-width
  • content-width
  • single-page
  • single-page-ratio

Choose a fit mode only after checking the document width and printable area. With no scaling, content wider than the available area may be clipped. Width fitting can change the scale, and single-page modes change how content is fitted to one page. These controls do not replace choosing the desired paper size and margins.

If the PDF still has unexpected whitespace, check three places:

  1. The API margins and whether no_margins is enabled.
  2. Top-level document CSS, including margins and padding on html and body.
  3. Configured header and footer content or heights, plus the content area reserved for them.
html, body {
    margin: 0;
    padding: 0;
}

PDFCrowd’s layout FAQ identifies page size, margins, header/footer height, and content area as factors in the rendered layout. Inspect them together when the visible content does not align with the page edges.

5. Python and Node.js request examples

The API examples below send the same kind of multipart form settings as the cURL request. Install the Python dependency with python -m pip install requests. The Node.js example uses the built-in fetch and FormData APIs in a runtime that supports them.

Python

import requests

url = "https://api.pdfcrowd.com/convert/24.04/"
data = {
    "url": "https://example.com/",
    "page_size": "Letter",
    "orientation": "landscape",
    "margin_top": "0.5in",
    "margin_right": "0.5in",
    "margin_bottom": "0.5in",
    "margin_left": "0.5in",
}

response = requests.post(
    url,
    auth=("USERNAME", "API_KEY"),
    data=data,
    timeout=120,
)
response.raise_for_status()
with open("output.pdf", "wb") as pdf:
    pdf.write(response.content)

Node.js

const form = new FormData();
form.set('url', 'https://example.com/');
form.set('page_size', 'Letter');
form.set('orientation', 'landscape');
form.set('margin_top', '0.5in');
form.set('margin_right', '0.5in');
form.set('margin_bottom', '0.5in');
form.set('margin_left', '0.5in');

const response = await fetch('https://api.pdfcrowd.com/convert/24.04/', {
  method: 'POST',
  headers: {
    Authorization: 'Basic ' + Buffer.from('USERNAME:API_KEY').toString('base64'),
  },
  body: form,
});

if (!response.ok) {
  throw new Error(`PDFCrowd returned HTTP ${response.status}: ${await response.text()}`);
}
const pdf = Buffer.from(await response.arrayBuffer());
await import('node:fs/promises').then(({ writeFile }) => writeFile('output.pdf', pdf));

Keep credentials in environment variables or a secret store in production. Do not expose an API key in browser-side JavaScript or commit it to source control.

6. Troubleshooting common layout problems

Symptom Likely cause What to change
Margins are larger than expected One or more margin fields were omitted, so the 0.4in defaults apply; or HTML CSS adds spacing. Set all four margins explicitly and inspect html/body padding and margin.
Full-bleed output still has a border of whitespace no_margins removes page margins, not CSS spacing or header/footer areas. Set no_margins=true, reset outer CSS spacing, and check header/footer configuration.
Content is cut off horizontally The content exceeds the printable width, possibly with no-scaling. Check page size, margins, source width, and fit mode. Consider landscape or an appropriate width-fit mode.
Content looks too small A fit mode may be shrinking wide content to fit the page. Inspect source width and compare the selected fit behavior; use a larger or landscape page if that matches the intended output.
The PDF is one long page or has unwanted breaks page_height=-1 requests expanded height; otherwise a paginated page height naturally splits content. Use a finite page height for pagination, or -1 when one continuous page is intended.
A very large custom PDF does not open Some PDF viewers may not handle dimensions above the documented safe maximum. Keep dimensions at or below 200in or divide the content into multiple pages.
The request fails before producing a PDF Credentials, endpoint/version, or form field values may be invalid. Check the HTTP status and response body, verify credentials and supported values, and consult the API reference for the converter version.

7. Performance, reliability, and cost considerations

PDF page size and margins are layout choices; they do not by themselves make a conversion faster or guarantee that source-page content has finished loading. For repeatable output, explicitly set the page preset or both custom dimensions, all four margins, orientation where needed, and any fit mode you depend on. Keep the converter version and source page stable when comparing layout changes.

For a fixed paper target, presets reduce ambiguity. For a report or print workflow with known dimensions, custom width and height offer control, while very large dimensions can reduce PDF viewer compatibility. A single expanded-height page avoids page breaks but may be inconvenient for printing and viewing. Choose based on how the PDF will be consumed.

Pricing depends on the PDFCrowd account and service plan; the reviewed layout reference does not establish a price. Check the current service pricing for the conversion volume and features your application needs.

8. Or skip the browser setup

If your job is capturing a web page as an image rather than controlling a multipage paper document, ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns PNG, JPEG, WebP, or a PDF. See the ScreenshotNeo API documentation for options.

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://stripe.com \
  -o shot.webp
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo returned HTTP ${res.status}`);
await import('node:fs/promises').then(({ writeFile }) => writeFile('shot.webp', Buffer.from(await res.arrayBuffer())));
  • Cookie banners are accepted and removed before capture; more than 60 known consent platforms, newsletter popups, and chat widgets can be removed, with each step configurable.
  • Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
  • An MCP server gives AI agents tools to take screenshots, inspect page information, and capture PDFs.
  • The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Every feature is on every plan.

Sign up for 1,000 free screenshots a month, no card required.

9. Frequently asked questions

Can I use millimeters for margins?

Yes. The documented dimension units include millimeters, inches, centimeters, pixels, and points.

Does setting zero margins remove every gap?

No. It removes the PDF page margins. CSS spacing and header/footer areas can still leave whitespace.

Should I use landscape or custom dimensions for a wide document?

Try landscape with a standard preset when a common paper size is suitable. Use custom width and height when the target dimensions themselves are nonstandard.

When is an expanded-height page appropriate?

Use page_height=-1 for a continuous web page or infographic where page breaks would interfere with the intended view. Use a finite page height when printing or pagination matters.