PHPWord: Insert page break and set margin and page orientation using Laravel 4

橙三吉。 提交于 2020-01-06 14:10:04

问题


I'm using PHPOffice/PHPWord, and I have a MySQL Database with a table named trials. It contains 2 columns id and name. Both columns are VARCHAR(255). There are several rows such as below:

id | name
---+-----------
A1 | Avatar
B1 | Browser
C1 | Calculator
A2 | Align

The query that I use is SELECT * FROM trials ORDER BY id ASC

What I'm trying to do is Make a DOC file and add a new page for each row with (1 page for 1 id and 1 for name).

How can I insert a page break between rows?

Also, how can I set the margin and page orientation?

As an example I want the content of mytrial.doc as below:

Page 01
    A1 - Avatar
Page 02
    A2 - Align
Page 03
    B1 - Browser
Page 04
    C1 - Calculator

I use Laravel 4 as my framework.

PS: I already read the following:

  • how to remove section pagebreak in phpword

  • sample paragraph pagination


回答1:


  1. You have 2 options to insert a page break

    • pageBreakBefore
    • addPageBreak()

      $section->addPageBreak();

  2. Set the margin and page orientation via Styles

    • margin

    $section = $phpWord->addSection( array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) );

    • orientation

    $section= $phpWord->addSection(array('orientation' => 'landscape'));



来源:https://stackoverflow.com/questions/29651259/phpword-insert-page-break-and-set-margin-and-page-orientation-using-laravel-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!