Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add the page border ??? #1256

Closed
rajendraprasadyk opened this issue Oct 25, 2021 · 4 comments
Closed

How to add the page border ??? #1256

rajendraprasadyk opened this issue Oct 25, 2021 · 4 comments

Comments

@rajendraprasadyk
Copy link

I didn't get example regrading the same

@rajendraprasadyk
Copy link
Author

@dolanmiu Can you please check

@anti-the-social
Copy link
Contributor

anti-the-social commented Oct 26, 2021

Hello there, that is how it works.
Close the issue if that solves your problem.

@dolanmiu you can put it as an example file into demo folder once you have time..

const { Document, Packer, TextRun, Paragraph, BorderStyle} = require('docx');

const doc = new Document({
  sections: [{
    properties: {
      page:{
        borders:{
          pageBorderBottom: {
            style: BorderStyle.SINGLE,
            size: 2*8, //2pt;
            color: '000000',
          },
          pageBorderLeft: {
            style: BorderStyle.SINGLE,
            size: 1*8, //1pt;
            color: '000000',
          },
          pageBorderRight: {
            style: BorderStyle.SINGLE,
            size: 1*8, //1pt;
            color: 'FF00AA',
          },
          pageBorderTop: {
            style: BorderStyle.SINGLE,
            size: 1*8, //1pt;
            color: '000000',
          },
          
          pageBorders: {
            display: "allPages", //https://docx.js.org/api/enums/PageBorderDisplay.html
            offsetFrom: "text", //https://docx.js.org/api/enums/PageBorderOffsetFrom.html
            zOrder: "front" //https://docx.js.org/api/enums/PageBorderZOrder.html
          }
        }
      },
    },
    children: [
      new Paragraph({
        children: [
          new TextRun({ text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`})
        ]
      }),
      new Paragraph({
        children: [
          new TextRun({ text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`})
        ]
      })
    ]
  }],
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("pageBorders.docx", buffer);
});

@rajendraprasadyk
Copy link
Author

Hello there, that is how it works. Close the issue if that solves your problem.

@dolanmiu you can put it as an example file into demo folder once you have time..

const { Document, Packer, TextRun, Paragraph, BorderStyle} = require('docx');

const doc = new Document({
  sections: [{
    properties: {
      page:{
        borders:{
          pageBorderBottom: {
            style: BorderStyle.SINGLE,
            size: 2*8, //2pt;
            color: '000000',
          },
          pageBorderLeft: {
            style: BorderStyle.SINGLE,
            size: 1*8, //1pt;
            color: '000000',
          },
          pageBorderRight: {
            style: BorderStyle.SINGLE,
            size: 1*8, //1pt;
            color: 'FF00AA',
          },
          pageBorderTop: {
            style: BorderStyle.SINGLE,
            size: 1*8, //1pt;
            color: '000000',
          },
          
          pageBorders: {
            display: "allPages", //https://docx.js.org/api/enums/PageBorderDisplay.html
            offsetFrom: "text", //https://docx.js.org/api/enums/PageBorderOffsetFrom.html
            zOrder: "front" //https://docx.js.org/api/enums/PageBorderZOrder.html
          }
        }
      },
    },
    children: [
      new Paragraph({
        children: [
          new TextRun({ text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`})
        ]
      }),
      new Paragraph({
        children: [
          new TextRun({ text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`})
        ]
      })
    ]
  }],
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("pageBorders.docx", buffer);
});

It works.. thanks for your quick help

dolanmiu added a commit that referenced this issue Oct 30, 2021
@dolanmiu
Copy link
Owner

Done, added the demo

thanks everyone :)

#1271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants