@wirabyte/w-pdfmaker 0.0.0-stage → 1.0.2

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.
Files changed (142) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/LICENSE +22 -0
  3. package/NOTICE.md +39 -0
  4. package/README.md +106 -2
  5. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  6. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  7. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  8. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  9. package/build/fonts/Roboto.js +27 -0
  10. package/build/pdfmake.js +103161 -0
  11. package/build/pdfmake.js.map +1 -0
  12. package/build/pdfmake.min.js +3 -0
  13. package/build/pdfmake.min.js.map +1 -0
  14. package/build/standard-fonts/Courier.js +9 -0
  15. package/build/standard-fonts/Helvetica.js +9 -0
  16. package/build/standard-fonts/Symbol.js +9 -0
  17. package/build/standard-fonts/Times.js +9 -0
  18. package/build/standard-fonts/ZapfDingbats.js +9 -0
  19. package/build/vfs_fonts.js +6 -0
  20. package/build-vfs.js +44 -0
  21. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  22. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  23. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  24. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  25. package/fonts/Roboto.js +8 -0
  26. package/fonts/THSarabunIT9/LICENSE.txt +7 -0
  27. package/fonts/THSarabunIT9/THSarabunIT9-Bold.ttf +0 -0
  28. package/fonts/THSarabunIT9/THSarabunIT9-BoldItalic.ttf +0 -0
  29. package/fonts/THSarabunIT9/THSarabunIT9-Italic.ttf +0 -0
  30. package/fonts/THSarabunIT9/THSarabunIT9.ttf +0 -0
  31. package/fonts/THSarabunNew/COPYING.GPLv2 +339 -0
  32. package/fonts/THSarabunNew/LICENSE.txt +13 -0
  33. package/fonts/THSarabunNew/THSarabunNew-Bold.ttf +0 -0
  34. package/fonts/THSarabunNew/THSarabunNew-BoldItalic.ttf +0 -0
  35. package/fonts/THSarabunNew/THSarabunNew-Italic.ttf +0 -0
  36. package/fonts/THSarabunNew/THSarabunNew.ttf +0 -0
  37. package/index.d.ts +167 -0
  38. package/interfaces.d.ts +2779 -0
  39. package/js/DocMeasure.js +695 -0
  40. package/js/DocPreprocessor.js +263 -0
  41. package/js/DocumentContext.js +563 -0
  42. package/js/ElementWriter.js +488 -0
  43. package/js/LayoutBuilder.js +1525 -0
  44. package/js/Line.js +105 -0
  45. package/js/OutputDocument.js +73 -0
  46. package/js/OutputDocumentServer.js +34 -0
  47. package/js/PDFDocument.js +322 -0
  48. package/js/PageElementWriter.js +302 -0
  49. package/js/PageSize.js +74 -0
  50. package/js/Printer.js +275 -0
  51. package/js/Renderer.js +439 -0
  52. package/js/SVGMeasure.js +94 -0
  53. package/js/StyleContextStack.js +191 -0
  54. package/js/TableProcessor.js +658 -0
  55. package/js/TextBreaker.js +164 -0
  56. package/js/TextDecorator.js +164 -0
  57. package/js/TextInlines.js +212 -0
  58. package/js/URLResolver.js +122 -0
  59. package/js/base.js +125 -0
  60. package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
  61. package/js/browser-extensions/fonts/Roboto.js +38 -0
  62. package/js/browser-extensions/fonts/thai.js +28 -0
  63. package/js/browser-extensions/index.js +88 -0
  64. package/js/browser-extensions/pageUrls.js +79 -0
  65. package/js/browser-extensions/pdfMake.js +3 -0
  66. package/js/browser-extensions/standard-fonts/Courier.js +20 -0
  67. package/js/browser-extensions/standard-fonts/Helvetica.js +20 -0
  68. package/js/browser-extensions/standard-fonts/Symbol.js +17 -0
  69. package/js/browser-extensions/standard-fonts/Times.js +20 -0
  70. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
  71. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  72. package/js/columnCalculator.js +159 -0
  73. package/js/helpers/node.js +122 -0
  74. package/js/helpers/tools.js +46 -0
  75. package/js/helpers/variableType.js +59 -0
  76. package/js/imageFallback.js +23 -0
  77. package/js/index.js +45 -0
  78. package/js/mergeStamp.js +194 -0
  79. package/js/pageNumbering.js +48 -0
  80. package/js/qrEnc.js +721 -0
  81. package/js/standardPageSizes.js +56 -0
  82. package/js/tableLayouts.js +98 -0
  83. package/js/thai.js +201 -0
  84. package/js/virtual-fs.js +82 -0
  85. package/package.json +93 -4
  86. package/skills/w-pdfmaker/SKILL.md +171 -0
  87. package/skills/w-pdfmaker/references/browser.md +36 -0
  88. package/skills/w-pdfmaker/references/document-definition.md +241 -0
  89. package/skills/w-pdfmaker/references/images.md +90 -0
  90. package/skills/w-pdfmaker/references/merge-stamp.md +94 -0
  91. package/skills/w-pdfmaker/references/thai.md +67 -0
  92. package/src/DocMeasure.js +780 -0
  93. package/src/DocPreprocessor.js +293 -0
  94. package/src/DocumentContext.js +605 -0
  95. package/src/ElementWriter.js +550 -0
  96. package/src/LayoutBuilder.js +1689 -0
  97. package/src/Line.js +114 -0
  98. package/src/OutputDocument.js +75 -0
  99. package/src/OutputDocumentServer.js +38 -0
  100. package/src/PDFDocument.js +352 -0
  101. package/src/PageElementWriter.js +343 -0
  102. package/src/PageSize.js +53 -0
  103. package/src/Printer.js +289 -0
  104. package/src/Renderer.js +468 -0
  105. package/src/SVGMeasure.js +109 -0
  106. package/src/StyleContextStack.js +208 -0
  107. package/src/TableProcessor.js +719 -0
  108. package/src/TextBreaker.js +166 -0
  109. package/src/TextDecorator.js +191 -0
  110. package/src/TextInlines.js +229 -0
  111. package/src/URLResolver.js +122 -0
  112. package/src/base.js +143 -0
  113. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  114. package/src/browser-extensions/fonts/Roboto.js +27 -0
  115. package/src/browser-extensions/fonts/thai.js +23 -0
  116. package/src/browser-extensions/index.js +91 -0
  117. package/src/browser-extensions/pageUrls.js +67 -0
  118. package/src/browser-extensions/pdfMake.js +1 -0
  119. package/src/browser-extensions/standard-fonts/Courier.js +25 -0
  120. package/src/browser-extensions/standard-fonts/Helvetica.js +25 -0
  121. package/src/browser-extensions/standard-fonts/Symbol.js +17 -0
  122. package/src/browser-extensions/standard-fonts/Times.js +25 -0
  123. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
  124. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  125. package/src/columnCalculator.js +160 -0
  126. package/src/helpers/node.js +134 -0
  127. package/src/helpers/tools.js +44 -0
  128. package/src/helpers/variableType.js +50 -0
  129. package/src/imageFallback.js +18 -0
  130. package/src/index.js +45 -0
  131. package/src/mergeStamp.js +132 -0
  132. package/src/pageNumbering.js +45 -0
  133. package/src/qrEnc.js +796 -0
  134. package/src/standardPageSizes.js +52 -0
  135. package/src/tableLayouts.js +100 -0
  136. package/src/thai.js +170 -0
  137. package/src/virtual-fs.js +92 -0
  138. package/standard-fonts/Courier.js +8 -0
  139. package/standard-fonts/Helvetica.js +8 -0
  140. package/standard-fonts/Symbol.js +5 -0
  141. package/standard-fonts/Times.js +8 -0
  142. package/standard-fonts/ZapfDingbats.js +5 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,53 @@
1
+ # Changelog
2
+
3
+ ทุกรุ่นระบุว่าอิง pdfmake รุ่นไหน · การเปลี่ยนแปลงของ pdfmake เองดูที่ [CHANGELOG ของ pdfmake](https://github.com/bpampuch/pdfmake/blob/master/CHANGELOG.md)
4
+
5
+ ## 1.0.2 - 2026-11-23
6
+
7
+ อิง **pdfmake 0.3.15** · เนื้อแพ็กเกจเหมือน 1.0.1
8
+
9
+ - publish จาก GitHub Actions ด้วย trusted publishing (ไม่ใช้ token)
10
+
11
+ ## 1.0.1 - 2026-11-23
12
+
13
+ อิง **pdfmake 0.3.15** · โค้ดเหมือน 1.0.0
14
+
15
+ - เผยแพร่บน npmjs.com แบบ public สัญญา MIT (1.0.0 อยู่บน GitHub Packages เท่านั้น): `npm install @wirabyte/w-pdfmaker` ไม่ต้องตั้ง `.npmrc` หรือ token · โปรเจกต์ที่มี `@wirabyte:registry=https://npm.pkg.github.com` ใน `.npmrc` ให้ลบบรรทัดนั้น
16
+ - `README.md` เป็นคู่มือการใช้งาน (ภาษาอังกฤษ)
17
+
18
+ ## 1.0.0 - 2026-11-23
19
+
20
+ อิง **pdfmake 0.3.15** ([CHANGELOG](https://github.com/bpampuch/pdfmake/blob/0.3.15/CHANGELOG.md))
21
+
22
+ - ตัดบรรทัดภาษาไทยระหว่างคำ (`Intl.Segmenter`) ไม่ต้องแทรก ZWSP หรือใช้ wordcut เอง
23
+ - `alignment: 'distribute'` จัดเต็มบรรทัดโดยกระจายช่องไฟระหว่างตัวอักษร แบบ "Thai Distributed" ของ Word · `'justify'` ยังกระจายระหว่างคำเหมือนเดิม
24
+ - คัดลอกและค้นหาคำที่มีสระอำได้ถูกต้อง (ไม่แตกเป็น "ํา") ด้วย `ActualText` เฉพาะกลุ่มอักษรที่มี ำ (เช่น "จำ" ใน "จำนวน") ให้โปรแกรมที่ใช้ MuPDF ถอดคำที่มี ำ กลางคำได้ถูกด้วย (ไม่ซ้ำท้ายคำ)
25
+ - ฝังฟอนต์ `THSarabunNew` และ `THSarabunIT9` (แสดงเลขไทย) ลงทะเบียนให้แล้วทั้ง Node.js และเบราว์เซอร์ ไม่ต้อง `setFonts` / `vfs_fonts.js`
26
+ - `pdfmake.merge(parts)` รวมหน้า PDF ตามลำดับ เลือกช่วงหน้าด้วย `{ pdf, from, to }` · เปิด PDF ที่ติดรหัสเจ้าของได้
27
+ - `pdfmake.stamp(pdf, fn)` เขียน content ของ pdfmake ลงบนหน้าของ PDF ที่มีอยู่แล้ว (เช่น เลขหน้า ลายน้ำ) รองรับหน้าหมุนและหน้าต่างขนาด
28
+ - ใส่ไฟล์ด้วย path ได้: `svg: 'logo.svg'` (เดิมต้องเป็นเนื้อ XML) · `image: 'logo.svg'` วาดเป็น svg ให้ · `merge(['a.pdf', { pdf: 'b.pdf', from: 2 }])` · `stamp('in.pdf', fn)` · ใส่ path ของ `.svg` ใน `images` ได้
29
+ - Node.js: อ่านไฟล์ในเครื่อง path สัมพัทธ์อิง `process.cwd()` ผ่าน `setLocalAccessPolicy` (`image: 'logo.png'` ใช้ได้อยู่แล้วตั้งแต่ pdfmake)
30
+ - เบราว์เซอร์: path ใน `image` / `svg` / `images` และของ `merge` / `stamp` เป็น URL เทียบกับหน้าเว็บ ดาวน์โหลดก่อนจัดหน้า ผ่าน `setUrlAccessPolicy` · หน้าเว็บต้องเปิดผ่าน http(s)
31
+ - `fallback: true` บน node `image` / `svg`: ถ้าหารูปไม่เจอ (ค่าว่าง เช่น `image: user.signature ?? ''` หรือรายการว่างใน `images`, ไม่มีไฟล์, ดาวน์โหลดไม่สำเร็จ — ทุกสถานะที่ไม่ใช่ 2xx รวม 403/500) จะเว้นที่ว่างโปร่งใสไว้แทน ไม่ทำให้ทั้งเอกสาร error
32
+ - ใส่ทั้ง `width` และ `height` เพื่อเว้นที่ให้พอดี (ที่ว่างไม่มีสัดส่วน: ใส่แค่ `width` ได้สี่เหลี่ยมจัตุรัส ไม่ใส่ขนาดได้ 1pt)
33
+ - ยัง error เหมือนเดิม: ถูก `setLocalAccessPolicy` / `setUrlAccessPolicy` ปฏิเสธ, ไฟล์เสียหรือชนิดที่ไม่รองรับ
34
+ - เลขหน้าราย section แบบ Word: `{ section: [...], pageNumbering: { start: 1, format: 'ก' } }` — `start` เริ่มนับใหม่, `format` เป็น `'1'` / `'i'` / `'I'` / `'๑'` / `'ก'` (ก ข ค ไม่มี ฃ ฅ) หรือฟังก์ชัน `n => string` · section ที่ไม่ใส่นับต่อจาก section ก่อนหน้าด้วยรูปแบบเดิม
35
+ - ใช้กับเลขหน้าในสารบัญ, `pageReference` และอาร์กิวเมนต์ที่ 4 ของ `header` / `footer`: `footer: (currentPage, pageCount, pageSize, pageLabel) => pageLabel` (`currentPage` ยังเป็นเลขหน้าจริงของไฟล์)
36
+ - ระดับหัวข้อในสารบัญ: `tocLevel: 2` บนหัวข้อ ย่อเข้า `(tocLevel − 1) × toc.indent` (ค่าเริ่มต้น 20pt) และเมื่อ `toc: { outlines: true }` bookmark จะซ้อนใต้หัวข้อระดับบนตัวก่อนหน้า
37
+ - skill สำหรับ Claude Code (`skills/w-pdfmaker/`) มากับแพ็กเกจ: คัดลอกไป `.claude/skills/` ของโปรเจกต์ (ดู README)
38
+ - type ของ TypeScript มากับแพ็กเกจ (`index.d.ts`, `interfaces.d.ts`) ไม่ต้องติดตั้ง `@types/pdfmake`
39
+ - ใช้ `@cantoo/pdf-lib` สำหรับ `merge` / `stamp` (ไม่ต้องติดตั้ง `pdf-lib` เอง)
40
+
41
+ ### ต่างจาก pdfmake 0.3.15 เดิม
42
+
43
+ - เอกสารที่ไม่ได้เลือกฟอนต์ใช้ `THSarabunNew` แทน `Roboto` และฟอนต์ไทยที่ฝังมีขนาดเริ่มต้น 16pt แทน 12pt
44
+ - ฝั่ง Node.js ลงทะเบียนเฉพาะฟอนต์ไทย ถ้าต้องการ Roboto: `pdfmake.addFonts(require('@wirabyte/w-pdfmaker/fonts/Roboto'))` แล้วใส่ `defaultStyle: { font: 'Roboto' }` · ฝั่งเบราว์เซอร์ชื่อ Roboto ลงทะเบียนไว้ แต่ต้องโหลด `build/vfs_fonts.js` เอง
45
+ - `setFonts()` ชุดที่ไม่มี `THSarabunNew` จะได้ค่าเริ่มต้นแบบ pdfmake (Roboto 12pt)
46
+ - ข้อความไทยที่ใช้ `alignment: 'justify'` จะมีช่องห่างที่รอยต่อคำไทย เพราะตัดคำไทยเสมอ → ใช้ `'distribute'` กับข้อความไทย
47
+ - ฝั่ง Node.js ไม่ดาวน์โหลดจาก URL เป็นค่าเริ่มต้น (`setUrlAccessPolicy(() => false)`) แต่อ่านไฟล์ในเครื่องได้ (`setLocalAccessPolicy(() => true)`) จึงไม่มี warning เรื่อง access policy
48
+ - `svg` ที่เป็นข้อความไม่ขึ้นต้นด้วย `<` ถือเป็น path หรือชื่อใน `images` (เดิม error "Invalid svg document")
49
+ - ฝั่งเบราว์เซอร์ ข้อความใน `image` / `svg` / `images` ที่ไม่ใช่ data URL, URL แบบ http(s) เต็ม หรือไฟล์ใน virtual file system จะถูกดาวน์โหลดจาก URL เทียบกับหน้าเว็บ (เดิม error ไม่พบไฟล์)
50
+ - แอปที่ใช้ bundler ต้องส่ง URL ที่ bundler ให้ (เช่น `import logoUrl from './logo.png'`) ไม่ใช่ path ในโฟลเดอร์ source
51
+ - path ที่ใช้ในฟังก์ชัน `header` / `footer` / `background` ต้องใส่ไว้ใน `images` เพราะฟังก์ชันทำงานหลังดาวน์โหลดเสร็จแล้ว
52
+ - รูปจาก URL ใน `images` ที่ดาวน์โหลดไม่สำเร็จ error ตอนที่ node ใช้รูปนั้น (ข้อความ "Network request failed …" เดิม) ไม่ใช่ตอนเริ่มสร้าง · รายการใน `images` ที่ไม่มี node ใช้ ดาวน์โหลดไม่ได้ก็ไม่ error แล้ว
53
+ - `build/pdfmake.min.js` ใหญ่ขึ้นจาก 0.88 MB เป็น 3.18 MB (ฟอนต์ไทยและ pdf-lib)
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2015 bpampuch
4
+ 2016-2026 liborm85
5
+ 2026 Wirabyte
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ this software and associated documentation files (the "Software"), to deal in
9
+ the Software without restriction, including without limitation the rights to
10
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ the Software, and to permit persons to whom the Software is furnished to do so,
12
+ subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/NOTICE.md ADDED
@@ -0,0 +1,39 @@
1
+ # Third-party notices
2
+
3
+ `@wirabyte/w-pdfmaker` is MIT licensed ([`LICENSE`](LICENSE)). It contains code and files from these projects. Their licenses apply to those parts.
4
+
5
+ | Part | Project | License |
6
+ |---|---|---|
7
+ | Everything except the parts below (`src/`, `js/`, `build/`, `fonts/Roboto/`, `standard-fonts/` …), together with the changes of w-pdfmaker | [pdfmake](https://github.com/bpampuch/pdfmake) 0.3.15 | MIT — [`LICENSE`](LICENSE) |
8
+ | `build/pdfmake*.js` (bundled); used from `node_modules` in Node.js | [@cantoo/pdf-lib](https://github.com/cantoo-scribe/pdf-lib) | MIT — below |
9
+ | `index.d.ts`, `interfaces.d.ts` | [@types/pdfmake](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/pdfmake) 0.3.3 | MIT — header of `interfaces.d.ts` |
10
+ | `fonts/THSarabunNew/` | TH Sarabun New | GPL v2 or later with a font embedding exception — `fonts/THSarabunNew/LICENSE.txt`, `COPYING.GPLv2` |
11
+ | `fonts/THSarabunIT9/` | TH SarabunIT๙ | DIP/SIPA font license — `fonts/THSarabunIT9/LICENSE.txt` |
12
+
13
+ The browser build (`build/pdfmake*.js`) also bundles the dependencies of pdfmake and pdf-lib (pdfkit, fontkit, linebreak and others), as upstream pdfmake does. Their licenses are in their packages, installed with this one.
14
+
15
+ ## @cantoo/pdf-lib
16
+
17
+ ```
18
+ MIT License
19
+
20
+ Copyright (c) 2019 Andrew Dillon
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all
30
+ copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
+ SOFTWARE.
39
+ ```
package/README.md CHANGED
@@ -1,3 +1,107 @@
1
- # Temporary Holding Version
1
+ # @wirabyte/w-pdfmaker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [pdfmake](https://github.com/bpampuch/pdfmake) 0.3.15 with Thai built in, plus merging and stamping of existing PDFs.
4
+ Works in Node.js and the browser. Document definitions are plain pdfmake 0.3, so the
5
+ [pdfmake docs](https://pdfmake.github.io/docs/) apply; this page covers what is different.
6
+
7
+ ไลบรารีสร้าง PDF จาก pdfmake ที่รองรับภาษาไทยในตัว: ฟอนต์ TH Sarabun, ตัดคำไทย, จัดเต็มบรรทัดแบบไทย, คัดลอกสระอำได้ถูกต้อง, รวมและประทับ PDF
8
+
9
+ - **Thai fonts registered:** text uses `THSarabunNew` at 16pt by default. `THSarabunIT9` draws digits as Thai numerals
10
+ while the text stays `0–9`.
11
+ - **Thai line breaking** between words (`Intl.Segmenter`), no zero-width spaces or word-cutting libraries.
12
+ - **`alignment: 'distribute'`** spreads a line like Word's "Thai Distributed" (`'justify'` leaves gaps in Thai).
13
+ - **ำ (SARA AM) copies and searches correctly** in Chrome, Acrobat and MuPDF-based viewers.
14
+ - **Section page numbering** like Word (ก ข ค for front matter, 1 2 3 for chapters) and nested table-of-contents levels.
15
+ - **Images and SVGs by file path**, and `fallback: true` to leave blank space when an image is missing.
16
+ - **`merge`** pages of several PDFs and **`stamp`** pdfmake content (page numbers, watermarks) onto existing PDFs.
17
+ - TypeScript types included.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install @wirabyte/w-pdfmaker
23
+ ```
24
+
25
+ Node.js >= 20.19. When migrating from pdfmake, remove `pdfmake`, `@types/pdfmake`, `pdf-lib` and any Thai font files or
26
+ line-breaking patches.
27
+
28
+ ## Use
29
+
30
+ ```js
31
+ const path = require('path');
32
+ const pdfmake = require('@wirabyte/w-pdfmaker'); // or: import pdfmake from '@wirabyte/w-pdfmaker';
33
+
34
+ const doc = {
35
+ pageSize: 'A4',
36
+ pageMargins: [85, 70, 57, 57],
37
+ content: [
38
+ { text: 'บันทึกข้อความ', fontSize: 29, bold: true, alignment: 'center' },
39
+ { text: 'ตามที่โรงเรียนได้กำหนดให้มีการจัดกิจกรรมสัปดาห์วิทยาศาสตร์ ...', alignment: 'distribute' },
40
+ { image: path.join(__dirname, 'signature.png'), fallback: true, width: 100, height: 40 },
41
+ ],
42
+ footer: (currentPage, pageCount) => ({ text: `${currentPage}/${pageCount}`, alignment: 'center' }),
43
+ };
44
+
45
+ const pdf = await pdfmake.createPdf(doc).getBuffer();
46
+ ```
47
+
48
+ Import the package as one object: `import { createPdf }` fails at runtime because its functions use `this`.
49
+ Types: `import type { TDocumentDefinitions } from '@wirabyte/w-pdfmaker/interfaces'`.
50
+
51
+ In Node.js, local files are readable and URL downloads are blocked by default; allow them with
52
+ `pdfmake.setUrlAccessPolicy(url => url.startsWith('https://files.example.com/'))`. In the browser, bundlers pick
53
+ `build/pdfmake.js` automatically, file paths are URLs relative to the page, and `download()`, `open()` and `print()`
54
+ are available.
55
+
56
+ ### Page numbers per section and table of contents
57
+
58
+ ```js
59
+ footer: (currentPage, pageCount, pageSize, pageLabel) => ({ text: pageLabel, alignment: 'center' }),
60
+ content: [
61
+ { section: [cover], footer: null },
62
+ { section: [abstract, { toc: { title: { text: 'สารบัญ' }, outlines: true } }], pageNumbering: { start: 1, format: 'ก' } },
63
+ { section: [{ text: 'บทที่ 1 บทนำ', tocItem: true }, { text: '1.1 ความเป็นมา', tocItem: true, tocLevel: 2 }, body],
64
+ pageNumbering: { start: 1, format: '1' } },
65
+ ],
66
+ ```
67
+
68
+ Formats: `'1'`, `'i'`, `'I'`, `'๑'`, `'ก'` or a function `n => string`.
69
+
70
+ ### Merge and stamp
71
+
72
+ ```js
73
+ const merged = await pdfmake.merge([
74
+ { pdf: mainPdf, to: 3 }, // pages 1–3
75
+ 'attachments/scan.pdf', // a string is a file path (a URL in the browser)
76
+ { pdf: mainPdf, from: 4 }, // page 4 to the end
77
+ ]);
78
+
79
+ const numbered = await pdfmake.stamp(merged, ({ pageNumber, pageCount, height }) => ({
80
+ absolutePosition: { x: 0, y: height - 40 },
81
+ stack: [{ text: `หน้า ${pageNumber}/${pageCount}`, alignment: 'right', margin: [0, 0, 40, 0] }],
82
+ }));
83
+ ```
84
+
85
+ Both return a `Buffer`. The `stamp` function may return `null` to leave a page untouched. PDFs locked with only an owner
86
+ password can be opened; the output is not encrypted.
87
+
88
+ All changes from pdfmake 0.3.15, including behaviour differences: [`CHANGELOG.md`](CHANGELOG.md).
89
+
90
+ ## Claude Code skill
91
+
92
+ The package ships a [Claude Code](https://claude.com/claude-code) skill (`skills/w-pdfmaker/`): a short guide plus
93
+ references, so Claude uses this package correctly without reading all the docs. Copy it into your project (again after
94
+ upgrading the package):
95
+
96
+ ```bash
97
+ mkdir -p .claude/skills && cp -r node_modules/@wirabyte/w-pdfmaker/skills/w-pdfmaker .claude/skills/
98
+ ```
99
+
100
+ ```powershell
101
+ New-Item -ItemType Directory -Force .claude/skills; Copy-Item -Recurse -Force node_modules/@wirabyte/w-pdfmaker/skills/w-pdfmaker .claude/skills/
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT ([`LICENSE`](LICENSE)), based on pdfmake (MIT). Bundled parts from other projects, including the TH Sarabun fonts
107
+ (GPL with a font embedding exception, and the DIP/SIPA font license), are listed in [`NOTICE.md`](NOTICE.md).