At most 4 elements (for any collection) can be viewed in evaluation mode- PageBreak isn't working

I am using a following code to add a page break after specific text fragment

        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(Server.MapPath("test.pdf"));
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(text);

        pdfDocument.Pages.Accept(textFragmentAbsorber);
        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
        foreach (TextFragment textFragment in textFragmentCollection)
        {
                Aspose.Pdf.Document outputDoc = new Aspose.Pdf.Document();
                PdfFileEditor fileEditor = new PdfFileEditor();
                fileEditor.AddPageBreak(pdfDocument, outputDoc, new PdfFileEditor.PageBreak[] {
                    new PdfFileEditor.PageBreak(textFragment.Page.Number, textFragment.Rectangle.URY - 1)
                });
                pdfDocument.Save(Server.MapPath("test.pdf"));
        }

I am getting following error “At most 4 elements (for any collection) can be viewed in evaluation mode”

Not able to add PageBreak.

Am i doing something wrong, please guide?

It looks like interesting. Though I don’t have better idea of it. But I would like to learn. Thanks!

@RafaelMalo, @abyjoshi2891

The error message you are facing is due to trial version limitation of the API. In order to evaluate API without any restrictions, please try to use a valid license or consider applying for a 30-days free temporary license. In case you still face any issue, please feel free to let us know.

Thanks @asad.ali i got the temporary license now.
Error is fixed, however i am not able to put a page break

Do you have any idea, about how to add PageBreak in existing PDF?

@abyjoshi2891

Would you kindly share a sample PDF document with us so that we can test the scenario in our environment and address it accordingly.

test.pdf (223.9 KB)

I have attached the PDF,
I am trying to PageBreak after certain headings, like “Heading level 1” and “Heading level 2”.
My heading title for PageBreak are fix, however the size of content between headings varies

@abyjoshi2891

We were able to notice the issue in our environment that AddPageBreak method was not generating correct result. We have logged an issue as PDFNET-47854 in our issue tracking system for the sake of further investigation. We will look into details of it and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Thanks Asad.

Can we achieve the same using #$NP with Aspose.Pdf.Facades namespace
Or using IsInNewPage Property of TextFragment

Or is there any quick fix for this by the time we can use?

Thanks again for your support.

Adding more info:
I have HTML Content, which i am converting into PDF using Aspose.Pdf
Here is a code below:

Aspose.Pdf.HtmlLoadOptions options = new Aspose.Pdf.HtmlLoadOptions();
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(Server.MapPath("Article.html"), options);
pdfDocument.Save(Server.MapPath("test.pdf"));

I will change my code approach, if required.
PDF file is already with you

@abyjoshi2891

We tested the scenario using following code snippet with your PDF document and it generated a result where all text was upside down in resultant PDF.

Document doc = new Document(dataDir + "Pagebreaktest.pdf");
var finder = new TextFragmentAbsorber("Heading level 1");
doc.Pages.Accept(finder);
TextFragment text = finder.TextFragments[1];
Facades.PdfFileEditor fileEditor = new Facades.PdfFileEditor();

fileEditor.AddPageBreak(dataDir + "Pagebreaktest.pdf", dataDir + "PageBreakWithDestPath_out.pdf", new Facades.PdfFileEditor.PageBreak[]
{
  new Facades.PdfFileEditor.PageBreak(1, text.Position.YIndent)
});

Please note that same code snippet worked fine with one of our sample PDF documents. May be you can try it with some other PDF file at your side. The issue has been logged for your particular PDF file and we will surely inform you as soon as it is resolved.

Regarding HTML to PDF conversion, following CSS property can put Page Break inside PDF if it is used in the source HTML:

page-break-before: always;

In case of any further inquiry, please feel free to let us know.

Thanks Asad

page-break-before: always;

Solution works for me

@abyjoshi2891

It is good to know that suggested solution worked for you. Please keep using our API and in case you need further assistance, please feel free to let us know.

HI team, any update? Is there any ETA for these items?

@abyjoshi2891

As the issue was logged under free support model, we are afraid that it is not resolved yet and it has low priority. We will surely inform you as soon as we have some definite updates regarding its resolution. Please spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-47854) have been fixed in Aspose.PDF for .NET 23.9.