ScreenshotNeo

BlogHow-to

How to Convert a Hindi Website Page to PDF with wkhtmltopdf

Convert a Hindi web page to PDF with wkhtmltopdf, preserve Devanagari text, and troubleshoot fonts, encoding, dynamic content, and layout.

By the ScreenshotNeo team4 October 20267 min read

Use wkhtmltopdf with UTF-8 encoding, then verify that the conversion environment has a font with Devanagari glyph coverage. For a URL, run:

wkhtmltopdf --encoding utf-8 'https://example.com/hindi-page' hindi-page.pdf

UTF-8 addresses character encoding; it does not supply missing glyphs or guarantee modern-page rendering. Check the resulting PDF for legible Hindi shaping, complete content, and correct layout.

1. Install and check wkhtmltopdf

Install wkhtmltopdf using the package or build appropriate for your operating system, then check that the executable is available:

wkhtmltopdf --version
wkhtmltopdf --extended-help

The project download page lists 0.12.6 as the stable series, released June 11, 2020. Because this is an older rendering stack, pages that depend on newer browser features may not match what you see in a current browser. Check the installed build and test the page in the environment where the PDF will be generated. Official downloads and build information.

2. Convert a Hindi page from a URL

For a page that declares its encoding correctly, the minimal command may be enough. Adding --encoding utf-8 is useful when the document does not declare its encoding properly or the converter guesses incorrectly:

wkhtmltopdf --encoding utf-8 'https://example.com/hindi-page' hindi-page.pdf

Quote the URL and output path, especially if they contain shell-sensitive characters or spaces. Use the page’s actual public URL. The standard command form is wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>; a page object can be a URL or a filename. See the official usage guide.

3. Convert local HTML

You can pass an HTML file instead of a URL:

wkhtmltopdf --encoding utf-8 ./hindi-page.html ./hindi-page.pdf

Check that the HTML is UTF-8 and that its linked stylesheets, images, and fonts are reachable from the conversion process. For local resources, wkhtmltopdf documents --allow <path> and --enable-local-file-access. Builds can differ in their defaults, so check wkhtmltopdf --extended-help or the installed manual.

# Allow access to one needed resource directory
wkhtmltopdf --encoding utf-8 --allow /path/to/page-assets ./hindi-page.html ./hindi-page.pdf

Only grant access to the files or directories the document needs. Local-file access can expose more than the page’s intended assets if the input is untrusted.

4. Make Devanagari render correctly

Check encoding and font coverage as separate issues:

  • Encoding: the HTML should be UTF-8. Use --encoding utf-8 when the page’s declaration is missing or unreliable.
  • Glyph coverage: the machine running wkhtmltopdf needs a font that contains Devanagari glyphs, and its font configuration must be available to the converter. A correctly encoded Hindi string can still appear as boxes or missing characters without suitable fonts.
  • Shaping and layout: inspect conjuncts, vowel marks, line breaks, and mixed Hindi and Latin text in the generated PDF. The result depends on the installed runtime and the page.

The project identifies fontconfig and freetype2 among its runtime font dependencies. Its documentation does not mandate one particular Hindi font or promise that every installation includes Devanagari support. Ensure suitable fonts are installed in the actual conversion environment, including containers or servers, rather than relying only on fonts present on a developer’s desktop. Project download and dependency notes.

5. Wait for dynamic page content

JavaScript is enabled by default, and the usage guide lists a default JavaScript delay of 200 ms. That may be too short for content populated asynchronously. Try a page-appropriate delay:

wkhtmltopdf --encoding utf-8 --javascript-delay 1500 'https://example.com/hindi-page' hindi-page.pdf

If the page controls readiness through window.status, wait for its expected value:

wkhtmltopdf --encoding utf-8 --window-status ready 'https://example.com/hindi-page' hindi-page.pdf

Use the status value the page actually sets. These options control when conversion proceeds; they do not guarantee that every script, network request, or lazy-loaded element has completed. Inspect the PDF for missing text or images and adjust the wait for the page.

6. Set page size, margins, and orientation

Use layout options when the page is clipped, too small, or unnecessarily spread across pages. For example, set paper size, orientation, and margins:

wkhtmltopdf --encoding utf-8 --page-size A4 --orientation Landscape --margin-top 12mm --margin-right 12mm --margin-bottom 12mm --margin-left 12mm 'https://example.com/hindi-page' hindi-page.pdf

Choose settings based on the content:

  • --page-size selects a paper size such as A4 or Letter.
  • --orientation Portrait or --orientation Landscape controls page direction.
  • --margin-top, --margin-right, --margin-bottom, and --margin-left control printable margins.
  • --print-media-type asks for print styles, when the page provides them.
  • --background includes background graphics when required by the design.
  • Header and footer options can add page information; consult the installed usage output for their exact syntax.

Start with defaults if the page already has suitable print styles. Changing paper size or margins cannot repair missing font glyphs or incomplete JavaScript content.

7. Inspect and validate the PDF

  1. Open the PDF in a viewer and check that Hindi text is visible rather than replaced with empty boxes.
  2. Inspect vowel marks, conjuncts, punctuation, and mixed-script passages at normal zoom.
  3. Check the first and last page, page breaks, headers, footers, and whether important content is clipped.
  4. Compare the PDF with the source page for content that appears after a delay or scroll.
  5. Repeat the conversion in the production environment if fonts, network access, or installed wkhtmltopdf builds differ.

No command-line option can guarantee that every website will render correctly. The page’s markup, assets, scripts, fonts, and the converter’s runtime all affect the output.

8. Troubleshooting

Symptom Likely cause What to try
Hindi appears as boxes or missing characters The conversion environment lacks a font with Devanagari coverage, or font configuration is unavailable. Install an appropriate Devanagari-capable font in the actual runtime, refresh font configuration as required by the operating system, and convert again. Verify other Hindi PDFs in the same environment.
Hindi characters are garbled The document encoding is missing or misidentified. Confirm the source is UTF-8 and retry with --encoding utf-8. Encoding does not solve missing glyphs.
Content or images are missing Assets are inaccessible, blocked, or loaded after the conversion starts. Check network access and asset URLs. For local HTML, check local-file permissions and use a narrowly scoped --allow path if needed. If scripts populate the page, adjust the JavaScript wait or use a page readiness status.
The PDF captures a loading state The default JavaScript delay is shorter than the page’s load time. Try --javascript-delay with a suitable value or --window-status if the page exposes a readiness signal. Recheck the output; neither option guarantees complete rendering.
The page is clipped or scaled poorly Paper size, orientation, margins, or print styles do not fit the page. Try landscape for wide content, adjust paper size and margins, and check whether the page has print CSS.
Local stylesheets or fonts fail to load The converter cannot access the referenced file under the build’s local-file rules, or paths resolve differently. Check paths from the converter’s working directory and inspect --extended-help. Allow only the required asset directory.
The output differs from a current browser The installed wkhtmltopdf rendering stack may not support a feature the page uses. Check the installed version and simplify or print-style the page where possible. Verify the output in the target environment rather than assuming current-browser parity.

9. Reliability, performance, and security

Conversion time depends on page complexity, network and asset loading, JavaScript, and the configured wait. A long fixed delay can make jobs slower; a short delay can capture incomplete content. Use the smallest page-appropriate wait that produces complete output, and inspect representative pages when building an automated workflow.

For repeatable results, keep the wkhtmltopdf build and font setup consistent across machines. Log the command, exit status, and stderr for automated jobs, and validate that the expected PDF was produced before serving it. Network failures and page changes can affect URL conversions, so handle failed conversions as failures rather than treating every output file as complete.

Security: the project warns against using wkhtmltopdf on untrusted HTML. User-supplied HTML or JavaScript can put the machine running the converter at risk, including complete server takeover. Sanitize and isolate input before processing it in a service or automated job, and do not expose broad local-file access to untrusted documents. See the project’s security and deployment notes.

10. Or skip the browser setup

If your goal is to capture a page as a PDF without installing and configuring wkhtmltopdf, ScreenshotNeo offers a website screenshot API and MCP server. Its PDF capture supports settings such as paper size, margins, landscape orientation, and page ranges. Review the API documentation.

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

The API accepts one GET request with a URL and returns a screenshot or PDF. Use an API key from your account. Its cookie and consent handling removes known consent banners, newsletter popups, and chat widgets before capture, and those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers identify the page verdict and billing status. AI agents can use its MCP server tools, including capture_pdf. The free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots. The same features are available on every plan. Sign up for 1,000 free screenshots a month, with no card required.

Frequently asked questions

Does --encoding utf-8 install a Hindi font?

No. It sets the encoding used when wkhtmltopdf interprets the document. Devanagari glyphs still need to be available through the conversion environment’s fonts.

Can wkhtmltopdf convert a page that requires a login?

Only if the converter can access the page with the required session or authentication setup. The command alone does not bypass access controls; confirm the page is available to the conversion process.

Will every Hindi website convert exactly as it appears in my browser?

No. Output depends on the page, its assets and scripts, installed fonts, and the wkhtmltopdf build. Inspect the PDF in the target environment.

Can I safely convert HTML submitted by users?

Do not process untrusted HTML or JavaScript without sanitization and appropriate isolation. The wkhtmltopdf project warns that malicious input can compromise the host.