Certificate positioning co-ordinates

Certificate positioning co-ordinates

by Nicola Fern -
Number of replies: 5

Hi

I've designed a new certificate for our moodle site, but am struggling with amending the position of the elements. I have no graphical elements to change, as I've incorporated them all into the background image, and that's working fine.

I need to adjust the text to be left aligned, and change the x and y co-ordinates for the text positions.

I've managed the left alignment, but for the life of me I can't figure out what the coordinate units are - can anyone enlighten me?

I assumed it was pixels, with a 0,0 origin of top left, but it seems definitely not - I laid everything up in illustrator and used the co-ordinates from that for my first try but it all ended up way lower down than I was expecting, and in ways that don't make a lot of sense to me.

I was working off an image at 842 x 595 (A4 at 72DPI), so from a pixel point of view it should have been screen accurate.

Everything I've seen on other forums, the manual etc just says to adjust the co-ordinates to move the text, but it doesn't say how you work out what they should be except by trial and error...e.g. this is from the manual:

"Changing the location of text is done by using code to set the x,y position on the page. The "x" is the distance from the left margin and the "y" is the distance from the top. All the certificate type code files start off with defining x,y points for various strings or images."

Unfortunately, trial and error is not an option for me as we don't manage our site installation directly, so everytime I want to try it I have to email it to a guy and he uploads it. I need to be able to work it out with more precision!

Many thanks

Nicola

Average of ratings: -
In reply to Nicola Fern

Re: Certificate positioning co-ordinates

by Jefferson Bien-Aime -
Hi Nicola,

(0,0) is the top middle. I don't even know where to set new coordinates. if you want to see the function, go to the lib.php file on the certificate module and you will certificate_print_text method. Once you understand it clearly go to the certificate.php file in certificate/type/certificate type. It could be A4_embedded, non_embeddeed, etc..  Arround line 90. You can see the text. To move text, just add number, $x+20, $y +20.

My only problem, is that I want to align the date to the left. Can you tell me how did you do it?
In reply to Jefferson Bien-Aime

Re: Certificate positioning co-ordinates

by Jefferson Bien-Aime -

Found it replace C that stands for Center to L that stands for Left. And once you set it, the origin (0,0) changes


certificate_print_text($pdf, $x, $y + 87, 'C', 'Helvetica', '', 20, $course->fullname);

In reply to Jefferson Bien-Aime

Re: Certificate positioning co-ordinates

by Nicola Fern -

Yes, it's changing the 'C' to 'L' that left aligns; and 'R' would right align it.

I understand where to change the coordinates, it's the unit measure I'm struggling with.

Unfortunately, I don't have access to the files you mentioned but I think I get the principles OK.

Here is an example of how I've amended it:


certificate_print_text($pdf, $x, $y + 36, 'L', 'Helvetica', '', 20, get_string('certify', 'certificate'));


I've also changed the variables at the top of the page to adjust where the start point is, but without knowing the unit measure or 0,0 position it's very hard to do this with any kind of accuracy.

In reply to Nicola Fern

Re: Certificate positioning co-ordinates

by Dave Balch -

Hi,

The units are defined in the certificate template, when instantiating the PDF object. E.g. for .mod/certificate/type/A4_embedded/certificate.php, there's the line:

$pdf = new PDF($certificate->orientation, 'mm', 'A4', true, 'UTF-8', false);

The second argument ('mm' - millimetres) sets the units. Your certificate probably uses the same.

HTH,
Dave.

In reply to Dave Balch

Re: Certificate positioning co-ordinates

by Nicola Fern -

Hi Dave

Thanks so much, I totally should have seen that! 

I think what confused me is that the certificate customising help page (https://docs.moodle.org/30/en/Certificate_customizing) mentions x,y distances, image sizes in pixels, and 'lines' (without specifying what those are either) as in: "Say we want to move it to the left to the 100 position from 130 and up to the 435 line from the 440 line."

It would perhaps be good if this could be edited by someone to point this out more clearly.

Thanks again!

Nicola