Flatten Fails with long documents

In an attempt to work around the last issue, I have replaced graphs with polyline annotations to draw lines, then flattening the document so that they’re non-interactive. This works fine except that with documents over a certain length the Document.Flatten() call stops working.

            Aspose.Pdf.Document pdf = new Document("test.pdf");

        PdfContentEditor editor = new PdfContentEditor();
        editor.BindPdf(pdf);

        LineInfo lineInfo = new LineInfo
        {
            VerticeCoordinate = new[] { 20f, 50f, 200f, 600f },
            Visibility = true,
            LineColor = System.Drawing.Color.Black,
            LineWidth = 3
        };
        editor.CreatePolyLine(lineInfo, 1, new System.Drawing.Rectangle(1, 1, 3, 1), "");

        pdf.Flatten();
        pdf.Save("output.pdf");

This will fail when the test document has more than 51 pages, but succeeds when it has 35 (I haven’t narrowed down to the exact page number that triggers it)

Test documents:
51 pages: test.pdf (201.2 KB)
35 pages: test2.pdf (191.5 KB)

@ShaneWS

Thank you for contacting support.

We have worked with the data shared by you but we have not been able to reproduce the issue with Aspose.PDF for .NET 18.6. We have attached generated files for your kind reference.

Please try using latest version of the API and then share your kind feedback with us.

Hi @Farhan.Raza,
The files you have posted demonstrate the issue. In the 51Pages_18.6.pdf file, the line is an interactive polyline annotation that the user can manipulate, while in 35Pages_18.6.pdf the line has been flattened and can’t be manipulated.

@ShaneWS

Thank you for elaborating it further.

We have been able to observe the issue. A ticket with ID PDFNET-45052 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

Until the ticket is investigated, you may add a line on a PDF page by using below code snippet to draw a line on a PDF page:

        //Load a document
        Document document = new Document("Test.pdf");

        //Specify starting and ending coordinates for a line
        Aspose.Pdf.Point start = new Aspose.Pdf.Point(100, 100);
        Aspose.Pdf.Point end = new Aspose.Pdf.Point(200, 200);

        // Create Line annotation object
        Aspose.Pdf.Annotations.LineAnnotation AsposeLineAnn = new Aspose.Pdf.Annotations.LineAnnotation(document, start, end);

        //Add the annotation
        document.Pages[1].Annotations.Add(AsposeLineAnn);

        //Set different properties
        AsposeLineAnn.Color = Aspose.Pdf.Color.Green;
        AsposeLineAnn.Border = new Aspose.Pdf.Annotations.Border(AsposeLineAnn) { Width = 2 };

        AsposeLineAnn.Flatten();

        // Save PDF file
        document.Save("LineTest.pdf");

We are sorry for the inconvenience.

Thanks. I gave that a try, but it seems to have the same issue. Calling AsposeLineAnn.Flatten(); doesn’t work with either the short document or the long one, and calling document.Flatten() works with the short document but not the long.

output.pdf (191.9 KB)

@ShaneWS

Thank you for your kind feedback.

We have recorded the information under logged ticket. We will let you know as soon as some significant progress is made towards resolution of this ticket. We appreciate your patience in this regard.

@ShaneWS

Would you please try to use the latest version of the API as we believe that it is not reproducible with the latest versions.