In docx js library i want to change the font size and font type of the bulletin points

347 Views Asked by At

const { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } = require("docx");
const { saveAs } = require("file-saver");
const fs = require("fs");


const heading = 'Bespoke Strategic Advisory Services';
const para = 'On 22 July 2019, ISRO launched Chandrayaan-2 on board a Launch Vehicle Mark-3 (LVM3) launch vehicle consisting of an orbiter, a lander and a rover.[14] The lander was scheduled to touch down on the lunar surface on 6 September 2019 to deploy the Pragyan rover. The lander lost contact with mission control, deviated from its intended trajectory while attempting to land near the lunar south pole, and crashed.[15][16]\n' +
  '\n' + // Insert a line break here
  '\n'+
  'The lunar south pole region holds particular interest for scientific exploration. Studies show large amounts of ice there. Mountainous terrain and unpredictable lighting protect the ice from melting, but they also make landing scientific probes there a challenging undertaking. The ice could contain solid-state compounds that would normally melt under warmer conditions elsewhere on the Moon—compounds which could provide insight into lunar, Earth, and Solar System history. For future crewed missions and outposts, ice could also be a source of drinking water and of hydrogen for fuel and oxygen.[17][18]\n' +
  '\n' + // Insert a line break here
  'The European Space Tracking network (ESTRACK), operated by the European Space Agency (ESA), and Deep Space Network operated by Jet Propulsion Laboratory (JPL) of NASA are supporting the mission.[19] Under a new cross-support arrangement, ESA tracking support could be provided for upcoming ISRO missions such as those of India\'s first human spaceflight programme, Gaganyaan, and the Aditya-L1 solar research mission. In return, future ESA missions will receive similar support from ISRO\'s own tracking stations.[20]';
  



// Create a new instance of Document for the docx module
const doc = new Document({
  numbering: {

    run : {
      size: 64,
      text : {
        size: 32, // Customize the font size for the numbering part
        font: "Times New Roman",
      }
    },
    size: 64,
    font: "Times New Roman",
    config: [
        {
            reference: "my-crazy-numbering",
            size: 64,
            font: "Times New Roman",
            levels: [
                {
                    level: 0,
                    format: "decimal",
                    size: 164,
                    font: "Times New Roman",
                    text: "%1.0",
                    alignment: AlignmentType.START,
                    style: {
                      size: 32, // Customize the font size for the numbering part
                      font: "Times New Roman", // Customize the font for the numbering part
                      text : {
                        size: 32, // Customize the font size for the numbering part
                        font: "Times New Roman",
                      }
                    },
                },
                {
                    level: 1,
                    format: "decimal",
                    text: "%1.",
                    alignment: AlignmentType.START,
                    style: {
                        paragraph: {
                            indent: { left: 1440, hanging: 980 },
                        },
                    },
                },
                {
                    level: 2,
                    format: "lowerLetter",
                    text: "%3)",
                    alignment: AlignmentType.START,
                    style: {
                        paragraph: {
                            indent: { left: 2160, hanging: 1700 },
                        },
                    },
                },
                {
                    level: 3,
                    format: "upperLetter",
                    text: "%4)",
                    alignment: AlignmentType.START,
                    style: {
                        paragraph: {
                            indent: { left: 2880, hanging: 2420 },
                        },
                    },
                },
            ],
        },
    ],
},
  sections: [
    {
        properties: {
          text : {
            size: 32, // Customize the font size for the numbering part
            font: "Times New Roman",
          }
        },
        children: [
         
          new Paragraph({
            alignment: AlignmentType.LEFT,
            children: [
                new TextRun({
                    text: heading,
                    bold: true,
                    size: 32,
                    font: "Times New Roman",
                    bullet: {
                        level: 1
                    }
                })
            ],
            spacing: {
                after: 200,
            },
            numbering: {
                reference: "my-crazy-numbering",
                level: 0,
                
                size : 36
              
            },
            // children: [
            //     new TextRun({
            //         numbering: {
            //             reference: "my-crazy-numbering",
            //             level: 0,
            //         },
            //         size: 32,
            //         font: "Times New Roman",
            //     })
            // ],
            styles: {
                size: 64,
                font: "Times New Roman",
            }
        }),
        
          
            ...para.split('\n').map((line) => new Paragraph({
              alignment: AlignmentType.JUSTIFIED,
              children: [
                new TextRun({
                  text: line,
                  size: 28, // Font size for the paragraph
                  font: "Times New Roman",
                }),
              ],
            })),
          ],
        },
      ],
  // styles: {
  //     default: {
  //         font: "Times New Roman",
  //     },
  //     numbering : {
  //       run: {
  //         size: 28,
  //         bold: true,
  //         italics: true,
  //         color: "FF0000",
  //     },
  //     },
  //     text : {
  //       font: "Times New Roman",
  //       size : 32
  //     },
  //     styles: {
  //       // ... (existing styles)
  //       listParagraph: {
  //           run: {
  //               font: "Times New Roman", // Replace with the desired font name
  //               size: 76, // Replace with the desired font size
  //               color: "#FF0000", // Customize the color if needed
  //           },
  //       },
  //       // ... (other styles)
  //   },
  // },
  styles: {
    // ... (existing styles)
    bullet: {
      run: {
        font: " Times New Roman", // Replace with the desired font name
        size: 68, // Replace with the desired font size
      },
    },
  },

});


  Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("My Document.docx", buffer);
});

for ex : 1.0 Space Mission --> Heading of the word document the font sizes for "1.0" and "Space Mission" are different "1.0" is size of 10 and font type is Calibri, while "Space Mission" is size 16 and Times New Roman. I would like both fonts to be the same size and family. Unfortunately, changing the font type and size for "1.0" is not permitted by the library.

0

There are 0 best solutions below