PDFKit Measurement Unit Node.js
What is the measurement unit used in PDFKit (Node.js)? Quick answer: They use points (pt) as the measurement unit. 1 inch is equal to 72 points.
Sariful Islam
When working with PDFKit in Node.js, understanding measurement units is crucial for creating precisely positioned and sized PDF elements. This guide will explain PDFKit’s measurement system and provide you with a handy converter tool.
What Measurement Unit Does PDFKit Use?
PDFKit uses points (pt) as its default measurement unit.
- 1 point = 1/72 of an inch
- 1 inch = 72 points
- 1 point ≈ 0.352778 millimeters
- 1 mm = 2.83465 pt
This is the same measurement system used by most PDF specifications and desktop publishing software.
PDFKit Measurement Converter
Unit Converter
Why Does PDFKit Use Points?
The point system has deep roots in traditional print publishing. Before computers, typesetters and printers used points as the standard measurement unit. When Adobe created the PostScript language in the 1980s (which later became the foundation for PDF), they adopted this system to maintain consistency with the printing industry.
Historical Context:
The point system dates back to 18th-century French typography, where printer Pierre Simon Fournier established a standardized measurement. The modern typographic point (also called the PostScript point) was later standardized at exactly 1/72 of an inch, making mathematical calculations easier in the digital age.
Why 72 Points per Inch?
The number 72 is highly divisible (by 2, 3, 4, 6, 8, 9, 12, 18, 24, 36), which makes it incredibly convenient for creating grids, layouts, and proportional designs. This divisibility allows designers to create harmonious layouts with clean fractions like 1/2 inch (36pt), 1/3 inch (24pt), 1/4 inch (18pt), and so on.
Understanding the Coordinate System
PDFKit uses a Cartesian coordinate system with the origin (0, 0) at the top-left corner of the page. This differs from traditional mathematics where the origin is at the bottom-left.
Key Concepts:
- X-axis: Runs horizontally from left to right. Increasing X values move elements rightward.
- Y-axis: Runs vertically from top to bottom. Increasing Y values move elements downward.
- Origin Point: The top-left corner is (0, 0), not the bottom-left as in traditional math.
This top-left origin system is common in computer graphics and web development, making it familiar for most developers. However, if you’re coming from a traditional print design background, this might feel inverted since print design often uses bottom-left as the origin.
The Relationship Between Points and Pixels
One of the most confusing aspects for developers is understanding how points relate to pixels. Let me break this down in simple terms.
Understanding Resolution-Independent vs Resolution-Dependent
Resolution-Independent (Points):
Think of points like measurements in inches or centimeters - they represent a fixed physical size in the real world. When you say something is 72 points wide, it means 1 inch wide, period. It doesn’t matter if you print it on a basic inkjet printer or a professional press, it will always measure 1 inch when you put a ruler on it.
Resolution-Dependent (Pixels):
Pixels are different - they’re like the dots on your screen or printer. The physical size they represent depends on how tightly packed those dots are (the DPI/PPI). It’s like the difference between a mosaic made with large tiles versus tiny tiles - both can show the same image, but the tiny tiles create finer detail.
Real-World Analogy:
Imagine you’re making a poster that says “1 foot wide” (resolution-independent). Whether you paint it with a thick brush or a fine brush (low vs high resolution), it’s still 1 foot wide. But if you say “100 brushstrokes wide” (resolution-dependent), the actual size changes based on how wide each brushstroke is.
The Conversion: How DPI/PPI Changes Everything
DPI (dots per inch) or PPI (pixels per inch) tells you how many pixels fit into one inch. Here’s how it affects the point-to-pixel conversion:
- At 72 DPI: 1 point = 1 pixel (1:1 ratio)
- 72 points = 72 pixels = 1 inch
- At 96 DPI (standard web/screen): 1 point = 1.333 pixels
- 72 points = 96 pixels = 1 inch
- At 300 DPI (print quality): 1 point = 4.167 pixels
- 72 points = 300 pixels = 1 inch
Practical Example: From Figma to PDFKit
Let’s say you designed a business card in Figma at 96 DPI (common for screen designs):
Your Figma Design:
- Width: 960 pixels at 96 DPI
Converting to PDFKit:
Step 1: How many inches is this?
- 960 pixels ÷ 96 DPI = 10 inches
Step 2: Convert inches to points for PDFKit
- 10 inches x 72 points/inch = 720 points
So your PDFKit width should be 720 points.
Quick Formula:
// Figma/Photoshop to PDFKit conversion
const pixelWidth = 960;
const designDPI = 96;
const pdfkitPoints = (pixelWidth / designDPI) * 72;
// Result: 720 points
Another Example: Profile Photo
You have a profile photo that’s 300 pixels x 300 pixels at 96 DPI for your certificate template.
In PDFKit, this should be:
- 300 ÷ 96 x 72 = 225 points x 225 points
doc.image('profile.jpg', 100, 100, {
width: 225, // 300px at 96 DPI = 225pt
height: 225
});
Why Your PDF Might Look Different Than Your Screen Mockup
When you view a PDF on screen, your computer typically displays it at 72-96 DPI. But PDFKit creates resolution-independent documents. This means:
- On Screen: Your 720-point-wide element might display as 720 pixels (looks 10 inches at 72 DPI) or 960 pixels (looks 10 inches at 96 DPI), but physically measures the same 10 inches on screen
- When Printed: That same 720-point-wide element always prints as exactly 10 inches, whether on a 300 DPI or 600 DPI printer
The Key Insight:
A PDF doesn’t care about pixels - it only knows about points. The printer or screen decides how many pixels to use to represent those points. A high-resolution printer uses more pixels (dots of ink) to draw the same 720-point line, making it look sharper, but it’s still the same physical size.
This is why PDFs always look crisp when printed, unlike images that can look pixelated - the PDF renderer creates as many pixels as needed for the output device’s resolution.
Common Conversions
Here are some common conversions you’ll need when working with PDFKit:
Points to Other Units
- 72 pt = 1 inch
- 28.35 pt ≈ 1 cm
- 2.83 pt ≈ 1 mm
Standard Paper Sizes in Points
- A4: 595 x 842 points
- Letter: 612 x 792 points
- Legal: 612 x 1008 points
- A3: 842 x 1191 points
Deep Dive: Paper Size Standards
Understanding standard paper sizes is crucial when working with PDFKit, especially if you’re creating documents for international audiences or specific industries.
The A-Series (ISO 216 Standard)
The A-series paper sizes follow a elegant mathematical principle. Each size is created by halving the previous size, and all sizes maintain the same aspect ratio of √2:1 (approximately 1.414:1).
Why This Ratio Matters:
When you fold an A4 sheet in half, you get A5. Fold A5 in half, you get A6. This consistency means you can scale designs proportionally without distortion. The √2 ratio ensures that when you cut or fold a sheet in half along its length, the two halves retain the same proportions as the original.
Common A-Series Sizes:
- A0: 2384 x 3370 points (841 x 1189 mm) - Technical drawings, posters
- A1: 1684 x 2384 points (594 x 841 mm) - Flip charts, architectural plans
- A2: 1191 x 1684 points (420 x 594 mm) - Small posters
- A3: 842 x 1191 points (297 x 420 mm) - Tabloid newspapers, larger documents
- A4: 595 x 842 points (210 x 297 mm) - Standard business documents (most common)
- A5: 420 x 595 points (148 x 210 mm) - Notebooks, booklets
- A6: 298 x 420 points (105 x 148 mm) - Postcards, small flyers
North American Paper Sizes
North America uses a different standard based on imperial measurements, which doesn’t follow the same elegant mathematical progression.
Common North American Sizes:
- Letter: 612 x 792 points (8.5 x 11 inches) - Standard in US/Canada
- Legal: 612 x 1008 points (8.5 x 14 inches) - Legal documents, contracts
- Tabloid/Ledger: 792 x 1224 points (11 x 17 inches) - Newspapers, presentations
- Executive: 522 x 756 points (7.25 x 10.5 inches) - Day planners, organizers
The Letter vs A4 Debate:
Letter (8.5” x 11”) is slightly wider but shorter than A4 (8.27” x 11.69”). This seemingly small difference can cause layout issues when documents are shared internationally. If you’re building an application for global users, consider offering both options or defaulting to A4 for better international compatibility.
Practical Use Cases: Real-World Scenarios
Use Case 1: Creating Invoices for International Clients
When building an invoicing system, you need to consider that businesses in Europe, Asia, and Australia use A4, while North American businesses use Letter size. The measurement difference affects margin calculations, logo placement, and content flow.
The Challenge:
If you design an invoice layout at 595pt wide (A4), it will look cramped on Letter paper (612pt wide). Conversely, a Letter-sized layout might get content cut off when printed on A4.
The Solution:
Design with relative measurements and dynamic margins. Use percentages of page width rather than fixed point values. For example, instead of positioning your logo at 72pt from the left, position it at 12% from the left edge, which works proportionally on both sizes.
Use Case 2: Restaurant Menus with Variable Content
Imagine creating a PDF menu generator for restaurants. Menus often need to accommodate variable amounts of content - some have 20 items, others have 200.
The Challenge:
You need to know exactly how much vertical space each menu item takes to prevent content from overflowing onto invisible parts of the page or creating awkward page breaks in the middle of a dish description.
Understanding Vertical Space:
Text in PDFKit doesn’t have a fixed height until you render it. A 12-point font doesn’t take exactly 12 points of vertical space because of line height (leading) and descenders (the parts of letters like ‘g’ and ‘y’ that extend below the baseline).
Typically, you need to account for:
- Font size in points
- Line height (usually 1.2-1.5 times font size)
- Paragraph spacing
- Padding around text boxes
For a 12-point font with standard line height, expect each line to consume about 16-18 points of vertical space.
Use Case 3: Certificates with Precise Alignment
When creating certificates, precise measurement is critical. A misaligned name or date can make a certificate look unprofessional.
The Challenge:
You need to center text perfectly, align signatures at exact positions, and ensure decorative elements are symmetrically placed. This requires understanding both absolute positioning (fixed coordinates) and relative positioning (calculated from page dimensions).
Key Measurement Concepts:
Horizontal Centering: Calculate the center point as pageWidth / 2, then subtract half of your element’s width to position it.
Vertical Spacing: Establish a baseline grid. For example, if your certificate uses 36pt spacing between major elements, stick to multiples of 36 throughout (72pt, 108pt, 144pt). This creates visual harmony.
Symmetry: When adding borders or decorative elements, use the same margin on all sides, or use proportional margins (like golden ratio: 1.618:1).
Use Case 4: Reports with Dynamic Tables
Generating business reports with tables requires careful measurement planning, especially when data varies in length.
The Challenge:
You need to fit columns that contain varying amounts of text without breaking table alignment or causing text overlap.
Column Width Strategy:
The total content width on a standard A4 page with 1-inch margins is 451 points (595 - 72 - 72). If you’re creating a table with 5 columns, you might allocate:
- Column 1 (Item Name): 150 points (33%)
- Column 2 (Description): 100 points (22%)
- Column 3 (Quantity): 67 points (15%)
- Column 4 (Price): 67 points (15%)
- Column 5 (Total): 67 points (15%)
The percentages should add up to 100% of your content width, accounting for any gutters or padding between columns.
Advanced Measurement Concepts
Understanding Margins and Bleed
Margins are the empty space between the page edge and your content. Standard business documents typically use 1-inch (72pt) margins, but this varies by document type:
- Standard business: 72pt (1 inch)
- Academic papers: 72pt top/bottom, 90pt (1.25 inches) left/right
- Books: Asymmetric margins (inner margin larger for binding)
- Minimalist designs: 36-54pt (0.5-0.75 inches)
Bleed is extra content that extends beyond the trim line when documents are professionally printed. If you’re creating PDFs for commercial printing, you typically need:
- 9pt (1/8 inch) bleed on all sides
- This means a US Letter page becomes 630 x 810pt with bleed
The Typography Connection
Points originated in typography, and understanding this connection helps you make better design decisions in PDFKit.
Font Size in Points:
When you set font size to 12pt, you’re setting the em-square height, not the actual visible height of letters. The em-square is an invisible box that contains the tallest ascender and lowest descender of that typeface.
Leading (Line Height):
Leading (pronounced “ledding”) is the vertical space between lines of text. It’s measured from baseline to baseline. Optimal leading is typically 120-145% of the font size:
- 10pt font: 12-14.5pt leading
- 12pt font: 14.4-17.4pt leading
- 14pt font: 16.8-20.3pt leading
Tighter leading makes text feel denser and harder to read. Looser leading improves readability but consumes more vertical space.
Responsive PDF Design
While PDFs aren’t responsive like websites, you can design them to adapt to different page sizes programmatically.
The Concept:
Instead of hardcoding measurements, calculate them as percentages or ratios of the page dimensions. This allows the same layout logic to work across Letter, A4, Legal, or custom sizes.
Practical Application:
If you need a sidebar that’s 1/4 of the page width, calculate it as pageWidth * 0.25 rather than using a fixed 153pt. This ensures your layout scales proportionally regardless of paper size.
Common Pitfalls
Here are some practical examples of how to use measurements in PDFKit:
Setting Page Size
const PDFDocument = require('pdfkit');
// Create a new PDF document with A4 size
const doc = new PDFDocument({
size: [595, 842] // A4 in points
});
// Or use predefined sizes
const doc2 = new PDFDocument({
size: 'A4' // PDFKit handles the conversion
});
Positioning Elements
// Add text at specific coordinates (in points)
doc.text('Hello World', 72, 72); // 1 inch from left and top
// Draw a rectangle
doc.rect(72, 144, 144, 72) // x, y, width, height in points
.stroke();
// Add margins (1 inch = 72 points)
const margin = 72;
doc.text('Content with margins', margin, margin, {
width: doc.page.width - (margin * 2)
});
Working with Images
// Add an image with specific dimensions
doc.image('image.jpg', 72, 72, {
width: 216, // 3 inches in points
height: 144 // 2 inches in points
});
Tips for Working with PDFKit Measurements
- Always work in points when using PDFKit to avoid confusion
- Use the converter above to quickly convert from familiar units
- Remember common conversions: 72pt = 1in, 28.35pt ≈ 1cm
- Test your layouts with different page sizes to ensure consistency
- Use variables for common measurements to make your code more maintainable
const INCH = 72;
const CM = 28.35;
const MARGIN = INCH; // 1 inch margin
doc.text('Title', MARGIN, MARGIN);
doc.text('Content', MARGIN, MARGIN + (0.5 * INCH));
Common Pitfalls
- Don’t mix units: Stick to points throughout your PDFKit code
- Be aware of coordinate system: PDFKit uses top-left as origin (0,0)
- Consider DPI: When converting from pixels, remember that PDFKit assumes 72 DPI by default
- Page boundaries: Always check that your content fits within the page dimensions
Mistake 1: Forgetting About Page Margins
New developers often position content at (0, 0) thinking it’s at the page edge, but this puts content right at the trim line where printers might cut it off. Always add margins - even a small 36pt margin makes documents look more professional and ensures nothing gets trimmed during printing.
Mistake 2: Mixing Measurement Units in Calculations
One of the most subtle bugs happens when you mix units. For example, getting a width from a design tool in pixels, adding it to a margin value in points, and then wondering why your layout is off by several millimeters.
Always convert to points first, then do all calculations in points. Keep your source measurements in comments for reference.
Mistake 3: Not Accounting for Font Metrics
Setting font size to 12pt doesn’t mean your text takes exactly 12pt of vertical space. Descenders (the hanging parts of letters like ‘g’, ‘y’, ‘p’) extend below the baseline, and some fonts have taller ascenders than others.
When calculating vertical positioning, test with your actual font and content. A safe rule of thumb is to multiply font size by 1.4 to get approximate line height.
Mistake 4: Ignoring Safe Zones
Even with margins, not all space is equal. The corners and edges of documents often get less attention from readers. Important information should be in the “optical center” - slightly above the mathematical center of the page, typically around 45% from the top rather than 50%.
Mistake 5: Fixed Layouts for Variable Content
Designing with fixed Y-coordinates works until you have variable content. If you position a footer at Y=700, it looks great until you add more content that pushes past that point, causing overlap.
Instead, track your current Y position and increment it as you add content, or use PDFKit’s built-in flow capabilities.
Best Practices for Measurement in PDFKit
1. Establish a Measurement System Early
Before writing any code, decide on your measurement conventions. Create constants for common values:
- Standard margin size
- Line heights for different font sizes
- Spacing between sections
- Column widths
Consistency makes maintenance easier and prevents layout drift over time.
2. Think in Inches, Calculate in Points
Most people think in inches or centimeters because that’s how we measure physical objects. When planning layouts, sketch with familiar units, then convert to points for implementation. This mental separation prevents confusion.
3. Use the 72-Point Grid System
Since 72 is highly divisible, using multiples of small factors (like 6, 8, or 12) creates a harmonious grid. For example:
- 6pt base unit: Tiny spaces between related elements
- 12pt: Small vertical rhythm
- 24pt: Medium spacing
- 48pt: Large section breaks
- 72pt: Major divisions or margins
This system ensures visual consistency and makes calculations easier.
4. Test on Multiple Paper Sizes
If your application serves international users, test your layouts on both A4 and Letter sizes. What looks perfect on Letter might have awkward spacing on A4, or vice versa.
5. Consider Print vs Digital Viewing
PDFs viewed on screen behave differently than printed PDFs. Screen readers typically default to “fit width” viewing, while printed documents show actual size. Design for both contexts by ensuring your layouts work at both full size and when scaled to fit different page widths.
Conclusion
Understanding PDFKit’s point-based measurement system is essential for creating professional PDF documents. Use the converter tool above to quickly translate between units, and remember that 72 points equal 1 inch. This knowledge will help you create precisely positioned and properly sized PDF content in your Node.js applications.
With this foundation, you can confidently work with PDFKit to create everything from simple reports to complex document layouts with pixel-perfect precision.