heavysixer / node-pptx

Generate PPTX files on the server-side with JavaScript.
MIT License
161 stars 46 forks source link

How to position text? #58

Closed rajatkhare619 closed 4 years ago

rajatkhare619 commented 4 years ago

I'm trying to figure out how to position the text using the x and y values

await pres.getSlide('slide3')
            .addText(text => {
                text.value('val')
                    .x(10)
                    .y(50)
            })

Is there a way by which I can know exactly what values to pass for x and y? For example, by opening an existing ppt and getting the position of a similar element and then passing those values in the function. Or do I have to do this by trial and error?

gregdolley commented 4 years ago

@rajatkhare619: The x and y coordinates are in pixels. Unfortunately, there's no programmatic way of getting the x/y pixel coords of objects that come from an externally loaded pptx file. You can however calculate it manually - when viewing the properties of any widget in PowerPoint, take the left/top position values in inches, and simply multiply by 72 to get pixels. For example, a widget at:

Left: 1.5" Top: 2"

Will be the following in pixels:

X = 1.5 72 = 108px Y = 2 72 = 144px

Hope this helps!

rajatkhare619 commented 4 years ago

Thanks @gregdolley!, I'll try that.