Pptxgenjs: Margin not working with placeholder text (v3)

Created on 7 Jan 2020  ·  6Comments  ·  Source: gitbrent/PptxGenJS

Hi,

This used to work:
defineSlideMaster having object:

{
    placeholder: {
        options: {
            name: "title",
            type: "title",
            x: leftMargin,
            y: 0.2,
            w: layoutWidth - leftMargin - logoWidth,
            h: 0.3,
            bold: true,
            fontFace: "Helvetica",
            color: "404040",
            fontSize: 18,
            align: "left",
            valign: "middle",
            margin: 0,
        },
        text: "",
    },
},

And then adding to it.

imageSlide.addText(slideTitle, {
    placeholder: "title",
});

Some screenshots to visualize the problem:

Old version:
title-has-no-margin-v2
New version:
title-has-margin-v3
And settings:
title-has-margins-v3

Tested with https://github.com/gitbrent/PptxGenJS.git#2cee3f0c412106aefb1f87fc16bfef78ae5521a7 (as it solved the JSZip problem).

bug

All 6 comments

Oh and just noticed that the "Vertical alignment" is not working either. As we can see on the screenshot it's "Top", but I did specify it as "middle".

Yes, I can confirm too that “vertical alignment” is not working. The default is top; setting valign=“bottom” or valign=“middle” does not change the alignment.

@gitbrent looks like there's a logic issue infunction genXmlBodyProperties(slideObject)

The first if statement block sets the anchor attribute for text objects to control vertical alignment, but Placeholders are being sent to the else block which doesn't set the anchor in bodyProperties.

This would also affect the margins as they are set in the same block of code

Is the valigin problem fixed? I got the same issue when adding placeholder.

Is the valigin problem fixed? I got the same issue when adding placeholder.

I confirmed that the latest 3.4.0 still has this issue.

Thanks for reporting this @bestis

Fixed in newest build, targeted to v3.6.0

let pptx = new PptxGenJS();
pptx.defineSlideMaster({
    title: "MASTER_SLIDE",
    background: { fill: "F1F1F1" },
    margin: [0.5, 0.25, 1.0, 0.25],
    objects: [
        {
            placeholder: {
                options: {
                    name: "header",
                    type: "title",
                    x: 0.6,
                    y: 0.2,
                    w: 6,
                    h: 1.0,
                    color: "696969",
                    fontSize: 18,
                    align: "left",
                    valign: "middle",
                    margin: 0,
                },
                text: "",
            },
        },
        {
            placeholder: {
                options: {
                    name: "title",
                    type: "title",
                    x: 0.6,
                    y: 2.2,
                    w: 6,
                    h: 1.0,
                    color: "404040",
                    fontSize: 18,
                    align: "right",
                    valign: "bottom",
                    margin: 0,
                },
                text: "METOO",
            },
        },
    ],
});

let slide = pptx.addSlide("MASTER_SLIDE");

pptx.writeFile({ fileName: "PptxGenJS-Sandbox.pptx" });

Screen Shot 2021-04-17 at 16 27 07

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jobnte picture jobnte  ·  5Comments

sangramjagtap picture sangramjagtap  ·  6Comments

luism-s picture luism-s  ·  3Comments

DSheffield picture DSheffield  ·  3Comments

LeoFC97 picture LeoFC97  ·  3Comments