@tiens.nguyen/gu-cli 1.0.903 → 1.0.905

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 (188) hide show
  1. package/NOTICE +18 -0
  2. package/gu-repl.mjs +1 -1
  3. package/package.json +3 -2
  4. package/skills/core/deep-research/SKILL.md +51 -0
  5. package/skills/core/docx/LICENSE.txt +202 -0
  6. package/skills/core/docx/SKILL.md +97 -0
  7. package/skills/core/docx/scripts/__init__.py +1 -0
  8. package/skills/core/docx/scripts/accept_changes.py +135 -0
  9. package/skills/core/docx/scripts/comment.py +368 -0
  10. package/skills/core/docx/scripts/merge_runs.py +310 -0
  11. package/skills/core/docx/scripts/office/helpers/__init__.py +121 -0
  12. package/skills/core/docx/scripts/office/helpers/pptx_chart.py +283 -0
  13. package/skills/core/docx/scripts/office/helpers/pptx_slide.py +100 -0
  14. package/skills/core/docx/scripts/office/helpers/pptx_theme.py +114 -0
  15. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  16. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  17. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  18. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  19. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  20. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  21. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  22. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  23. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  24. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  25. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  26. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  27. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  28. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  29. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  30. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  31. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  32. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  33. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  34. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  35. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  36. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  37. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  38. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  39. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  40. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  41. package/skills/core/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  42. package/skills/core/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  43. package/skills/core/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  44. package/skills/core/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  45. package/skills/core/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  46. package/skills/core/docx/scripts/office/schemas/mce/mc.xsd +75 -0
  47. package/skills/core/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  48. package/skills/core/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  49. package/skills/core/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  50. package/skills/core/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  51. package/skills/core/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  52. package/skills/core/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  53. package/skills/core/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  54. package/skills/core/docx/scripts/office/soffice.py +192 -0
  55. package/skills/core/docx/scripts/office/validate.py +210 -0
  56. package/skills/core/docx/scripts/office/validators/__init__.py +15 -0
  57. package/skills/core/docx/scripts/office/validators/base.py +874 -0
  58. package/skills/core/docx/scripts/office/validators/docx.py +519 -0
  59. package/skills/core/docx/scripts/office/validators/pptx.py +549 -0
  60. package/skills/core/docx/scripts/office/validators/redlining.py +461 -0
  61. package/skills/core/docx/scripts/templates/comments.xml +3 -0
  62. package/skills/core/docx/scripts/templates/commentsExtended.xml +3 -0
  63. package/skills/core/docx/scripts/templates/commentsExtensible.xml +3 -0
  64. package/skills/core/docx/scripts/templates/commentsIds.xml +3 -0
  65. package/skills/core/docx/scripts/templates/people.xml +3 -0
  66. package/skills/core/pdf/FORMS.md +294 -0
  67. package/skills/core/pdf/LICENSE.txt +202 -0
  68. package/skills/core/pdf/REFERENCE.md +613 -0
  69. package/skills/core/pdf/SKILL.md +314 -0
  70. package/skills/core/pdf/scripts/check_bounding_boxes.py +65 -0
  71. package/skills/core/pdf/scripts/check_fillable_fields.py +11 -0
  72. package/skills/core/pdf/scripts/convert_pdf_to_images.py +33 -0
  73. package/skills/core/pdf/scripts/create_validation_image.py +37 -0
  74. package/skills/core/pdf/scripts/extract_form_field_info.py +122 -0
  75. package/skills/core/pdf/scripts/extract_form_structure.py +115 -0
  76. package/skills/core/pdf/scripts/fill_fillable_fields.py +98 -0
  77. package/skills/core/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
  78. package/skills/core/pptx/LICENSE.txt +202 -0
  79. package/skills/core/pptx/SKILL.md +275 -0
  80. package/skills/core/pptx/scripts/__init__.py +0 -0
  81. package/skills/core/pptx/scripts/add_slide.py +463 -0
  82. package/skills/core/pptx/scripts/apply_theme.js +107 -0
  83. package/skills/core/pptx/scripts/clean.py +309 -0
  84. package/skills/core/pptx/scripts/office/helpers/__init__.py +121 -0
  85. package/skills/core/pptx/scripts/office/helpers/pptx_chart.py +283 -0
  86. package/skills/core/pptx/scripts/office/helpers/pptx_slide.py +100 -0
  87. package/skills/core/pptx/scripts/office/helpers/pptx_theme.py +114 -0
  88. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  89. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  90. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  91. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  92. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  93. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  94. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  95. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  96. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  97. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  98. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  99. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  100. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  101. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  102. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  103. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  104. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  105. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  106. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  107. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  108. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  109. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  110. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  111. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  112. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  113. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  114. package/skills/core/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  115. package/skills/core/pptx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  116. package/skills/core/pptx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  117. package/skills/core/pptx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  118. package/skills/core/pptx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  119. package/skills/core/pptx/scripts/office/schemas/mce/mc.xsd +75 -0
  120. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  121. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  122. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  123. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  124. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  125. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  126. package/skills/core/pptx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  127. package/skills/core/pptx/scripts/office/soffice.py +192 -0
  128. package/skills/core/pptx/scripts/office/validate.py +210 -0
  129. package/skills/core/pptx/scripts/office/validators/__init__.py +15 -0
  130. package/skills/core/pptx/scripts/office/validators/base.py +874 -0
  131. package/skills/core/pptx/scripts/office/validators/docx.py +519 -0
  132. package/skills/core/pptx/scripts/office/validators/pptx.py +549 -0
  133. package/skills/core/pptx/scripts/office/validators/redlining.py +461 -0
  134. package/skills/core/pptx/scripts/slide_text.py +132 -0
  135. package/skills/core/pptx/scripts/thumbnail.py +311 -0
  136. package/skills/core/xlsx/LICENSE.txt +202 -0
  137. package/skills/core/xlsx/SKILL.md +99 -0
  138. package/skills/core/xlsx/scripts/office/helpers/__init__.py +121 -0
  139. package/skills/core/xlsx/scripts/office/helpers/pptx_chart.py +283 -0
  140. package/skills/core/xlsx/scripts/office/helpers/pptx_slide.py +100 -0
  141. package/skills/core/xlsx/scripts/office/helpers/pptx_theme.py +114 -0
  142. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  143. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  144. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  145. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  146. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  147. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  148. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  149. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  150. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  151. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  152. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  153. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  154. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  155. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  156. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  157. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  158. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  159. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  160. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  161. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  162. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  163. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  164. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  165. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  166. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  167. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  168. package/skills/core/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  169. package/skills/core/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  170. package/skills/core/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  171. package/skills/core/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  172. package/skills/core/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  173. package/skills/core/xlsx/scripts/office/schemas/mce/mc.xsd +75 -0
  174. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  175. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  176. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  177. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  178. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  179. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  180. package/skills/core/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  181. package/skills/core/xlsx/scripts/office/soffice.py +192 -0
  182. package/skills/core/xlsx/scripts/office/validate.py +210 -0
  183. package/skills/core/xlsx/scripts/office/validators/__init__.py +15 -0
  184. package/skills/core/xlsx/scripts/office/validators/base.py +874 -0
  185. package/skills/core/xlsx/scripts/office/validators/docx.py +519 -0
  186. package/skills/core/xlsx/scripts/office/validators/pptx.py +549 -0
  187. package/skills/core/xlsx/scripts/office/validators/redlining.py +461 -0
  188. package/skills/core/xlsx/scripts/recalc.py +456 -0
@@ -0,0 +1,613 @@
1
+ # PDF Processing Advanced Reference
2
+
3
+ This document contains advanced PDF processing features, detailed examples, and additional libraries not covered in the main skill instructions.
4
+
5
+ ## pypdfium2 Library (Apache/BSD License)
6
+
7
+ ### Overview
8
+ pypdfium2 is a Python binding for PDFium (Chromium's PDF library). It's excellent for fast PDF rendering, image generation, and serves as a PyMuPDF replacement.
9
+
10
+ ### Render PDF to Images
11
+ ```python
12
+ import pypdfium2 as pdfium
13
+ from PIL import Image
14
+
15
+ # Load PDF
16
+ pdf = pdfium.PdfDocument("document.pdf")
17
+
18
+ # Render page to image
19
+ page = pdf[0] # First page
20
+ bitmap = page.render(
21
+ scale=2.0, # Higher resolution
22
+ rotation=0 # No rotation
23
+ )
24
+
25
+ # Convert to PIL Image
26
+ img = bitmap.to_pil()
27
+ img.save("page_1.png", "PNG")
28
+
29
+ # Process multiple pages
30
+ for i, page in enumerate(pdf):
31
+ bitmap = page.render(scale=1.5)
32
+ img = bitmap.to_pil()
33
+ img.save(f"page_{i+1}.jpg", "JPEG", quality=90)
34
+ ```
35
+
36
+ ### Extract Text with pypdfium2
37
+ ```python
38
+ import pypdfium2 as pdfium
39
+
40
+ pdf = pdfium.PdfDocument("document.pdf")
41
+ for i, page in enumerate(pdf):
42
+ textpage = page.get_textpage()
43
+ text = textpage.get_text_range()
44
+ print(f"Page {i+1} text length: {len(text)} chars")
45
+ ```
46
+
47
+ ## JavaScript Libraries
48
+
49
+ ### pdf-lib (MIT License)
50
+
51
+ pdf-lib is a powerful JavaScript library for creating and modifying PDF documents in any JavaScript environment.
52
+
53
+ #### Load and Manipulate Existing PDF
54
+ ```javascript
55
+ import { PDFDocument } from 'pdf-lib';
56
+ import fs from 'fs';
57
+
58
+ async function manipulatePDF() {
59
+ // Load existing PDF
60
+ const existingPdfBytes = fs.readFileSync('input.pdf');
61
+ const pdfDoc = await PDFDocument.load(existingPdfBytes);
62
+
63
+ // Get page count
64
+ const pageCount = pdfDoc.getPageCount();
65
+ console.log(`Document has ${pageCount} pages`);
66
+
67
+ // Add new page
68
+ const newPage = pdfDoc.addPage([600, 400]);
69
+ newPage.drawText('Added by pdf-lib', {
70
+ x: 100,
71
+ y: 300,
72
+ size: 16
73
+ });
74
+
75
+ // Save modified PDF
76
+ const pdfBytes = await pdfDoc.save();
77
+ fs.writeFileSync('modified.pdf', pdfBytes);
78
+ }
79
+ ```
80
+
81
+ #### Create Complex PDFs from Scratch
82
+ ```javascript
83
+ import { PDFDocument, rgb, StandardFonts } from 'pdf-lib';
84
+ import fs from 'fs';
85
+
86
+ async function createPDF() {
87
+ const pdfDoc = await PDFDocument.create();
88
+
89
+ // Add fonts
90
+ const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
91
+ const helveticaBold = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
92
+
93
+ // Add page
94
+ const page = pdfDoc.addPage([595, 842]); // A4 size
95
+ const { width, height } = page.getSize();
96
+
97
+ // Add text with styling
98
+ page.drawText('Invoice #12345', {
99
+ x: 50,
100
+ y: height - 50,
101
+ size: 18,
102
+ font: helveticaBold,
103
+ color: rgb(0.2, 0.2, 0.8)
104
+ });
105
+
106
+ // Add rectangle (header background)
107
+ page.drawRectangle({
108
+ x: 40,
109
+ y: height - 100,
110
+ width: width - 80,
111
+ height: 30,
112
+ color: rgb(0.9, 0.9, 0.9)
113
+ });
114
+
115
+ // Add table-like content
116
+ const items = [
117
+ ['Item', 'Qty', 'Price', 'Total'],
118
+ ['Widget', '2', '$50', '$100'],
119
+ ['Gadget', '1', '$75', '$75']
120
+ ];
121
+
122
+ let yPos = height - 150;
123
+ items.forEach(row => {
124
+ let xPos = 50;
125
+ row.forEach(cell => {
126
+ page.drawText(cell, {
127
+ x: xPos,
128
+ y: yPos,
129
+ size: 12,
130
+ font: helveticaFont
131
+ });
132
+ xPos += 120;
133
+ });
134
+ yPos -= 25;
135
+ });
136
+
137
+ const pdfBytes = await pdfDoc.save();
138
+ fs.writeFileSync('created.pdf', pdfBytes);
139
+ }
140
+ ```
141
+
142
+ #### Advanced Merge and Split Operations
143
+ ```javascript
144
+ import { PDFDocument } from 'pdf-lib';
145
+ import fs from 'fs';
146
+
147
+ async function mergePDFs() {
148
+ // Create new document
149
+ const mergedPdf = await PDFDocument.create();
150
+
151
+ // Load source PDFs
152
+ const pdf1Bytes = fs.readFileSync('doc1.pdf');
153
+ const pdf2Bytes = fs.readFileSync('doc2.pdf');
154
+
155
+ const pdf1 = await PDFDocument.load(pdf1Bytes);
156
+ const pdf2 = await PDFDocument.load(pdf2Bytes);
157
+
158
+ // Copy pages from first PDF
159
+ const pdf1Pages = await mergedPdf.copyPages(pdf1, pdf1.getPageIndices());
160
+ pdf1Pages.forEach(page => mergedPdf.addPage(page));
161
+
162
+ // Copy specific pages from second PDF (pages 0, 2, 4)
163
+ const pdf2Pages = await mergedPdf.copyPages(pdf2, [0, 2, 4]);
164
+ pdf2Pages.forEach(page => mergedPdf.addPage(page));
165
+
166
+ const mergedPdfBytes = await mergedPdf.save();
167
+ fs.writeFileSync('merged.pdf', mergedPdfBytes);
168
+ }
169
+ ```
170
+
171
+ ### pdfjs-dist (Apache License)
172
+
173
+ PDF.js is Mozilla's JavaScript library for rendering PDFs in the browser.
174
+
175
+ #### Basic PDF Loading and Rendering
176
+ ```javascript
177
+ import * as pdfjsLib from 'pdfjs-dist';
178
+
179
+ // Configure worker (important for performance)
180
+ pdfjsLib.GlobalWorkerOptions.workerSrc = './pdf.worker.js';
181
+
182
+ async function renderPDF() {
183
+ // Load PDF
184
+ const loadingTask = pdfjsLib.getDocument('document.pdf');
185
+ const pdf = await loadingTask.promise;
186
+
187
+ console.log(`Loaded PDF with ${pdf.numPages} pages`);
188
+
189
+ // Get first page
190
+ const page = await pdf.getPage(1);
191
+ const viewport = page.getViewport({ scale: 1.5 });
192
+
193
+ // Render to canvas
194
+ const canvas = document.createElement('canvas');
195
+ const context = canvas.getContext('2d');
196
+ canvas.height = viewport.height;
197
+ canvas.width = viewport.width;
198
+
199
+ const renderContext = {
200
+ canvasContext: context,
201
+ viewport: viewport
202
+ };
203
+
204
+ await page.render(renderContext).promise;
205
+ document.body.appendChild(canvas);
206
+ }
207
+ ```
208
+
209
+ #### Extract Text with Coordinates
210
+ ```javascript
211
+ import * as pdfjsLib from 'pdfjs-dist';
212
+
213
+ async function extractText() {
214
+ const loadingTask = pdfjsLib.getDocument('document.pdf');
215
+ const pdf = await loadingTask.promise;
216
+
217
+ let fullText = '';
218
+
219
+ // Extract text from all pages
220
+ for (let i = 1; i <= pdf.numPages; i++) {
221
+ const page = await pdf.getPage(i);
222
+ const textContent = await page.getTextContent();
223
+
224
+ const pageText = textContent.items
225
+ .map(item => item.str)
226
+ .join(' ');
227
+
228
+ fullText += `\n--- Page ${i} ---\n${pageText}`;
229
+
230
+ // Get text with coordinates for advanced processing
231
+ const textWithCoords = textContent.items.map(item => ({
232
+ text: item.str,
233
+ x: item.transform[4],
234
+ y: item.transform[5],
235
+ width: item.width,
236
+ height: item.height
237
+ }));
238
+ }
239
+
240
+ console.log(fullText);
241
+ return fullText;
242
+ }
243
+ ```
244
+
245
+ #### Extract Annotations and Forms
246
+ ```javascript
247
+ import * as pdfjsLib from 'pdfjs-dist';
248
+
249
+ async function extractAnnotations() {
250
+ const loadingTask = pdfjsLib.getDocument('annotated.pdf');
251
+ const pdf = await loadingTask.promise;
252
+
253
+ for (let i = 1; i <= pdf.numPages; i++) {
254
+ const page = await pdf.getPage(i);
255
+ const annotations = await page.getAnnotations();
256
+
257
+ annotations.forEach(annotation => {
258
+ console.log(`Annotation type: ${annotation.subtype}`);
259
+ console.log(`Content: ${annotation.contents}`);
260
+ console.log(`Coordinates: ${JSON.stringify(annotation.rect)}`);
261
+ });
262
+ }
263
+ }
264
+ ```
265
+
266
+ ## Advanced Command-Line Operations
267
+
268
+ ### poppler-utils Advanced Features
269
+
270
+ #### Extract Text with Bounding Box Coordinates
271
+ ```bash
272
+ # Extract text with bounding box coordinates (essential for structured data)
273
+ pdftotext -bbox-layout document.pdf output.xml
274
+
275
+ # The XML output contains precise coordinates for each text element
276
+ ```
277
+
278
+ #### Advanced Image Conversion
279
+ ```bash
280
+ # Convert to PNG images with specific resolution
281
+ pdftoppm -png -r 300 document.pdf output_prefix
282
+
283
+ # Convert specific page range with high resolution
284
+ pdftoppm -png -r 600 -f 1 -l 3 document.pdf high_res_pages
285
+
286
+ # Convert to JPEG with quality setting
287
+ pdftoppm -jpeg -jpegopt quality=85 -r 200 document.pdf jpeg_output
288
+ ```
289
+
290
+ #### Extract Embedded Images
291
+ ```bash
292
+ # Extract all embedded images with metadata
293
+ pdfimages -j -p document.pdf page_images
294
+
295
+ # List image info without extracting
296
+ pdfimages -list document.pdf
297
+
298
+ # Extract images in their original format
299
+ pdfimages -all document.pdf images/img
300
+ ```
301
+
302
+ ### qpdf Advanced Features
303
+
304
+ #### Complex Page Manipulation
305
+ ```bash
306
+ # Split PDF into groups of pages
307
+ qpdf --split-pages=3 input.pdf output_group_%02d.pdf
308
+
309
+ # Extract specific pages with complex ranges
310
+ qpdf input.pdf --pages input.pdf 1,3-5,8,10-end -- extracted.pdf
311
+
312
+ # Merge specific pages from multiple PDFs
313
+ qpdf --empty --pages doc1.pdf 1-3 doc2.pdf 5-7 doc3.pdf 2,4 -- combined.pdf
314
+ ```
315
+
316
+ #### PDF Optimization and Repair
317
+ ```bash
318
+ # Optimize PDF for web (linearize for streaming)
319
+ qpdf --linearize input.pdf optimized.pdf
320
+
321
+ # Remove unused objects and compress
322
+ qpdf --optimize-level=all input.pdf compressed.pdf
323
+
324
+ # Attempt to repair corrupted PDF structure
325
+ qpdf --check input.pdf
326
+ qpdf --fix-qdf damaged.pdf repaired.pdf
327
+
328
+ # Show detailed PDF structure for debugging
329
+ qpdf --show-all-pages input.pdf > structure.txt
330
+ ```
331
+
332
+ #### Advanced Encryption
333
+ ```bash
334
+ # Add password protection with specific permissions
335
+ qpdf --encrypt user_pass owner_pass 256 --print=none --modify=none -- input.pdf encrypted.pdf
336
+
337
+ # Check encryption status
338
+ qpdf --show-encryption encrypted.pdf
339
+
340
+ # Remove password protection (requires password)
341
+ qpdf --password=secret123 --decrypt encrypted.pdf decrypted.pdf
342
+ ```
343
+
344
+ ## Advanced Python Techniques
345
+
346
+ ### pdfplumber Advanced Features
347
+
348
+ #### Extract Text with Precise Coordinates
349
+ ```python
350
+ import pdfplumber
351
+
352
+ with pdfplumber.open("document.pdf") as pdf:
353
+ page = pdf.pages[0]
354
+
355
+ # Extract all text with coordinates
356
+ chars = page.chars
357
+ for char in chars[:10]: # First 10 characters
358
+ print(f"Char: '{char['text']}' at x:{char['x0']:.1f} y:{char['y0']:.1f}")
359
+
360
+ # Extract text by bounding box (left, top, right, bottom)
361
+ bbox_text = page.within_bbox((100, 100, 400, 200)).extract_text()
362
+ ```
363
+
364
+ #### Advanced Table Extraction with Custom Settings
365
+ ```python
366
+ import pdfplumber
367
+ import pandas as pd
368
+
369
+ with pdfplumber.open("complex_table.pdf") as pdf:
370
+ page = pdf.pages[0]
371
+
372
+ # Extract tables with custom settings for complex layouts
373
+ table_settings = {
374
+ "vertical_strategy": "lines",
375
+ "horizontal_strategy": "lines",
376
+ "snap_tolerance": 3,
377
+ "intersection_tolerance": 15
378
+ }
379
+ tables = page.extract_tables(table_settings)
380
+
381
+ # Visual debugging for table extraction
382
+ img = page.to_image(resolution=150)
383
+ img.save("debug_layout.png")
384
+ ```
385
+
386
+ ### reportlab Advanced Features
387
+
388
+ #### Create Professional Reports with Tables
389
+ ```python
390
+ from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph
391
+ from reportlab.lib.styles import getSampleStyleSheet
392
+ from reportlab.lib import colors
393
+
394
+ # Sample data
395
+ data = [
396
+ ['Product', 'Q1', 'Q2', 'Q3', 'Q4'],
397
+ ['Widgets', '120', '135', '142', '158'],
398
+ ['Gadgets', '85', '92', '98', '105']
399
+ ]
400
+
401
+ # Create PDF with table
402
+ doc = SimpleDocTemplate("report.pdf")
403
+ elements = []
404
+
405
+ # Add title
406
+ styles = getSampleStyleSheet()
407
+ title = Paragraph("Quarterly Sales Report", styles['Title'])
408
+ elements.append(title)
409
+
410
+ # Add table with advanced styling
411
+ table = Table(data)
412
+ table.setStyle(TableStyle([
413
+ ('BACKGROUND', (0, 0), (-1, 0), colors.grey),
414
+ ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
415
+ ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
416
+ ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
417
+ ('FONTSIZE', (0, 0), (-1, 0), 14),
418
+ ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
419
+ ('BACKGROUND', (0, 1), (-1, -1), colors.beige),
420
+ ('GRID', (0, 0), (-1, -1), 1, colors.black)
421
+ ]))
422
+ elements.append(table)
423
+
424
+ doc.build(elements)
425
+ ```
426
+
427
+ ## Complex Workflows
428
+
429
+ ### Extract Figures/Images from PDF
430
+
431
+ #### Method 1: Using pdfimages (fastest)
432
+ ```bash
433
+ # Extract all images with original quality
434
+ pdfimages -all document.pdf images/img
435
+ ```
436
+
437
+ #### Method 2: Using pypdfium2 + Image Processing
438
+ ```python
439
+ import pypdfium2 as pdfium
440
+ from PIL import Image
441
+ import numpy as np
442
+
443
+ def extract_figures(pdf_path, output_dir):
444
+ pdf = pdfium.PdfDocument(pdf_path)
445
+
446
+ for page_num, page in enumerate(pdf):
447
+ # Render high-resolution page
448
+ bitmap = page.render(scale=3.0)
449
+ img = bitmap.to_pil()
450
+
451
+ # Convert to numpy for processing
452
+ img_array = np.array(img)
453
+
454
+ # Simple figure detection (non-white regions)
455
+ mask = np.any(img_array != [255, 255, 255], axis=2)
456
+
457
+ # Find contours and extract bounding boxes
458
+ # (This is simplified - real implementation would need more sophisticated detection)
459
+
460
+ # Save detected figures
461
+ # ... implementation depends on specific needs
462
+ ```
463
+
464
+ ### Batch PDF Processing with Error Handling
465
+ ```python
466
+ import os
467
+ import glob
468
+ from pypdf import PdfReader, PdfWriter
469
+ import logging
470
+
471
+ logging.basicConfig(level=logging.INFO)
472
+ logger = logging.getLogger(__name__)
473
+
474
+ def batch_process_pdfs(input_dir, operation='merge'):
475
+ pdf_files = glob.glob(os.path.join(input_dir, "*.pdf"))
476
+
477
+ if operation == 'merge':
478
+ writer = PdfWriter()
479
+ for pdf_file in pdf_files:
480
+ try:
481
+ reader = PdfReader(pdf_file)
482
+ for page in reader.pages:
483
+ writer.add_page(page)
484
+ logger.info(f"Processed: {pdf_file}")
485
+ except Exception as e:
486
+ logger.error(f"Failed to process {pdf_file}: {e}")
487
+ continue
488
+
489
+ with open("batch_merged.pdf", "wb") as output:
490
+ writer.write(output)
491
+
492
+ elif operation == 'extract_text':
493
+ for pdf_file in pdf_files:
494
+ try:
495
+ reader = PdfReader(pdf_file)
496
+ text = ""
497
+ for page in reader.pages:
498
+ text += page.extract_text()
499
+
500
+ output_file = pdf_file.replace('.pdf', '.txt')
501
+ with open(output_file, 'w', encoding='utf-8') as f:
502
+ f.write(text)
503
+ logger.info(f"Extracted text from: {pdf_file}")
504
+
505
+ except Exception as e:
506
+ logger.error(f"Failed to extract text from {pdf_file}: {e}")
507
+ continue
508
+ ```
509
+
510
+ ### Advanced PDF Cropping
511
+ ```python
512
+ from pypdf import PdfWriter, PdfReader
513
+
514
+ reader = PdfReader("input.pdf")
515
+ writer = PdfWriter()
516
+
517
+ # Crop page (left, bottom, right, top in points)
518
+ page = reader.pages[0]
519
+ page.mediabox.left = 50
520
+ page.mediabox.bottom = 50
521
+ page.mediabox.right = 550
522
+ page.mediabox.top = 750
523
+
524
+ writer.add_page(page)
525
+ with open("cropped.pdf", "wb") as output:
526
+ writer.write(output)
527
+ ```
528
+
529
+ ## Performance Optimization Tips
530
+
531
+ ### 1. For Large PDFs
532
+ - Use streaming approaches instead of loading entire PDF in memory
533
+ - Use `qpdf --split-pages` for splitting large files
534
+ - Process pages individually with pypdfium2
535
+
536
+ ### 2. For Text Extraction
537
+ - `pdftotext` is fastest for plain text extraction
538
+ - Use pdfplumber for structured data and tables
539
+ - Avoid `pypdf.extract_text()` for very large documents
540
+
541
+ ### 3. For Image Extraction
542
+ - `pdfimages` is much faster than rendering pages
543
+ - Use low resolution for previews, high resolution for final output
544
+
545
+ ### 4. For Form Filling
546
+ - pdf-lib maintains form structure better than most alternatives
547
+ - Pre-validate form fields before processing
548
+
549
+ ### 5. Memory Management
550
+ ```python
551
+ # Process PDFs in chunks
552
+ def process_large_pdf(pdf_path, chunk_size=10):
553
+ reader = PdfReader(pdf_path)
554
+ total_pages = len(reader.pages)
555
+
556
+ for start_idx in range(0, total_pages, chunk_size):
557
+ end_idx = min(start_idx + chunk_size, total_pages)
558
+ writer = PdfWriter()
559
+
560
+ for i in range(start_idx, end_idx):
561
+ writer.add_page(reader.pages[i])
562
+
563
+ # Process chunk
564
+ with open(f"chunk_{start_idx//chunk_size}.pdf", "wb") as output:
565
+ writer.write(output)
566
+ ```
567
+
568
+ ## Troubleshooting Common Issues
569
+
570
+ ### Encrypted PDFs
571
+ ```python
572
+ # Handle password-protected PDFs
573
+ from pypdf import PdfReader
574
+
575
+ try:
576
+ reader = PdfReader("encrypted.pdf")
577
+ if reader.is_encrypted:
578
+ reader.decrypt("password")
579
+ except Exception as e:
580
+ print(f"Failed to decrypt: {e}")
581
+ ```
582
+
583
+ ### Corrupted PDFs
584
+ ```bash
585
+ # Use qpdf to repair
586
+ qpdf --check corrupted.pdf
587
+ qpdf --replace-input corrupted.pdf
588
+ ```
589
+
590
+ ### Text Extraction Issues
591
+ ```python
592
+ # Fallback to OCR for scanned PDFs
593
+ import pytesseract
594
+ from pdf2image import convert_from_path
595
+
596
+ def extract_text_with_ocr(pdf_path):
597
+ images = convert_from_path(pdf_path)
598
+ text = ""
599
+ for i, image in enumerate(images):
600
+ text += pytesseract.image_to_string(image)
601
+ return text
602
+ ```
603
+
604
+ ## License Information
605
+
606
+ - **pypdf**: BSD License
607
+ - **pdfplumber**: MIT License
608
+ - **pypdfium2**: Apache/BSD License
609
+ - **reportlab**: BSD License
610
+ - **poppler-utils**: GPL-2 License
611
+ - **qpdf**: Apache License
612
+ - **pdf-lib**: MIT License
613
+ - **pdfjs-dist**: Apache License