REST API - Remove Page Break

Hi Guys,

How can I remove page breaks from a document with ASPOSE.Word?

Thanks!

@gbastian

Thanks for your inquiry. After the initial investigation, we logged a ticket WORDSCLOUD-1364 for further investigation and fulfilling your requirement.

Hi @tilal.ahmad, any news regarding this request? After appending files, ASPOSE adds section breaks to the document, which is separating the content of the appended doc in a new page. I would like to use continuous page break. Also another funny thing is that while appending docs and ASPOSE adds section breaks, the sections received their numbers, but they are not sequential. For example, section 7 is missing and the docs go from section 6 to 8, which breaks the config of the document. I would like to prevent ASPOSE to add section breaks to my new document. How can I do that? Thanks!

@gbastian

I’m afraid we have recently logged the issue and it is pending for investigation in the queue. We will notify you as soon as it is resolved.

For this requirement, to make the source document appear straight after the destination documents content, you can set the first section start of the source document to continuous and then append to the destination document. Hopefully, it will resolve your issue.

curl -X PUT "https://api.aspose.cloud/v4.0/words/Sections_source.docx/sections/0/pageSetup?folder=Temp" 
-H "accept: application/json" 
-H "Authorization: Bearer [Access_Token]" 
-H "Content-Type: application/json" 
-H "x-aspose-client: Containerize.Swagger" 
-d "{\"SectionStart\":\"Continuous\"}"	

If you still face the issue after the above suggestion, then please share your sample documents along with the problematic document and expected document as a zip file here. We will look into the requirement and will guide you accordingly.

Hi @tilal.ahmad,

The processes of removing or updating the section break did not work. All I need is a config/setting in the append API to do not add section break. None of my documents have it and the append proccess is adding it without my interventation.

Another issue I´m having is that when a document to be append to the source have a footnote, the proccess of copying the footer is stopped and no footer content is copied/applied to the appended document.

What could be this other issue?

@gbastian

As requested above, please share your sample input documents along with the current output document and expected document. You can create an expected document using MS Word. It will help us to understand your requirement exactly and address it accordingly.

@tilal.ahmad, as the documents are confidencial, can you please send me your email so I can forward you the docs?

Thanks!

@gbastian

I have sent you a private message with the details.

@gbastian

Thanks for sharing your sample documents. We have investigated the issue and noticed that your source documents have different page setup than destination document(1-template.docx). Otherwise above suggested solution should work.

1-templatex.docx(destination)
“Orientation”: “Portrait”,
“PageHeight”: 840.85,
“PageWidth”: 595.05,
“PaperSize”: “A4”,

2-Esc…docx(source)
Orientation": “Portrait”,
“PageHeight”: 842,
“PageWidth”: 595.35,
“PaperSize”: “A4”,

So, for your requirements, all the appending documents should have the same page setup and the first section of source documents has section start property with continuous value. So please set page setup of first sections of your source documents and then append with the destination document. It will resolve the issue.

{
  "SectionStart":"Continuous"
  "PageHeight": 840.85,
  "PageWidth": 595.05     
}

Hi @tilal.ahmad, I will try this settings on all documents and will let you know. Meanwhile, can you please confirm if it is possible to cumulate in on append request many source documents? Something like editing the body request to append multiple files with only one request:

{ “DocumentEntries”: [ { “Href”: “INTEGROMAT/Modelos_Topicos_AI/01.docx”, “ImportFormatMode”: “UseDestinationStyles” }, “Href”: “INTEGROMAT/Modelos_Topicos_AI/02.docx”, “ImportFormatMode”: “UseDestinationStyles” }, “Href”: “INTEGROMAT/Modelos_Topicos_AI/03.docx”, “ImportFormatMode”: “UseDestinationStyles” } ], “ApplyBaseDocumentHeadersAndFootersToAppendingDocuments”: true }

And if yes, can you provide me the write code for that?

Thanks!

@gbastian

Yes, you can append a list of document with a single API call.

{
  "DocumentEntries": [
    {
      "Href": "Temp/append/01.docx",
      "ImportFormatMode": "KeepSourceFormatting"
    },
{
      "Href": "Temp/append/02.docx",
      "ImportFormatMode": "KeepSourceFormatting"
    },
{
      "Href": "Temp/append/03.docx",
      "ImportFormatMode": "KeepSourceFormatting"
    },
{
      "Href": "Temp/append/04.docx",
      "ImportFormatMode": "KeepSourceFormatting"
    },
{
      "Href": "Temp/append/05.docx",
      "ImportFormatMode": "KeepSourceFormatting"
    },
{
      "Href": "Temp/append/06.docx",
      "ImportFormatMode": "KeepSourceFormatting"
    }
  ],
  "ApplyBaseDocumentHeadersAndFootersToAppendingDocuments": true
}

Hi @tilal.ahmad, it worked! I applyed the settings to all files and I was able to add the sectorstart as continues.

But I found a new issue. Everytime I add more text to the final document and a new page is added to the document created, because of the new content typed, the footer is not appearing.

Its important to remember that only destination file has header and footer and I’m using aspose setting to apply it to the source files and it works.

However, after the append proccess is done, when I need to manually type new text and the content sufficient to create a new page, the new page is only getting the header, but not the footer.

Any idea on how to solve this new issue?

Thanks!

@gbastian

Thanks for your feedback. It is good to know you are able to append the documents now.

I have tested the scenario with Append1-2.docx file that I shared with you via email, it is working fine as expected. While typing manually and moving to the third page both header and footer are added successfully. Can you please check the shared document and confirm?

@gbastian

We have good news for you, now you can remove page break from Word document using Aspose.Words Cloud 20.11 as following.

  1. Retrieve the collection of Paragraph nodes of document.
  2. Check if each Paragraph has the ParagraphFormat.PageBreakBefore property set and set it to false it if it does.
  3. Find the ControlChar.PageBreakChar (\f) character and remove this character.

Sample .NET Code:

            // fix  ParagraphFormat.PageBreakBefore
            var getParagraphsRequest = new GetParagraphsRequest(
                name:fileName,
                folder: remoteDataFolder);
            var paragraphs = this.WordsApi.GetParagraphs(getParagraphsRequest);
            foreach (var paragraph in paragraphs.Paragraphs.ParagraphLinkList)
            {
                var parPathStartIndex = paragraph.Link.Href.IndexOf(fileName) + fileName.Length + 1;
                var parPathEndIndex = paragraph.Link.Href.IndexOf("paragraphs");
                var parPath = paragraph.Link.Href.Substring(parPathStartIndex, parPathEndIndex - parPathStartIndex);

                var parIndex = paragraph.Link.Href.Substring(parPathEndIndex + 11, paragraph.Link.Href.IndexOf("?") - parPathEndIndex - 11);
                var updateFormatRequest = new UpdateParagraphFormatRequest(
                    dto: new ParagraphFormatUpdate
                    {
                        PageBreakBefore = false
                    },
                    nodePath: parPath,
                    index: int.Parse(parIndex),
                    name: fileName,
                    folder: remoteDataFolder);

                this.WordsApi.UpdateParagraphFormat(updateFormatRequest);
            }

            // remove \f characters
            var searchRequest = new SearchRequest(
                pattern: "\f",
                name: fileName,
                folder: remoteDataFolder);

            var searchResult = this.WordsApi.Search(searchRequest);

            var pageBreaks = searchResult.SearchResults.ResultsList
                .Where(p => (p.RangeStart.Node is RunLink) && ((RunLink)p.RangeStart.Node).Text == "\f").ToList();

            var runId = pageBreaks[0].RangeStart.Node.NodeId;

            var removeRangeRequest = new RemoveRangeRequest(
                rangeStartIdentifier: "id" + runId,
                name: fileName,
                folder: remoteDataFolder);
            this.WordsApi.RemoveRange(removeRangeRequest);

            var stats = this.WordsApi.GetDocumentStatistics(
                new GetDocumentStatisticsRequest(name: fileName, folder: remoteDataFolder));