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

Frame alignment doesn't seem to work #933

Closed
anti-the-social opened this issue May 7, 2021 · 2 comments · Fixed by #2477
Closed

Frame alignment doesn't seem to work #933

anti-the-social opened this issue May 7, 2021 · 2 comments · Fixed by #2477

Comments

@anti-the-social
Copy link
Contributor

anti-the-social commented May 7, 2021

Hi! Thanks for the great lib once again.
Noticed that alignment doesn't seem to work for the frames.

  1. frame.position cannot be just dropped since error is thrown.
  2. frame.alignment never overwrites rule that mandatory frame.position created

Result of the code downstairs:
image

const fs = require('fs');
const { Document, Packer, Paragraph, FrameAnchorType, HorizontalPositionAlign, VerticalPositionAlign, FrameWrap} = require('docx');

const doc = new Document({
  sections: [{
    children: [
      new Paragraph({
        text: "Random text in frame",
        frame: {
          space:{
            horizontal: 250, //twips
            vertical: 250 //twips
          },
          wrap: FrameWrap.AROUND, 
          position: {
            x: 0, // should be mentioned, otherwise error thrown
            y: 0, // should be mentioned, otherwise error thrown
          },
          anchor: {
            horizontal: FrameAnchorType.MARGIN,
            vertical: FrameAnchorType.TEXT,
          },
          // for some reason this is ignored; hardocding position.x to certain value; Need to be reported I suppose
          alignment: {
            x: HorizontalPositionAlign.CENTER,
            y: VerticalPositionAlign.TOP,
          },
        }
      }),
      new Paragraph({
        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. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.`,
      })
    ],
  }]
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("frame_test.docx", buffer);
});
@anti-the-social
Copy link
Contributor Author

Just some additional info if helps. The position thingy in word's UI can be not only number, but also word left/right etc
image
image

@dolanmiu
Copy link
Owner

I have made a PR here to hopefully address this:

#2477

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

Successfully merging a pull request may close this issue.

2 participants