first
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Membuat beberapa PDF contoh untuk validasi:
|
||||
* output/labels-01.pdf - 1 label (1 halaman)
|
||||
* output/labels-10.pdf - 10 label (1 halaman)
|
||||
* output/labels-13.pdf - 13 label (1 halaman)
|
||||
* output/labels-18.pdf - 18 label (1 halaman penuh, 3 x 6)
|
||||
* output/labels-25.pdf - 25 label (2 halaman)
|
||||
*
|
||||
* Jalankan: node scripts/generate-samples.js
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const LabelData = require('../src/data');
|
||||
const { writePdfFile } = require('../src/pdf');
|
||||
|
||||
function makeItems(count) {
|
||||
const lines = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const unique = '26-' + i.toString(16).toUpperCase().padStart(4, '0');
|
||||
lines.push('ONT-1910' + unique.replace('-', '') + ' | ' + (12345678 + i));
|
||||
}
|
||||
return LabelData.parseText(lines.join('\n'));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const outDir = path.resolve(__dirname, '..', 'output');
|
||||
const targets = [1, 10, 13, 18, 25];
|
||||
|
||||
for (const count of targets) {
|
||||
const items = makeItems(count);
|
||||
const name = 'labels-' + String(count).padStart(2, '0') + '.pdf';
|
||||
const out = path.join(outDir, name);
|
||||
const result = await writePdfFile({ items: items, out: out });
|
||||
process.stdout.write(
|
||||
name + ' ' +
|
||||
result.pageCount + ' halaman, ' + items.length + ' label, ' +
|
||||
'halaman ' + result.layout.page.widthMm + ' x ' + result.layout.page.heightMm + ' mm\n'
|
||||
);
|
||||
}
|
||||
|
||||
// Format 2 baris seperti pada gambar referensi (potongan roll 3 kolom x 2 baris).
|
||||
const stripItems = makeItems(8);
|
||||
const strip = await writePdfFile({
|
||||
items: stripItems,
|
||||
out: path.join(outDir, 'labels-strip-2-baris.pdf'),
|
||||
config: { pageHeightMm: 43.6, rows: 2, labelHeightMm: 0 }
|
||||
});
|
||||
process.stdout.write(
|
||||
'labels-strip-2-baris.pdf ' + strip.pageCount + ' halaman, ' + stripItems.length +
|
||||
' label, halaman ' + strip.layout.page.widthMm + ' x ' + strip.layout.page.heightMm + ' mm\n'
|
||||
);
|
||||
}
|
||||
|
||||
main().catch(function (err) {
|
||||
process.stderr.write('Error: ' + err.message + '\n');
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user