()
| 11 | import { formatBytes, loadFixture } from "../utils"; |
| 12 | |
| 13 | async function main() { |
| 14 | // Load a PDF from the fixtures directory |
| 15 | console.log("Loading PDF...\n"); |
| 16 | const bytes = await loadFixture("basic", "rot0.pdf"); |
| 17 | const pdf = await PDF.load(bytes); |
| 18 | |
| 19 | // Print basic document info |
| 20 | console.log("=== Document Properties ==="); |
| 21 | console.log(`PDF Version: ${pdf.version}`); |
| 22 | console.log(`File Size: ${formatBytes(bytes.length)}`); |
| 23 | console.log(`Page Count: ${pdf.getPageCount()}`); |
| 24 | console.log(`Encrypted: ${pdf.isEncrypted ? "Yes" : "No"}`); |
| 25 | console.log(`Linearized: ${pdf.isLinearized ? "Yes" : "No"}`); |
| 26 | console.log(`Uses XRef Streams: ${pdf.usesXRefStreams ? "Yes" : "No"}`); |
| 27 | |
| 28 | // Check for any parsing warnings |
| 29 | if (pdf.warnings.length > 0) { |
| 30 | console.log(`\nWarnings: ${pdf.warnings.length}`); |
| 31 | for (const warning of pdf.warnings) { |
| 32 | console.log(` - ${warning}`); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // Iterate through pages and show dimensions |
| 37 | console.log("\n=== Page Information ==="); |
| 38 | const pages = pdf.getPages(); |
| 39 | |
| 40 | for (let i = 0; i < pages.length; i++) { |
| 41 | const page = pages[i]; |
| 42 | if (!page) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | console.log(`\nPage ${i + 1}:`); |
| 47 | console.log(` Size: ${page.width.toFixed(2)} x ${page.height.toFixed(2)} points`); |
| 48 | console.log( |
| 49 | ` Size (inches): ${(page.width / 72).toFixed(2)} x ${(page.height / 72).toFixed(2)}`, |
| 50 | ); |
| 51 | console.log(` Rotation: ${page.rotation} degrees`); |
| 52 | console.log(` Orientation: ${page.isLandscape ? "Landscape" : "Portrait"}`); |
| 53 | |
| 54 | // Show page boxes (using x1/y1/x2/y2 coordinates) |
| 55 | const mediaBox = page.getMediaBox(); |
| 56 | const cropBox = page.getCropBox(); |
| 57 | |
| 58 | const mediaX2 = mediaBox.x + mediaBox.width; |
| 59 | const mediaY2 = mediaBox.y + mediaBox.height; |
| 60 | |
| 61 | console.log( |
| 62 | ` Media Box: [${mediaBox.x}, ${mediaBox.y}, ${mediaX2}, ${mediaY2}] (${mediaBox.width} x ${mediaBox.height})`, |
| 63 | ); |
| 64 | |
| 65 | // Show crop box if different from media box |
| 66 | if ( |
| 67 | cropBox.x !== mediaBox.x || |
| 68 | cropBox.y !== mediaBox.y || |
| 69 | cropBox.width !== mediaBox.width || |
| 70 | cropBox.height !== mediaBox.height |
no test coverage detected