# Advanced Features — פיצ'רים מתקדמים ## הערות שוליים (Footnotes) **שימוש מרכזי:** הפניות לחקיקה ופסיקה. ```javascript const { FootnoteReferenceRun } = require('docx'); const doc = new Document({ footnotes: { 1: { children: [new Paragraph({ bidirectional: true, alignment: AlignmentType.START, children: [new TextRun({ text: "חוק החוזים (חלק כללי), התשל״ג-1973, סעיף 12.", font: "David", size: 20, rightToLeft: true })] })] }, }, // ...sections }); // הפניה בגוף הטקסט: new Paragraph({ bidirectional: true, alignment: AlignmentType.BOTH, children: [ new TextRun({ text: "חובת תום הלב", font: "David", size: 24, rightToLeft: true }), new FootnoteReferenceRun(1), new TextRun({ text: " חלה על כל שלבי המשא ומתן.", font: "David", size: 24, rightToLeft: true }), ] }) ``` ### תיקון RTL בהערות שוליים (post-unpack) docx-js לא מגדיר RTL מלא. אחרי unpack, תקן ב-`word/footnotes.xml`: ```xml ``` --- ## תוכן עניינים (TOC) **⚠️ TOC ידני בלבד** — `TableOfContents` של docx-js מאבד הגדרות RTL בעדכון Word. ```javascript const { Tab, TabStopType, LeaderType, LineRuleType } = require('docx'); const tocEntry = (text, pageNum, opts = {}) => new Paragraph({ bidirectional: true, spacing: { after: 60, line: 276, lineRule: LineRuleType.AUTO }, ...(opts.indent ? { indent: { right: opts.indent } } : {}), tabStops: [{ type: TabStopType.RIGHT, position: 9026, leader: LeaderType.DOT }], children: [ new TextRun({ text, font: "David", size: 24, rightToLeft: true, bold: opts.bold || false }), new TextRun({ children: [new Tab()], font: "David", rightToLeft: true }), new TextRun({ text: String(pageNum), font: "David", size: 24, rightToLeft: true }), ] }); // שימוש: tocEntry("פרק א׳ — הגדרות כלליות", 2, { bold: true }), tocEntry("1. הגדרות יסוד", 2, { indent: 400 }), ``` --- ## מספר סקשנים (Multiple Sections) **שימוש:** כותרות שונות לנספחים, שוליים שונים. ```javascript const doc = new Document({ sections: [ { properties: { page: { size: { width: 11906, height: 16838 }, margin: { top: 1417, right: 1417, bottom: 1417, left: 1417 } }, bidi: true, }, headers: { default: new Header({ children: [new Paragraph({ bidirectional: true, alignment: AlignmentType.CENTER, children: [new TextRun({ text: "הסכם שירותים", font: "David", size: 20, bold: true, rightToLeft: true })] })] }) }, children: [ /* גוף ההסכם */ ] }, { properties: { page: { size: { width: 11906, height: 16838 }, margin: { top: 1417, right: 1417, bottom: 1417, left: 1417 } }, bidi: true, }, headers: { default: new Header({ children: [new Paragraph({ bidirectional: true, alignment: AlignmentType.START, children: [new TextRun({ text: "נספח א׳ — לוח תעריפים", font: "David", size: 20, bold: true, rightToLeft: true })] })] }) }, children: [ /* הנספח */ ] } ] }); ``` --- ## לוגו/תמונה בכותרת (Letterhead) ```javascript const { ImageRun } = require('docx'); const logoBuffer = fs.readFileSync('/path/to/logo.png'); headers: { default: new Header({ children: [ new Paragraph({ alignment: AlignmentType.CENTER, children: [new ImageRun({ data: logoBuffer, transformation: { width: 200, height: 60 }, type: "png" })], }), new Paragraph({ bidirectional: true, alignment: AlignmentType.CENTER, children: [new TextRun({ text: "משרד עורכי דין ישראלי ושות׳", font: "David", size: 20, bold: true, rightToLeft: true })], }), ], }), } ``` **הערה:** תמונה חייבת להיות קובץ אמיתי — לבקש מהמשתמש אם אין. --- ## היפרלינקים ```javascript const { ExternalHyperlink, UnderlineType } = require('docx'); new Paragraph({ bidirectional: true, children: [ new TextRun({ text: "ראה: ", font: "David", size: 24, rightToLeft: true }), new ExternalHyperlink({ link: "https://www.nevo.co.il/law_html/law01/073_002.htm", children: [new TextRun({ text: "חוק החוזים באתר נבו", font: "David", size: 24, rightToLeft: true, color: "0563C1", underline: { type: UnderlineType.SINGLE }, })], }), ] }) ``` **⚠️ אל תשתמש ב-`style: "Hyperlink"`** — מפריע ל-RTL. הגדר `color` + `underline` ידנית.