Skip to content

Commit cc819eb

Browse files
falworks-dyFAL
andauthored
入出力形式単純化: WOFF系フォントの入力およびBase64形式の入出力をオミット (#11)
* style: code formatting * chore: bypass wrong type declaration of UPNG * test: readFile系の関数をwrapperで置き換え(Buffer - Uint8Array 非互換の回避のため) * build: TypeScript バージョン最新化 * build: rollup バージョン最新化 * build: TypeScript 3.4 のサポートをオミット * chore: upgrade devDependencies (prettier, rimraf, http-server) * chore: remove unused node-fetch from devDependencies * build: update target es2020 -> es2022 * build: fontkit を v2.0.4-mod.2025.3 に更新 * fix!: PDFDocument の各種メソッドでBase64形式の入力受付をオミット * fix!: PDFDocument の saveAsBase64 メソッドをオミット * chore: 不要になったBase64系のテストデータを削除 * docs: update changelog * build: fontkit を v2.0.4-mod.2025.4 に更新 --------- Co-authored-by: FAL <contact@fal-works.com>
1 parent 8aa6bb6 commit cc819eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1695
-2833
lines changed

.github/workflows/npm-publish-github-packages.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
cjs/
3131
es/
3232
umd/
33-
ts3.4/
3433
3534
publish-gpr:
3635
needs: build

MODIFICATIONS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Modifications
22

3+
## [Unreleased]
4+
5+
### Feature Removals
6+
7+
- Remove WOFF/WOFF2/DFont support from `PDFDocument#embedFont` by updating `@denkiyagi/fontkit` to `2.0.4-mod.2025.4`;
8+
only `*.ttf` and `*.otf` font formats are now supported.
9+
- Remove Base64 string/dataURI inputs across `PDFDocument` loading, embedding, and attachments;
10+
binary data must now be provided as `Uint8Array` or `ArrayBuffer`.
11+
- Remove Base64 output by removing the `PDFDocument#saveAsBase64` method;
12+
use `PDFDocument#save` which resolves a `Uint8Array` instead.
13+
14+
### Internal Changes
15+
16+
- Update several devDependencies including `typescript` to their latest versions.
17+
318
## [1.17.1-mod.2025.7]
419

520
- Add `PDFDocument#embedTTFFont` (subset-only) and `CustomFontSubsetEmbedder.forTTFFont` so pre-created fontkit `TTFFont` instances can be embedded.

apps/node/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const assets = {
7272
fonts: {
7373
ttf: {
7474
ubuntu_r: readFont('ubuntu/Ubuntu-R.ttf'),
75-
ubuntu_r_base64: String(readFont('ubuntu/Ubuntu-R.ttf.base64')),
7675
bio_rhyme_r: readFont('bio_rhyme/BioRhymeExpanded-Regular.ttf'),
7776
press_start_2p_r: readFont('press_start_2p/PressStart2P-Regular.ttf'),
7877
indie_flower_r: readFont('indie_flower/IndieFlower.ttf'),
@@ -91,17 +90,11 @@ const assets = {
9190
images: {
9291
jpg: {
9392
cat_riding_unicorn: readImage('cat_riding_unicorn.jpg'),
94-
cat_riding_unicorn_base64: String(
95-
readImage('cat_riding_unicorn.jpg.base64'),
96-
),
9793
minions_laughing: readImage('minions_laughing.jpg'),
9894
cmyk_colorspace: readImage('cmyk_colorspace.jpg'),
9995
},
10096
png: {
10197
greyscale_bird: readImage('greyscale_bird.png'),
102-
greyscale_bird_base64_uri: String(
103-
readImage('greyscale_bird.png.base64.uri'),
104-
),
10598
minions_banana_alpha: readImage('minions_banana_alpha.png'),
10699
minions_banana_no_alpha: readImage('minions_banana_no_alpha.png'),
107100
small_mario: readImage('small_mario.png'),
@@ -112,11 +105,7 @@ const assets = {
112105
},
113106
pdfs: {
114107
normal: readPdf('normal.pdf'),
115-
normal_base64: String(readPdf('normal.pdf.base64')),
116108
with_update_sections: readPdf('with_update_sections.pdf'),
117-
with_update_sections_base64_uri: String(
118-
readPdf('with_update_sections.pdf.base64.uri'),
119-
),
120109
linearized_with_object_streams: readPdf(
121110
'linearized_with_object_streams.pdf',
122111
),

apps/node/tests/test1.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export default async (assets: Assets) => {
233233

234234
const { fonts } = assets;
235235

236-
const ubuntuFont = await pdfDoc.embedFont(fonts.ttf.ubuntu_r_base64, {
236+
const ubuntuFont = await pdfDoc.embedFont(fonts.ttf.ubuntu_r, {
237237
subset: true,
238238
});
239239
page2.drawText(ipsumLines.join('\n'), {
@@ -318,13 +318,9 @@ export default async (assets: Assets) => {
318318

319319
const { jpg, png } = assets.images;
320320

321-
const catRidingUnicornImage = await pdfDoc.embedJpg(
322-
jpg.cat_riding_unicorn_base64,
323-
);
321+
const catRidingUnicornImage = await pdfDoc.embedJpg(jpg.cat_riding_unicorn);
324322
const minionsLaughingImage = await pdfDoc.embedJpg(jpg.minions_laughing);
325-
const greyscaleBirdImage = await pdfDoc.embedPng(
326-
png.greyscale_bird_base64_uri,
327-
);
323+
const greyscaleBirdImage = await pdfDoc.embedPng(png.greyscale_bird);
328324
const minionsBananaAlphaImage = await pdfDoc.embedPng(
329325
png.minions_banana_alpha,
330326
);

apps/node/tests/test3.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111
export default async (assets: Assets) => {
1212
const { pdfs, images } = assets;
1313

14-
const pdfDoc = await PDFDocument.load(pdfs.with_update_sections_base64_uri, {
14+
const pdfDoc = await PDFDocument.load(pdfs.with_update_sections, {
1515
parseSpeed: ParseSpeeds.Fastest,
1616
updateMetadata: false,
1717
});
1818

19-
await pdfDoc.attach(pdfs.normal_base64, 'tax_form.pdf', {
19+
await pdfDoc.attach(pdfs.normal, 'tax_form.pdf', {
2020
mimeType: 'application/pdf',
2121
description: 'D-2210 tax form for 2012 🏦',
2222
creationDate: new Date('2004/04/04'),
@@ -120,9 +120,5 @@ export default async (assets: Assets) => {
120120
console.log('Creation Date:', pdfDoc.getCreationDate());
121121
console.log('Modification Date:', pdfDoc.getModificationDate());
122122

123-
const base64Pdf = await pdfDoc.saveAsBase64();
124-
125-
const pdfBytes = Buffer.from(base64Pdf, 'base64');
126-
127-
return pdfBytes;
123+
return pdfDoc.save();
128124
};

apps/node/tests/test4.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
export default async (assets: Assets) => {
1313
const { pdfs, images } = assets;
1414

15-
const pdfDoc = await PDFDocument.load(pdfs.normal_base64, {
15+
const pdfDoc = await PDFDocument.load(pdfs.normal, {
1616
parseSpeed: ParseSpeeds.Fastest,
1717
});
1818

apps/node/tests/test6.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ export default async (assets: Assets) => {
1616
modificationDate: new Date('1992/05/07'),
1717
});
1818

19-
await pdfDoc.attach(
20-
images.jpg.cat_riding_unicorn_base64,
21-
'cat_riding_unicorn.jpg',
22-
{
23-
mimeType: 'image/jpeg',
24-
description: 'Cool cat riding a unicorn! 🦄🐈🕶️',
25-
creationDate: new Date('2019/12/01'),
26-
modificationDate: new Date('2020/04/19'),
27-
},
28-
);
19+
await pdfDoc.attach(images.jpg.cat_riding_unicorn, 'cat_riding_unicorn.jpg', {
20+
mimeType: 'image/jpeg',
21+
description: 'Cool cat riding a unicorn! 🦄🐈🕶️',
22+
creationDate: new Date('2019/12/01'),
23+
modificationDate: new Date('2020/04/19'),
24+
});
2925

3026
const nunitoLigaFont = await pdfDoc.embedFont(fonts.ttf.nunito, {
3127
subset: true,

apps/node/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
/* Basic Options */
4-
"target": "es2020",
4+
"target": "es2022",
55
"module": "commonjs",
66
"composite": false,
77
"incremental": true,

apps/web/test1.html

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
const fetchBinaryAsset = (asset) =>
3737
fetch(`/assets/${asset}`).then((res) => res.arrayBuffer());
3838

39-
const fetchStringAsset = (asset) =>
40-
fetch(`/assets/${asset}`).then((res) => res.text());
41-
4239
const renderInIframe = (pdfBytes) => {
4340
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
4441
const blobUrl = URL.createObjectURL(blob);
@@ -285,7 +282,7 @@
285282
page2.setFontColor(rgb(101 / 255, 123 / 255, 131 / 255));
286283

287284
const [
288-
ubuntuBase64,
285+
ubuntuBytes,
289286
fantasqueBytes,
290287
indieFlowerBytes,
291288
greatVibesBytes,
@@ -294,7 +291,7 @@
294291
pressStart2PBytes,
295292
hussar3DBytes,
296293
] = await Promise.all([
297-
fetchStringAsset('fonts/ubuntu/Ubuntu-R.ttf.base64'),
294+
fetchBinaryAsset('fonts/ubuntu/Ubuntu-R.ttf'),
298295
fetchBinaryAsset(
299296
'fonts/fantasque/OTF/FantasqueSansMono-BoldItalic.otf',
300297
),
@@ -306,7 +303,7 @@
306303
fetchBinaryAsset('fonts/hussar_3d/Hussar3DFour.otf'),
307304
]);
308305

309-
const ubuntuFont = await pdfDoc.embedFont(ubuntuBase64, { subset: true });
306+
const ubuntuFont = await pdfDoc.embedFont(ubuntuBytes, { subset: true });
310307
page2.drawText(ipsumLines.join('\n'), {
311308
y: size - 20,
312309
size: 20,
@@ -386,26 +383,26 @@
386383
const page3 = pdfDoc.addPage([size, page3Height]);
387384

388385
const [
389-
catRidingUnicornBase64,
386+
catRidingUnicornBytes,
390387
minionsLaughingBytes,
391-
greyscaleBirdBase64,
388+
greyscaleBirdBytes,
392389
minionsBananaAlphaBytes,
393390
minionsBananaNoAlphaBytes,
394391
smallMarioBytes,
395392
] = await Promise.all([
396-
fetchStringAsset('images/cat_riding_unicorn.jpg.base64'),
393+
fetchBinaryAsset('images/cat_riding_unicorn.jpg'),
397394
fetchBinaryAsset('images/minions_laughing.jpg'),
398-
fetchStringAsset('images/greyscale_bird.png.base64.uri'),
395+
fetchBinaryAsset('images/greyscale_bird.png'),
399396
fetchBinaryAsset('images/minions_banana_alpha.png'),
400397
fetchBinaryAsset('images/minions_banana_no_alpha.png'),
401398
fetchBinaryAsset('images/small_mario.png'),
402399
]);
403400

404401
const catRidingUnicornImage = await pdfDoc.embedJpg(
405-
catRidingUnicornBase64,
402+
catRidingUnicornBytes,
406403
);
407404
const minionsLaughingImage = await pdfDoc.embedJpg(minionsLaughingBytes);
408-
const greyscaleBirdImage = await pdfDoc.embedPng(greyscaleBirdBase64);
405+
const greyscaleBirdImage = await pdfDoc.embedPng(greyscaleBirdBytes);
409406
const minionsBananaAlphaImage = await pdfDoc.embedPng(
410407
minionsBananaAlphaBytes,
411408
);

apps/web/test19.html

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@
3838
const fetchBinaryAsset = (asset) =>
3939
fetch(`/assets/${asset}`).then((res) => res.arrayBuffer());
4040

41-
const fetchStringAsset = (asset) =>
42-
fetch(`/assets/${asset}`).then((res) => res.text());
43-
44-
const renderInIframe = (pdfDataUri) => {
45-
document.getElementById('iframe').src = pdfDataUri;
41+
const renderInIframe = (pdfBytes) => {
42+
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
43+
const blobUrl = URL.createObjectURL(blob);
44+
document.getElementById('iframe').src = blobUrl;
4645
};
4746

4847
async function test() {
@@ -75,12 +74,11 @@
7574
console.log('PDF encryption with useObjectStreams: false');
7675
console.log('password:', password);
7776

78-
const base64PdfDataUri = await pdfDoc.saveAsBase64({
79-
dataUri: true,
77+
const pdfBytes = await pdfDoc.save({
8078
useObjectStreams: false,
8179
});
8280

83-
renderInIframe(base64PdfDataUri);
81+
renderInIframe(pdfBytes);
8482
}
8583
</script>
8684
</html>

0 commit comments

Comments
 (0)