PHP API: Add a Paragraph with page break

I’d like to add a paragraph with the PageBreakBefore property set to true.

The API method for this:

has a ParagraphInsert parameter - but this only has one property ‘text’.

How can I add a new paragraph and set all the formatting options at the same time?

@FFSPUD

I am afraid that currently you can not set the formatting properties while adding a new paragraph to a Word document. However, you can update the formatting accordingly later using the following API methods. So you can achieve your requirement in two API calls.

POST ​/words​/{name}​/paragraphs​/{index}​/format Updates the formatting properties of a paragraph in the document node.

​PUT /words​/online​/put​/paragraphs​/{index}​/format Updates the formatting properties of a paragraph in the document node.

Hi Tilal

Thanks for your response.

I’m trying the code but I can’t find in the documentation what $index refers to:

    /*
     * Initializes a new instance of the UpdateParagraphFormatRequest class.
     *
     * @param string $name The filename of the input document.
     * @param int $index Object index.
     * @param \Aspose\Words\Model\ParagraphFormatUpdate $paragraph_format_dto Dto for paragraph format update.
     * @param string $node_path The path to the node in the document tree.

Am I right in thinking that if I have a single page doc with two paragraphs in it, the first paragraph will have a $node_path of 0.0.1 and the second will have a $node_path of 0.0.2?

What then does $index refer to?

If I want to format the second paragraph so that it has page_break_before = true what should I use for $node_path and $index?

@FFSPUD

Please note that the node path is the parent node path of paragraphs. For example, node_path can be “sections/0” and index would be paragraph index starting from 0. If you want to update the second paragraph of section 1 then you will use the values node_path is “sections/0” and index is “1”.