Files
PM_test/scratch_inspect_hwp.js
2026-06-19 17:58:47 +09:00

48 lines
2.3 KiB
JavaScript

const fs = require('fs');
const hwp = require('./libs/hwp.js');
function run() {
console.log("Parsing downloaded_test.hwpx...");
try {
const fileBuffer = fs.readFileSync('downloaded_test.hwpx');
const doc = hwp.parse(fileBuffer, { type: 'buffer' });
console.log("\nDocument parsed successfully.");
console.log(`Number of sections: ${doc.sections.length}`);
doc.sections.forEach((section, sIdx) => {
console.log(`\nSection ${sIdx}:`);
console.log(` Page width: ${section.width} (${section.width / 7200} in)`);
console.log(` Page height: ${section.height} (${section.height / 7200} in)`);
console.log(` PaddingTop: ${section.paddingTop}`);
console.log(` HeaderPadding: ${section.headerPadding}`);
console.log(` PaddingLeft: ${section.paddingLeft}`);
let shapeCount = 0;
section.content.forEach((para, pIdx) => {
para.controls.forEach((ctrl, cIdx) => {
// Check if it's a shape (Rectangle, Ellipse, Line, etc.)
// Check properties
const isShape = ctrl.type !== 1347570004; // Not table
if (isShape) {
shapeCount++;
console.log(`\n --- Shape #${shapeCount} inside Paragraph ${pIdx} ---`);
console.log(` Control ID: ${ctrl.id} / Type: ${ctrl.type}`);
console.log(` Width: ${ctrl.width} (${ctrl.width / 100} pt)`);
console.log(` Height: ${ctrl.height} (${ctrl.height / 100} pt)`);
console.log(` vertRelTo: ${ctrl.attribute ? ctrl.attribute.vertRelTo : 'N/A'}`);
console.log(` verticalOffset: ${ctrl.verticalOffset} (${ctrl.verticalOffset / 100} pt)`);
console.log(` horizontalOffset: ${ctrl.horizontalOffset} (${ctrl.horizontalOffset / 100} pt)`);
console.log(` zIndex: ${ctrl.zIndex}`);
}
});
});
console.log(`\nTotal shapes in section ${sIdx}: ${shapeCount}`);
});
} catch (err) {
console.error("Error parsing HWP:", err);
}
}
run();