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

Slide number shown by default change styling #96

Open
an-rushikeshlondhe opened this issue Jul 11, 2022 · 1 comment
Open

Slide number shown by default change styling #96

an-rushikeshlondhe opened this issue Jul 11, 2022 · 1 comment

Comments

@an-rushikeshlondhe
Copy link

No description provided.

@MaoHuPi
Copy link

MaoHuPi commented Apr 8, 2023

You can directly change the xmlObject.

function setPageNumStyle(slide, style){
    let pageNumElement = slide.powerPointFactory.pptFactory.slideFactory.content[`ppt/slides/${slide.name}.xml`]['p:sld']['p:cSld'][0]['p:spTree'][0]['p:sp'][0];
    let fld = pageNumElement['p:txBody'][0]['a:p'][0]['a:fld'][0];
    let styleData = {$: fld['a:rPr'][0].$};
    if(style.fontSize !== undefined) styleData.$.sz = style.fontSize * 100;
    if(style.fontBold !== undefined) styleData.$.b = style.fontBold ? 1 : 0;
    if(style.fontItalic !== undefined) styleData.$.i = style.fontItalic ? 1 : 0;
    if(style.fontUnderline !== undefined) styleData.$.u = style.fontUnderline ? 'sng' : 0;
    if(style.textColor) styleData['a:solidFill'] = [{'a:srgbClr': [{$: {val: style.textColor}}]}];
    if(style.fontFace){
        let fontFaceAttribute = [{$: {typeface: style.fontFace, pitchFamily: 0, charset: 0}}];
        styleData['a:latin'] = fontFaceAttribute;
        styleData['a:cs'] = fontFaceAttribute;
    }
    fld['a:rPr'][0] = styleData;
}

Here's how the function works.

const PPTX = require('nodejs-pptx');
let pptx = new PPTX.Composer();
await pptx.compose(async pres => {
  await pres.addSlide(slide => {
    setPageNumStyle(slide, {
        fontFace: 'Abadi', 
        fontSize: 15, 
        fontBold: true, 
        fontItalic: false, 
        fontUnderline: true, 
        textColor: '000000', 
    });
  });
});
await pptx.save(`./set-page-num-style.pptx`);

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

2 participants