Forum


Replies: 11   Views: 2302
Setting margins with drupal plugin
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by gmakstutis  · 22-05-2019 - 07:34

Hi,

I'm using the plugin for Drupal 8, and I'd like to modify the margins of my output. Is there a way to do this?

I'm happy to 'hard-code' this, as we are only outputting a specific type of document and the margins will always be as we set them.

Thanks

Posted by admin  · 22-05-2019 - 07:49

Hello,

You can use the modifyPageLayout method to change page layouts: margins, columns, orientation... The addSection method also allows setting margins and other section properties when creating them.

If you need to do these changes using HTML, you'd need to use HTML Extended, available in Premium licenses.

Regards.

Posted by gmakstutis  · 22-05-2019 - 08:14

Hi,

Thanks for the additional info. I am using the Premium, but I can't see any examples in the documentation. Can you give an example of how to change output page margins in the HTML?

Thanks

Posted by admin  · 22-05-2019 - 08:18

Hello,

Your account has an Advanced 9.0 license, not a Premium license (https://www.phpdocx.com/pricing). You can see the license name you are using on MY PHPDOCX page after login.

If you are using a Premium license please send to contact[at]phpdocx.com the username or e-mail of the account that purchased it.

Regards.

Posted by gmakstutis  · 22-05-2019 - 08:30

Ah, didn't realise I was on Advanced. I've just upgraded the license, so should have the HTMLextended available. So, can you point me to an example of how to adjust page margins in HTML?

Many thanks

Posted by admin  · 22-05-2019 - 08:57

Hello,

To generate the sample, please update the topic with the following information:

· You need to change the margins of the current DOCX section or you need to generate a new section with new margins after the current DOCX section.

· If you are using the classic or namespace package.

Please note that to use the Premium license you need to download a new package from MY PHPDOCX page.

Regards.

Posted by gmakstutis  · 22-05-2019 - 09:02

I'm using the namespace version (Drupal 8 plugin). I've downloaded the Premium package and reinstalled.

I need to change the margins for the entire document (current DOCX section) being output.

Ideally, I'd like:

Page size set to: A4

Margins:

  • Top: 1.5cm
  • Bottom: 1.5cm
  • Right: 1.9cm
  • Left: 1.9cm

Thanks for your help.

Posted by admin  · 22-05-2019 - 09:25

Hello,

We are generating the sample script, we'll send it to your e-mail.

Regards.

Posted by admin  · 22-05-2019 - 09:55

Hello,

Please check your e-mail, we have sent a sample script and other files.

Regards.

Posted by gmakstutis  · 22-05-2019 - 10:47

 

Hi,

I've received the samples and am trying to get this to work. I've replaced the class files that you sent.

I have embedded:

<phpdocx_modifypagelayout data-paperType="A4" data-marginTop="850" data-marginRight="1077" data-marginBottom="850" data-marginLeft="1077" />

in the drupal html.html.twig template file, so that this gets added to the page. 

I note that the sample includes:

$docx->embedHTML($html, array('useHTMLExtended' => true));

However, as I'm working through the Drupal module, I don't see how I can pass this code. Is there a way to make useHTMLExtended default to true for my entire site?

Again, many thanks for your assistance

 

Posted by admin  · 22-05-2019 - 10:54

Hello,

We recommend you to change the Drupal 8 plugin. In plugins/drupal-8/node-to-docx/src/NodetoDocxHandler.php you can find the following method:

private function generateDocxFromHtml($html, $file_name_output) {

In this method, instead of:

$docx = new \Phpdocx\Create\CreateDocx();
$docx->embedHTML($html);

You can use:

$docx = new \Phpdocx\Create\CreateDocx();
$docx->embedHTML($html, array('useHTMLExtended' => true));

to enable using HTML Extended.

Regards.

 

Posted by gmakstutis  · 22-05-2019 - 11:13

You folks are the best!!!

I've got it working, thanks to you.

A few tips for anyone else trying to do something similar.

I have had best results by adding: 

<phpdocx_modifypagelayout data-paperType="A4" data-marginTop="850" data-marginRight="1077" data-marginBottom="850" data-marginLeft="1077" />

to the top of the node.html.twig (adjusting for whatever page size and margins you need).