ScreenshotNeo

BlogHTML to image & PDF

How to Convert HTML to PDF with GrabzIt

Convert an HTML string, live URL, or local HTML file to PDF with GrabzIt. Configure assets and page layout, then troubleshoot missing styles and watermarks.

By the ScreenshotNeo team4 October 20268 min read

To convert HTML to PDF with GrabzIt, choose the method that matches your input: use ConvertHTML for an HTML string, ConvertURL for a published page, or the SDK’s file-to-PDF method for a local HTML file. In the JavaScript API, provide your Application Key and the HTML or URL, set the output format to pdf, and download the result. Make CSS and images available to the renderer, choose page settings for your document, and note that GrabzIt says free-tier and trial API conversions include a watermark.

Choose the right input method

Your input GrabzIt method Use it when
HTML markup string JavaScript ConvertHTML; Node.js html_to_pdf You generate the document markup in your application.
Published page URL JavaScript ConvertURL; Node.js url_to_pdf The page is reachable at a URL and should be rendered as served.
Local HTML file Node.js file_to_pdf or the equivalent method in your SDK You already have an HTML file on disk. Check how that SDK resolves local and linked resources.

These inputs are not interchangeable. An HTML string does not automatically carry the files referenced by relative paths. A URL conversion starts from a web address. A local file conversion must still be able to resolve its CSS, fonts, and images.

Convert an HTML string to PDF with the JavaScript API

The JavaScript API requires the GrabzIt library and an Application Key. The JavaScript API documentation also says to authorize the domain where the library is used in your account. Consult the official JavaScript API documentation for the current library setup and download or callback flow. The essential conversion call is:

grabzIt("YOUR_APPLICATION_KEY").ConvertHTML(
  "<html><head><title>Invoice</title></head><body><h1>Invoice 1042</h1><p>Amount due: $42.00</p></body></html>",
  { format: "pdf", download: 1 }
);

Replace the sample markup and key with your own. The documented example sets PDF format and requests a download. Keep the key restricted to authorized domains as instructed by GrabzIt, and use the full library setup from its documentation in your page.

Convert a published URL

For a page already served over the web, use the URL conversion method and the documented PDF options:

grabzIt("YOUR_APPLICATION_KEY").ConvertURL(
  "https://example.com/invoice/1042",
  { format: "pdf", download: 1 }
);

The URL must be reachable by the conversion service. If the page requires a logged-in session, custom request headers or cookies may be needed; check the options supported by the API or SDK you are using.

Convert a local HTML file with Node.js

GrabzIt’s Node.js documentation lists file_to_pdf, html_to_pdf, and url_to_pdf. Follow its installation and authentication instructions, then use the method matching your input. The SDK’s option names and result handling are specific to Node.js, so do not copy JavaScript API parameter names into Node.js without checking the Node.js reference.

// Node.js SDK shape: initialize the GrabzIt client using the
// current Node.js documentation, then call its file-to-PDF method.
// Method arguments and save/result handling depend on the SDK version.
grabzItClient.file_to_pdf("./invoice.html", {
  /* Set supported PDF options from the Node.js documentation. */
});

This is an SDK method outline, not a complete executable Node.js program: the supplied research identifies the method but does not provide the package initialization, exact arguments, or save callback signature. Use GrabzIt’s Node.js technical documentation for those version-specific details. For an HTML string, use its documented html_to_pdf method; for a URL, use url_to_pdf.

Make CSS, fonts, and images appear

Missing styling and images usually mean the renderer cannot resolve the referenced resources. A conversion service cannot reliably load a relative path such as images/logo.png unless it has a base address or the resource is included in a way the conversion supports.

  • Use absolute URLs for linked stylesheets, images, and fonts when the resources are publicly reachable.
  • Inline or embed resources when appropriate for a self-contained HTML string.
  • Set a base address with the API’s documented address option when your markup uses relative references. This helps resolve paths against the intended site location.
  • Check access to resources that need authentication or are blocked from external requests.

For example, <img src="images/chart.png"> needs a usable base address or a resolvable absolute URL. A path that works in your local browser may not work when the conversion service renders the document.

Set PDF page and rendering options

Choose options based on the document’s content and print target. GrabzIt’s JavaScript parameter reference documents these options; the Node.js SDK has its own documented PDF option names.

Option What it controls Decision
Page size Paper dimensions. JavaScript reference lists A3, A4, A5, A6, B3, B4, B5, B6, Legal, and Letter; default is A4. Use the size expected by readers or a downstream print workflow.
Orientation Portrait or Landscape; default is Portrait. Landscape may suit wide tables or charts; portrait often suits prose.
CSS media type Screen or Print; JavaScript reference default is Screen. Choose Print if the document has print-specific CSS; otherwise inspect how its screen styling renders.
Margins Space around page content. Leave room for printing and avoid clipping near page edges.
Background Whether page backgrounds are included, where supported. Enable when background colors or images carry meaning; consider ink use for printed copies.
Title PDF document title metadata or displayed title, depending on API behavior. Set a useful title for saved files and document handling.

The JavaScript reference also documents address for relative assets and waitfor to wait before conversion where needed. Node.js documents additional PDF options such as links, outline, cover URL, and password. Confirm each option’s exact name and behavior in the documentation for the SDK in use.

cURL and Python alternatives

GrabzIt documents a REST API as well as SDKs. The supplied research confirms REST key, callback, format, and address parameters, but does not include the exact endpoint, response format, or complete request schema needed to write a reliable runnable cURL or Python conversion here. Consult the official REST API documentation for the current request and result flow rather than guessing an endpoint or response handling. If your task is simply to capture a page as a PDF, ScreenshotNeo provides a one-request screenshot/PDF API; example calls follow below.

Review the output before using it

  1. Check every page for clipping, unexpected breaks, and content that runs past the margins.
  2. Verify that the chosen page size and orientation suit the document.
  3. Inspect fonts, images, and styles, especially resources referenced through relative paths.
  4. Review print-specific CSS behavior if you selected the Print media type.
  5. For trial or free-tier API conversions, check whether the watermark is acceptable. GrabzIt says unbranded production output requires a premium plan; the research here does not establish current plan prices or quotas.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. A single GET request can return a screenshot in PNG, JPEG, or WebP, or a PDF. It can remove cookie and consent banners from more than 60 known platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs.

Use this cURL request to capture a page as PDF (the documented API base is ScreenshotNeo API documentation):

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://stripe.com \
  -d format=pdf \
  -o page.pdf

ScreenshotNeo offers 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000 screenshots. Every feature is on every plan. Try it by creating a free ScreenshotNeo account.

Troubleshooting

Symptom Likely cause What to check
Styles are missing Stylesheet URL is relative, unreachable, or unavailable to the renderer. Use an absolute URL or a valid base address; confirm the resource can be fetched.
Images do not appear Relative image path, inaccessible file, or rendering before resources are ready. Use absolute or embedded image resources, set the base address, and consult the API’s documented wait option.
PDF is clipped or breaks awkwardly Paper size, orientation, margins, or print CSS do not match the content. Adjust the relevant PDF settings and review the resulting pages.
Conversion is rejected from a webpage The JavaScript API domain may not be authorized, or the Application Key may be wrong. Verify the key and authorize the site domain in the GrabzIt account.
Watermark appears GrabzIt states free-tier and trial API conversions include a watermark. Use a premium plan for unbranded production output; check GrabzIt’s current plan terms directly.
Node.js example does not match your package SDK method signatures and result handling are version-specific. Use the current Node.js documentation for initialization, arguments, and saving the conversion.

Performance, reliability, and cost considerations

PDF conversion has to retrieve and render the page’s content and linked resources. Large images, slow external assets, and pages that depend on client-side rendering can affect completion time or output. Keep the document’s resources reachable and lightweight, and use documented wait behavior where a page needs time to finish rendering. For critical documents, inspect the generated file and handle conversion failures in your application according to the SDK’s documented result flow.

GrabzIt’s supplied documentation states that free-tier and trial API conversions carry a watermark and that premium plans are needed for unbranded production output. No current prices, limits, or plan quotas were verified in the supplied research, so check GrabzIt’s own pricing before estimating ongoing conversion costs. If you need screenshots or PDF capture through one simple GET call, ScreenshotNeo’s documented pricing starts with 1,000 free screenshots monthly and paid plans from $5 for 3,000.

FAQ

Can I convert an HTML string without publishing a page?

Yes. Use JavaScript ConvertHTML or the Node.js html_to_pdf method, with the library and authentication setup required by that SDK.

Why does the same HTML look different in the PDF?

The renderer may be using a different CSS media type, page size, or resource base than your browser. Check Screen versus Print styling, page settings, and whether linked assets are accessible.

Does a GrabzIt free trial create unbranded PDFs?

According to GrabzIt’s HTML-to-PDF documentation, free-tier and trial API conversions include a watermark. Its page says a premium plan is required for unbranded production documents.

Can I set a password on a PDF?

The Node.js documentation lists a password PDF option. Check the current SDK reference for the exact parameter and supported behavior.

References: GrabzIt HTML-to-PDF API, GrabzIt JavaScript API, JavaScript parameter reference, Node.js technical documentation, and REST API documentation.