Skip to content

Commit 97d0c7a

Browse files
ralfstxclaude
andcommitted
♻️ Use pdf-core native lang option
The `setLanguage` workaround manually set the `/Lang` entry in the PDF catalog using `unsafeOnRender`, `PDFDict`, and `PDFString`. pdf-core 0.2.0 now supports `lang` as a constructor option on `PDFDocument`, so the workaround can be replaced with a single property. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c4c6d8c commit 97d0c7a

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/render/render-document.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PDFContext, PDFDict, WriteOptions } from '@ralfstx/pdf-core';
2-
import { PDFDocument, PDFStream, PDFString } from '@ralfstx/pdf-core';
2+
import { PDFDocument, PDFStream } from '@ralfstx/pdf-core';
33

44
import type { Page } from '../page.ts';
55
import type { DocumentDefinition, Metadata } from '../read/read-document.ts';
@@ -10,11 +10,8 @@ export async function renderDocument(
1010
pages: Page[],
1111
writeOptions?: WriteOptions,
1212
): Promise<Uint8Array> {
13-
const pdfDoc = new PDFDocument();
13+
const pdfDoc = new PDFDocument({ lang: def.language });
1414
setMetadata(pdfDoc, def.info);
15-
if (def.language) {
16-
setLanguage(def.language, pdfDoc);
17-
}
1815
if (def.customData) {
1916
setCustomData(def.customData, pdfDoc);
2017
}
@@ -52,13 +49,6 @@ function setMetadata(doc: PDFDocument, info?: Metadata) {
5249
});
5350
}
5451

55-
function setLanguage(language: string, doc: PDFDocument) {
56-
doc.unsafeOnRender((renderContext) => {
57-
const catalog = renderContext.catalog as PDFDict;
58-
catalog.set('Lang', PDFString.of(language));
59-
});
60-
}
61-
6252
function setCustomData(data: Record<string, string | Uint8Array>, doc: PDFDocument) {
6353
for (const [key, value] of Object.entries(data)) {
6454
doc.unsafeOnRender((renderContext) => {

0 commit comments

Comments
 (0)