53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { PDFDocument } from "pdf-lib";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createPdf } from "../../src/labels/pdf";
|
|
import { renderLabelPages } from "../../src/labels/render";
|
|
import { STOCKS } from "../../src/labels/stocks";
|
|
import type { RenderOptions } from "../../src/labels/types";
|
|
|
|
describe("vector PDF export", () => {
|
|
it("keeps the physical page geometry and emits vector page operators", async () => {
|
|
const stock = STOCKS[0]!;
|
|
const options: RenderOptions = {
|
|
stock,
|
|
calibration: { offsetXmm: 0, offsetYmm: 0, scaleX: 1, scaleY: 1 },
|
|
layout: "address",
|
|
mapping: {
|
|
title: "name",
|
|
subtitle: "subtitle",
|
|
body: "body",
|
|
barcode: "code",
|
|
image: "image",
|
|
},
|
|
barcodeFormat: "qrcode",
|
|
includeBarcodeText: false,
|
|
fontFamily: "Arial, Helvetica, sans-serif",
|
|
records: [
|
|
{
|
|
name: "Vector label",
|
|
subtitle: "Local",
|
|
body: "Physical units",
|
|
code: "SAFE-1",
|
|
},
|
|
],
|
|
images: [],
|
|
defaultImage: "",
|
|
cutMarks: true,
|
|
registrationMarks: true,
|
|
startPosition: 0,
|
|
};
|
|
const blob = await createPdf(renderLabelPages(options), stock);
|
|
expect(blob.type).toBe("application/pdf");
|
|
const document = await PDFDocument.load(await blob.arrayBuffer());
|
|
expect(document.getPageCount()).toBe(1);
|
|
expect(document.getPage(0).getWidth()).toBeCloseTo(
|
|
(stock.pageWidthMm * 72) / 25.4,
|
|
4,
|
|
);
|
|
expect(document.getPage(0).getHeight()).toBeCloseTo(
|
|
(stock.pageHeightMm * 72) / 25.4,
|
|
4,
|
|
);
|
|
});
|
|
});
|