How to move content to next page in PDF based on delimiter

Hello Team,

Attached is the document template I am using to create a word document, after which it is converted to PDF.

document.docx (17.7 KB)

My input request is as follows:

{
    "printerQueue": "<<printer name is passed here>>",
    "printLineData":
    [
        {
            "printLine": "   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "           FIRSTNAME  LASTNAME                         108025942304     TS70CBZ "
        },
        {
            "printLine": " "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                           "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "     Continue to next page 2                                                             "
        },
        {
            "printLine": "           STATIONFOUROONE  ADDRESSOVERRIDE                108022041378     NC     "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                   "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "                                                                "
        },
        {
            "printLine": "      "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                                              "
        },
        {
            "printLine": "                      "
        },
        {
            "printLine": "                      "
        },
        {
            "printLine": "                      "
        },
        {
            "printLine": "    "
        },
        {
            "printLine": "                                        "
        },
        {
            "printLine": "                        "
        },
        {
            "printLine": "                        "
        }                       
    ]
}

I would want to always move the contents/text to the next page after the line “Continue to next page” which is part of request object.

Is there an aspose function to help with this. Thank You…

@manikantakondepati You can use conditional block to achieve this. Please see the following template syntax:

<<foreach [items in PrintLineData]>><<[items.PrintLine]>><<if [items.PrintLine.Contains(“next page”)]>><<[“\f”]>><<else>><<[“\r\n”]>><</if>><</foreach>>

@alexey.noskov

I have tried it but the content is not moved to the next page. Any advice.

Thank You,
Mani K.

@manikantakondepati The condition works as expected on my side and page break is inserted. I used the following simple code for testing:

Document doc = new Document(@"C:\Temp\document.docx");

JsonDataSource data = new JsonDataSource(@"C:\Temp\data.json");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, data);

doc.Save(@"C:\Temp\out.docx");

Modified template, data and output document are attached. docs.zip (25.8 KB)

@alexey.noskov Thanks for the quick response, I did download the docs.zip folder and upon looking at the out.docx, I noticed there is no page break. Can you please take a look at it again.

out.docx (12.6 KB)

Thank You…

@manikantakondepati Page break is there. Simply remove whitespaces and you will notice the page break is there. See the screenshot image.png (3.7 KB)

@alexey.noskov
I tried the syntax you provided and its throwing the below error,

$exception|{“An error has been encountered while evaluating the expression or statement ‘items.PrintLine.Contains(“next page”)]>’. Cannot create boxed ByRef-like values.”}
2021-12-01_13-10-37.png (49.0 KB)

Just FYI, We are using .net core 5.0.303.

@manikantakondepati The problem is caused by reflection optimization option, which was disabled for .NET Standard in the previous version of Aspose.Words. The problem is already resolved in the current codebase and the fix will be available soon. As a temporary solution you can disable reflection optimization.

Document doc = new Document(@"C:\Temp\document.docx");

ReportingEngine.UseReflectionOptimization = false;
JsonDataSource data = new JsonDataSource(@"C:\Temp\data.json");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, data);

doc.Save(@"C:\Temp\out.docx");

@alexey.noskov That worked like a charm, thank you…

The issues you have found earlier (filed as WORDSNET-22979) have been fixed in this Aspose.Words for .NET 21.12 update also available on NuGet.