Question

I would like to center a text in an output PDF

  • 19 March 2018
  • 6 replies
  • 24 views

Badge

Hi,

I created a red colored box with PDFStyler and PDFPageFormatter.

Now I would like to center a text in front of this box.

Any idea ?

 

How FME computes text position ?


6 replies

Userlevel 5
Badge +25

Since you use 2 different boxes in the PDFPageFormatter the only way you can center the text on the red box is by moving the Title box in the PDFPageFormatter., you'll probably need a bit of trial and error to get it to the right position (and it will depend on the length of the text). However, that's probably actually the best way to do it...

When it comes to PDF writing FME will regard everything that you feed in to one PDFPageFormatter input port as if it's within the same coordinate space. Every PDFPageFormatter input port represents one single "map"

Badge

And if I'm using only 1 box, you see a way to obtain a red box with center title inside ?

Userlevel 5
Badge +25

And if I'm using only 1 box, you see a way to obtain a red box with center title inside ?

I changed the box to 0,0 - 100,10 and the point to 45,4

 

 

This at least puts the title visually in the center of the box. Unfortunately the text position is the lower left point of the text so you'll have to position that a little to the left and below the actual center of the box, and how far depends on the length of the text as well as the font size you've specified. So those coordinates I used for the point will have to be changed if you decide to use a longer title and/or different font size.

 

 

I also set the maintain aspect ratio parameter to yes.

 

 

Badge

Ok I see. Thanks.

So unfortunately we are forced to use "visual" positions to place texts. :-(

Badge +3

@mathieu_ambrosy

Get insertionpoint of text.

Merge the box or it's centerpoint to it. Use centerppoint to affine (move) the text.

(Set the pdf-opacity value for that box to 0 (if u use a box).)

Make the pdf properties of the title box same size as that of the Polygon.

There is a post I made to do similar to jpegs, but it just a bit of calculation as well.

Badge +3

Here is the length I went trough in some of my more pdf assembling workbenches, just to get a title text centered in a box.

The only thing that I have not managed to control (yet) is the relative size of text dependent on font.

Definitely something for safe to improve upon..

Reply