DEV Community

Cover image for Printing Front-and-Back ID Cards at Exact ISO/IEC 7810 ID-1 Scale (85.6 x 53.98 mm) Without Uploading Sensitive Documents
Jason Liang
Jason Liang

Posted on

Printing Front-and-Back ID Cards at Exact ISO/IEC 7810 ID-1 Scale (85.6 x 53.98 mm) Without Uploading Sensitive Documents

Search for "merge front and back of ID card to A4 PDF" and almost every top result asks you to upload high-resolution photos of your driver's license, national ID, or passport card to an unknown remote server.

From a security engineering perspective, that workflow is indefensible. Once a raw JPEG of a government-issued ID leaves the browser over HTTPS, you have zero visibility into server access logs, temporary /tmp directories, CDN caches, S3 lifecycle rules, or third-party processing queues. And the irony is that placing two cropped images onto a printable PDF page requires zero server-side compute. Modern browsers can perform perspective correction, watermark baking, exact ISO scaling, and 300 DPI PDF assembly entirely in local RAM.

Exact ISO/IEC 7810 ID-1 Physical Geometry

Standard driver's licenses, national identity cards, and payment cards conform to ISO/IEC 7810 ID-1:

  • Width: 85.60 mm
  • Height: 53.98 mm
  • Corner radius: 3.18 mm

When people paste smartphone photos of an ID into a word processor, they usually drag the corner handles until it "looks roughly right." That often prints the card 20% oversized or squashed, which bank clerks and administrative offices reject.

In a browser-based layout engine, convert those ISO constants straight into exact 300 DPI canvas pixels and PostScript PDF points (1/72 inch):

const MM_PER_INCH = 25.4;

const ID1_MM = {
  width: 85.60,
  height: 53.98,
  cornerRadius: 3.18,
};

const toPx300 = (mm) => Math.round((mm / MM_PER_INCH) * 300);
const toPt = (mm) => Number(((mm / MM_PER_INCH) * 72).toFixed(2));

// At 300 DPI: 1011 x 638 px, corner radius 38 px
// In PDF points: 242.65 x 153.01 pt, corner radius 9.01 pt
Enter fullscreen mode Exit fullscreen mode

Rounding to exact pixel dimensions on a 300 DPI plate guarantees that when the PDF embeds /ViewerPreferences with /PrintScaling /None on DIN A4 (210 x 297 mm) or US Letter (215.9 x 279.4 mm), a ruler placed over the printed sheet measures 85.6 x 53.98 mm down to printer tolerance.

Perspective-Cleaning Phone Captures Locally

Users rarely scan IDs on a flatbed scanner; they snap angled photos on a desk with a phone camera. That introduces trapezoidal perspective distortion.

Before scaling the card to 1011 x 638 px, map the four user-selected card corners to the target rectangle using a 2D projective homography (an 8-degree-of-freedom 3x3 transformation matrix solved via Gaussian elimination). Sampling the source ImageData with bilinear interpolation across the destination 1011 x 638 pixel grid produces a crisp, rectangular card face in a few milliseconds on the main thread—or inside a Web Worker to keep pointer dragging smooth.

After the warp, apply an exact 3.18 mm (38 px at 300 DPI) rounded-rectangle clipping path (ctx.roundRect(0, 0, 1011, 638, 38)) so stray desk background outside the card's rounded corners disappears cleanly.

Baking Anti-Misuse Watermarks Into the Pixels

Many privacy-conscious users add a diagonal watermark such as "FOR VERIFICATION ONLY" (or a specific purpose and date) across ID copies before handing them to a landlord, hotel, or HR department.

A subtle security pitfall when generating PDFs: do not add the watermark as a separate PDF text overlay or annotation object. Anyone with a free PDF editor can select and delete a text layer in two seconds, recovering the clean ID image underneath.

Instead, paint the diagonal watermark directly onto the 300 DPI canvas before encoding the card image into the PDF stream:

function drawAntiMisuseWatermark(ctx, width, height, text) {
  ctx.save();
  ctx.translate(width / 2, height / 2);
  ctx.rotate((-24 * Math.PI) / 180);

  ctx.font = '600 28px system-ui, -apple-system, sans-serif';
  ctx.fillStyle = 'rgba(20, 20, 20, 0.22)';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';

  const stepX = 360;
  const stepY = 120;
  for (let y = -height; y <= height; y += stepY) {
    for (let x = -width; x <= width; x += stepX) {
      ctx.fillText(text, x, y);
    }
  }
  ctx.restore();
}
Enter fullscreen mode Exit fullscreen mode

With low-opacity repeating strokes tiled across portrait and text regions, the underlying identity details stay completely legible for legitimate verification while making unauthorized reuse dramatically harder.

Composing Front and Back on A4 or US Letter

On the final 300 DPI sheet (2480 x 3508 px for A4 or 2550 x 3300 px for US Letter), center both 1011 x 638 px card faces vertically with a generous ~15–20 mm gap between front and back. Adding subtle outer crop hairline marks (drawn outside the card boundary so they never touch the ID content) makes cutting or filing effortless while keeping total page memory under ~40 MB.

When you release the temporary URL.createObjectURL handles right after generating the downloadable PDF Blob, no residual image references linger in memory.

Verifying Zero-Upload Claims With Airplane Mode

Any web tool can slap a "100% private" badge on its landing page. As engineers, we should prefer verifiable architecture over trust-me marketing copy.

Because a purely client-side canvas-to-PDF pipeline requires zero backend API calls after the initial static assets load, it is trivially testable:

  • Load the page in your browser.
  • Open DevTools on the Network tab—or simply switch your device into Airplane Mode.
  • Select front and back ID photos, adjust corners, apply your "FOR VERIFICATION ONLY" watermark, and export the 300 DPI PDF.

If the tool still crops, warps, watermarks, and outputs the full A4 or US Letter PDF offline with zero network errors, you have mathematical proof that your identity documents never touched a server.

That exact offline-first architecture is how we built the local front-and-back ID card print tool as part of the client-side print suite at CreoArt Poster. Sensitive personal documents belong in volatile browser RAM on your own machine—never in someone else's cloud storage bucket.

Top comments (0)