pdfnative 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/index.cjs +39 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -19
- package/dist/index.js.map +1 -1
- package/dist/worker/index.cjs +232 -12
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.js +232 -12
- package/dist/worker/index.js.map +1 -1
- package/package.json +2 -1
package/dist/worker/index.cjs
CHANGED
|
@@ -2393,9 +2393,26 @@ function buildStructureTree(root, startObjNum, pageObjToStructParents) {
|
|
|
2393
2393
|
totalObjects: nextObj - startObjNum
|
|
2394
2394
|
};
|
|
2395
2395
|
}
|
|
2396
|
-
function
|
|
2396
|
+
function buildPdfMetadata(now = /* @__PURE__ */ new Date()) {
|
|
2397
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
2398
|
+
const yyyy = now.getFullYear();
|
|
2399
|
+
const mm = pad2(now.getMonth() + 1);
|
|
2400
|
+
const dd = pad2(now.getDate());
|
|
2401
|
+
const hh = pad2(now.getHours());
|
|
2402
|
+
const mi = pad2(now.getMinutes());
|
|
2403
|
+
const ss = pad2(now.getSeconds());
|
|
2404
|
+
const tzMinutes = -now.getTimezoneOffset();
|
|
2405
|
+
const tzSign = tzMinutes >= 0 ? "+" : "-";
|
|
2406
|
+
const tzAbs = Math.abs(tzMinutes);
|
|
2407
|
+
const tzH = pad2(Math.floor(tzAbs / 60));
|
|
2408
|
+
const tzM = pad2(tzAbs % 60);
|
|
2409
|
+
const pdfDate = `D:${yyyy}${mm}${dd}${hh}${mi}${ss}${tzSign}${tzH}'${tzM}'`;
|
|
2410
|
+
const xmpDate = `${yyyy}-${mm}-${dd}T${hh}:${mi}:${ss}${tzSign}${tzH}:${tzM}`;
|
|
2411
|
+
return { pdfDate, xmpDate };
|
|
2412
|
+
}
|
|
2413
|
+
function buildXMPMetadata(title, createDate, pdfaPart = 2, pdfaConformance = "B", author) {
|
|
2397
2414
|
const escapedTitle = escapeXml(title);
|
|
2398
|
-
|
|
2415
|
+
const lines = [
|
|
2399
2416
|
'<?xpacket begin="\xEF\xBB\xBF" id="W5M0MpCehiHzreSzNTczkc9d"?>',
|
|
2400
2417
|
'<x:xmpmeta xmlns:x="adobe:ns:meta/">',
|
|
2401
2418
|
' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">',
|
|
@@ -2404,17 +2421,21 @@ function buildXMPMetadata(title, createDate, pdfaPart = 2, pdfaConformance = "B"
|
|
|
2404
2421
|
' xmlns:pdf="http://ns.adobe.com/pdf/1.3/"',
|
|
2405
2422
|
' xmlns:xmp="http://ns.adobe.com/xap/1.0/"',
|
|
2406
2423
|
' xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">',
|
|
2407
|
-
` <dc:title><rdf:Alt><rdf:li xml:lang="x-default">${escapedTitle}</rdf:li></rdf:Alt></dc:title
|
|
2408
|
-
|
|
2424
|
+
` <dc:title><rdf:Alt><rdf:li xml:lang="x-default">${escapedTitle}</rdf:li></rdf:Alt></dc:title>`
|
|
2425
|
+
];
|
|
2426
|
+
lines.push(
|
|
2409
2427
|
" <pdf:Producer>pdfnative</pdf:Producer>",
|
|
2410
2428
|
` <xmp:CreateDate>${createDate}</xmp:CreateDate>`,
|
|
2429
|
+
` <xmp:ModifyDate>${createDate}</xmp:ModifyDate>`,
|
|
2430
|
+
` <xmp:MetadataDate>${createDate}</xmp:MetadataDate>`,
|
|
2411
2431
|
` <pdfaid:part>${pdfaPart}</pdfaid:part>`,
|
|
2412
2432
|
` <pdfaid:conformance>${pdfaConformance}</pdfaid:conformance>`,
|
|
2413
2433
|
" </rdf:Description>",
|
|
2414
2434
|
" </rdf:RDF>",
|
|
2415
2435
|
"</x:xmpmeta>",
|
|
2416
2436
|
'<?xpacket end="w"?>'
|
|
2417
|
-
|
|
2437
|
+
);
|
|
2438
|
+
return lines.join("\n");
|
|
2418
2439
|
}
|
|
2419
2440
|
function buildOutputIntentDict(iccStreamObjNum, subtype = "GTS_PDFA1") {
|
|
2420
2441
|
return `<< /Type /OutputIntent /S /${subtype} /OutputConditionIdentifier (sRGB IEC61966-2.1) /RegistryName (http://www.color.org) /DestOutputProfile ${iccStreamObjNum} 0 R >>`;
|
|
@@ -2744,6 +2765,205 @@ function parsePdfRgbString(str) {
|
|
|
2744
2765
|
}
|
|
2745
2766
|
return str;
|
|
2746
2767
|
}
|
|
2768
|
+
var MD5_S = [
|
|
2769
|
+
7,
|
|
2770
|
+
12,
|
|
2771
|
+
17,
|
|
2772
|
+
22,
|
|
2773
|
+
7,
|
|
2774
|
+
12,
|
|
2775
|
+
17,
|
|
2776
|
+
22,
|
|
2777
|
+
7,
|
|
2778
|
+
12,
|
|
2779
|
+
17,
|
|
2780
|
+
22,
|
|
2781
|
+
7,
|
|
2782
|
+
12,
|
|
2783
|
+
17,
|
|
2784
|
+
22,
|
|
2785
|
+
5,
|
|
2786
|
+
9,
|
|
2787
|
+
14,
|
|
2788
|
+
20,
|
|
2789
|
+
5,
|
|
2790
|
+
9,
|
|
2791
|
+
14,
|
|
2792
|
+
20,
|
|
2793
|
+
5,
|
|
2794
|
+
9,
|
|
2795
|
+
14,
|
|
2796
|
+
20,
|
|
2797
|
+
5,
|
|
2798
|
+
9,
|
|
2799
|
+
14,
|
|
2800
|
+
20,
|
|
2801
|
+
4,
|
|
2802
|
+
11,
|
|
2803
|
+
16,
|
|
2804
|
+
23,
|
|
2805
|
+
4,
|
|
2806
|
+
11,
|
|
2807
|
+
16,
|
|
2808
|
+
23,
|
|
2809
|
+
4,
|
|
2810
|
+
11,
|
|
2811
|
+
16,
|
|
2812
|
+
23,
|
|
2813
|
+
4,
|
|
2814
|
+
11,
|
|
2815
|
+
16,
|
|
2816
|
+
23,
|
|
2817
|
+
6,
|
|
2818
|
+
10,
|
|
2819
|
+
15,
|
|
2820
|
+
21,
|
|
2821
|
+
6,
|
|
2822
|
+
10,
|
|
2823
|
+
15,
|
|
2824
|
+
21,
|
|
2825
|
+
6,
|
|
2826
|
+
10,
|
|
2827
|
+
15,
|
|
2828
|
+
21,
|
|
2829
|
+
6,
|
|
2830
|
+
10,
|
|
2831
|
+
15,
|
|
2832
|
+
21
|
|
2833
|
+
];
|
|
2834
|
+
var MD5_K = new Uint32Array([
|
|
2835
|
+
3614090360,
|
|
2836
|
+
3905402710,
|
|
2837
|
+
606105819,
|
|
2838
|
+
3250441966,
|
|
2839
|
+
4118548399,
|
|
2840
|
+
1200080426,
|
|
2841
|
+
2821735955,
|
|
2842
|
+
4249261313,
|
|
2843
|
+
1770035416,
|
|
2844
|
+
2336552879,
|
|
2845
|
+
4294925233,
|
|
2846
|
+
2304563134,
|
|
2847
|
+
1804603682,
|
|
2848
|
+
4254626195,
|
|
2849
|
+
2792965006,
|
|
2850
|
+
1236535329,
|
|
2851
|
+
4129170786,
|
|
2852
|
+
3225465664,
|
|
2853
|
+
643717713,
|
|
2854
|
+
3921069994,
|
|
2855
|
+
3593408605,
|
|
2856
|
+
38016083,
|
|
2857
|
+
3634488961,
|
|
2858
|
+
3889429448,
|
|
2859
|
+
568446438,
|
|
2860
|
+
3275163606,
|
|
2861
|
+
4107603335,
|
|
2862
|
+
1163531501,
|
|
2863
|
+
2850285829,
|
|
2864
|
+
4243563512,
|
|
2865
|
+
1735328473,
|
|
2866
|
+
2368359562,
|
|
2867
|
+
4294588738,
|
|
2868
|
+
2272392833,
|
|
2869
|
+
1839030562,
|
|
2870
|
+
4259657740,
|
|
2871
|
+
2763975236,
|
|
2872
|
+
1272893353,
|
|
2873
|
+
4139469664,
|
|
2874
|
+
3200236656,
|
|
2875
|
+
681279174,
|
|
2876
|
+
3936430074,
|
|
2877
|
+
3572445317,
|
|
2878
|
+
76029189,
|
|
2879
|
+
3654602809,
|
|
2880
|
+
3873151461,
|
|
2881
|
+
530742520,
|
|
2882
|
+
3299628645,
|
|
2883
|
+
4096336452,
|
|
2884
|
+
1126891415,
|
|
2885
|
+
2878612391,
|
|
2886
|
+
4237533241,
|
|
2887
|
+
1700485571,
|
|
2888
|
+
2399980690,
|
|
2889
|
+
4293915773,
|
|
2890
|
+
2240044497,
|
|
2891
|
+
1873313359,
|
|
2892
|
+
4264355552,
|
|
2893
|
+
2734768916,
|
|
2894
|
+
1309151649,
|
|
2895
|
+
4149444226,
|
|
2896
|
+
3174756917,
|
|
2897
|
+
718787259,
|
|
2898
|
+
3951481745
|
|
2899
|
+
]);
|
|
2900
|
+
function rotl32(x, n) {
|
|
2901
|
+
return (x << n | x >>> 32 - n) >>> 0;
|
|
2902
|
+
}
|
|
2903
|
+
function md5(input) {
|
|
2904
|
+
const len = input.length;
|
|
2905
|
+
const totalBits = len * 8;
|
|
2906
|
+
const padLen = (56 - (len + 1) % 64 + 64) % 64;
|
|
2907
|
+
const padded = new Uint8Array(len + 1 + padLen + 8);
|
|
2908
|
+
padded.set(input);
|
|
2909
|
+
padded[len] = 128;
|
|
2910
|
+
const dv = new DataView(padded.buffer);
|
|
2911
|
+
dv.setUint32(padded.length - 8, totalBits >>> 0, true);
|
|
2912
|
+
dv.setUint32(padded.length - 4, 0, true);
|
|
2913
|
+
let a0 = 1732584193 >>> 0;
|
|
2914
|
+
let b0 = 4023233417 >>> 0;
|
|
2915
|
+
let c0 = 2562383102 >>> 0;
|
|
2916
|
+
let d0 = 271733878 >>> 0;
|
|
2917
|
+
for (let off = 0; off < padded.length; off += 64) {
|
|
2918
|
+
const M = new Uint32Array(16);
|
|
2919
|
+
for (let j = 0; j < 16; j++) {
|
|
2920
|
+
M[j] = dv.getUint32(off + j * 4, true);
|
|
2921
|
+
}
|
|
2922
|
+
let a = a0, b = b0, c = c0, d = d0;
|
|
2923
|
+
for (let i = 0; i < 64; i++) {
|
|
2924
|
+
let f, g;
|
|
2925
|
+
if (i < 16) {
|
|
2926
|
+
f = b & c | ~b & d;
|
|
2927
|
+
g = i;
|
|
2928
|
+
} else if (i < 32) {
|
|
2929
|
+
f = d & b | ~d & c;
|
|
2930
|
+
g = (5 * i + 1) % 16;
|
|
2931
|
+
} else if (i < 48) {
|
|
2932
|
+
f = b ^ c ^ d;
|
|
2933
|
+
g = (3 * i + 5) % 16;
|
|
2934
|
+
} else {
|
|
2935
|
+
f = c ^ (b | ~d);
|
|
2936
|
+
g = 7 * i % 16;
|
|
2937
|
+
}
|
|
2938
|
+
f = f >>> 0;
|
|
2939
|
+
const temp = d;
|
|
2940
|
+
d = c;
|
|
2941
|
+
c = b;
|
|
2942
|
+
b = b + rotl32(a + f + MD5_K[i] + M[g] >>> 0, MD5_S[i]) >>> 0;
|
|
2943
|
+
a = temp;
|
|
2944
|
+
}
|
|
2945
|
+
a0 = a0 + a >>> 0;
|
|
2946
|
+
b0 = b0 + b >>> 0;
|
|
2947
|
+
c0 = c0 + c >>> 0;
|
|
2948
|
+
d0 = d0 + d >>> 0;
|
|
2949
|
+
}
|
|
2950
|
+
const result = new Uint8Array(16);
|
|
2951
|
+
const rv = new DataView(result.buffer);
|
|
2952
|
+
rv.setUint32(0, a0, true);
|
|
2953
|
+
rv.setUint32(4, b0, true);
|
|
2954
|
+
rv.setUint32(8, c0, true);
|
|
2955
|
+
rv.setUint32(12, d0, true);
|
|
2956
|
+
return result;
|
|
2957
|
+
}
|
|
2958
|
+
function hexStr(bytes) {
|
|
2959
|
+
let h = "";
|
|
2960
|
+
for (let i = 0; i < bytes.length; i++) h += bytes[i].toString(16).padStart(2, "0");
|
|
2961
|
+
return h.toUpperCase();
|
|
2962
|
+
}
|
|
2963
|
+
function buildIdArray(docId) {
|
|
2964
|
+
const h = hexStr(docId);
|
|
2965
|
+
return `[<${h}> <${h}>]`;
|
|
2966
|
+
}
|
|
2747
2967
|
|
|
2748
2968
|
// src/core/pdf-assembler.ts
|
|
2749
2969
|
function createPdfWriter(compress, encState) {
|
|
@@ -2776,7 +2996,7 @@ endstream`);
|
|
|
2776
2996
|
_offset += d;
|
|
2777
2997
|
}, objOffsets, parts };
|
|
2778
2998
|
}
|
|
2779
|
-
function writeXrefTrailer(w, totalObjs, infoObjNum, encState) {
|
|
2999
|
+
function writeXrefTrailer(w, totalObjs, infoObjNum, encState, idSeed = "") {
|
|
2780
3000
|
const xrefOffset = w.offset();
|
|
2781
3001
|
w.emit("xref\n");
|
|
2782
3002
|
w.emit(`0 ${totalObjs + 1}
|
|
@@ -2788,8 +3008,10 @@ function writeXrefTrailer(w, totalObjs, infoObjNum, encState) {
|
|
|
2788
3008
|
`);
|
|
2789
3009
|
}
|
|
2790
3010
|
w.emit("trailer\n");
|
|
3011
|
+
const docId = md5(new TextEncoder().encode(`pdfnative|${idSeed}|${totalObjs}`));
|
|
3012
|
+
const idArray = buildIdArray(docId);
|
|
2791
3013
|
{
|
|
2792
|
-
w.emit(`<< /Size ${totalObjs + 1} /Root 1 0 R /Info ${infoObjNum} 0 R >>
|
|
3014
|
+
w.emit(`<< /Size ${totalObjs + 1} /Root 1 0 R /Info ${infoObjNum} 0 R /ID ${idArray} >>
|
|
2793
3015
|
`);
|
|
2794
3016
|
}
|
|
2795
3017
|
w.emit("startxref\n");
|
|
@@ -2960,6 +3182,7 @@ function buildPDF(params, layoutOptions) {
|
|
|
2960
3182
|
if (totalPages < 1) totalPages = 1;
|
|
2961
3183
|
const pdfaConfig = resolvePdfAConfig();
|
|
2962
3184
|
const tagged = pdfaConfig.enabled;
|
|
3185
|
+
const encState = null;
|
|
2963
3186
|
const wmExtraObjs = 0;
|
|
2964
3187
|
const mcidAlloc = tagged ? createMCIDAllocator() : void 0;
|
|
2965
3188
|
const documentChildren = [];
|
|
@@ -3164,10 +3387,7 @@ function buildPDF(params, layoutOptions) {
|
|
|
3164
3387
|
}
|
|
3165
3388
|
const baseObjCount = enc.isUnicode ? 4 + fontEntries.length * 5 + wmExtraObjs + totalPages * 2 : 4 + wmExtraObjs + totalPages * 2;
|
|
3166
3389
|
const infoObjNum = baseObjCount + 1;
|
|
3167
|
-
const
|
|
3168
|
-
const pad2 = (n) => String(n).padStart(2, "0");
|
|
3169
|
-
const pdfDate = `D:${now.getFullYear()}${pad2(now.getMonth() + 1)}${pad2(now.getDate())}${pad2(now.getHours())}${pad2(now.getMinutes())}${pad2(now.getSeconds())}`;
|
|
3170
|
-
const isoDate = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}T${pad2(now.getHours())}:${pad2(now.getMinutes())}:${pad2(now.getSeconds())}`;
|
|
3390
|
+
const { pdfDate, xmpDate: isoDate } = buildPdfMetadata();
|
|
3171
3391
|
const infoTitle = params.docTitle || title || "";
|
|
3172
3392
|
emitObj(
|
|
3173
3393
|
infoObjNum,
|
|
@@ -3228,7 +3448,7 @@ endobj
|
|
|
3228
3448
|
}
|
|
3229
3449
|
}
|
|
3230
3450
|
const writer = { emit, emitObj, emitStreamObj, offset: getOffset, adjustOffset, objOffsets, parts };
|
|
3231
|
-
writeXrefTrailer(writer, totalObjs, infoObjNum);
|
|
3451
|
+
writeXrefTrailer(writer, totalObjs, infoObjNum, encState, `${infoTitle}|${pdfDate}`);
|
|
3232
3452
|
return parts.join("");
|
|
3233
3453
|
}
|
|
3234
3454
|
|