Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ragaeeb/kokokor/llms.txt

Use this file to discover all available pages before exploring further.

Function Signature

calculateDPI(imageSize: Size, pdfSize: Size): { x: number; y: number }

Parameters

imageSize
Size
required
Dimensions of the rasterized image in pixels
width
number
required
Width in pixels
height
number
required
Height in pixels
pdfSize
Size
required
Original dimensions of the PDF page in points (1/72 inch)
width
number
required
Width in points
height
number
required
Height in points

Returns

Object containing x and y DPI values
x
number
Horizontal DPI (dots per inch)
y
number
Vertical DPI (dots per inch)

Description

Calculates the DPI (dots per inch) based on image dimensions and original PDF size. This utility function helps determine the resolution at which a PDF was rasterized by comparing the resulting image dimensions with the original PDF page dimensions. The DPI values are essential for proper scaling of pixel-based tolerances and measurements throughout the document processing pipeline.

Usage Example

import { calculateDPI } from 'kokokor';

// A4 page dimensions
const imageSize = { width: 2480, height: 3508 };
const pdfSize = { width: 595, height: 842 }; // A4 page in points

const dpi = calculateDPI(imageSize, pdfSize);
console.log(`DPI: ${dpi.x} x ${dpi.y}`);
// Result: DPI: 300 x 300 for a 300 DPI scan

// Use DPI for scaling tolerances
const pixelTolerance = 5;
const scaledTolerance = pixelTolerance * (dpi.x / 72);