Save pdf documet into stream

Hi
I’m using Aspose total and I have encountered an issue.
I am trying to save a very large pdf table and save it into a stream and the function _doc.ProcessParagraphs() gets stuck (using smaller table works), do you have any suggestions .

_doc.ProcessParagraphs();
_doc.OptimizeResources(new Document.OptimizationOptions()
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
AllowReusePageContent = true,
RemoveUnusedStreams = true,
UnembedFonts = false,
});
_doc.Save(Stream);

        _doc.Dispose();

Thanks for your help

@amdiei

Could you please share sample source PDF document for our reference? We will test the scenario in our environment and address it accordingly.

Its a PDF which I build dynamically from table (pdf Aspose table) so there is no source document, and after creating the the table I am trying to save it into file stream
this is a sample code for the table creation
_doc = new Document();
Page _page = _doc.Pages.Add();
foreach (IList row in table)
{
Row tableRow = pdfTable.Rows.Add();

            foreach( FieldDescriptor cell in row)
            {
                Cell tableCell = tableRow.Cells.Add();
                tableCell.VerticalAlignment = VerticalAlignment.Top;
                try
                {
                    BaseParagraph element = _fieldElementCreatorProxy.GetFieldElementCreator(cell)?
                            .CreateElement(cell, (int)alignment);

                    if (element == null)
                    {
                        BaseParagraph emptyElement = PdfReportHelper.EmptyPhrase;
                        tableCell.Paragraphs.Add(emptyElement);
                        continue;
                    }
                    tableCell.Paragraphs.Add(element);
                    tableCell.IsWordWrapped = true;
                }
                catch (Exception ex)
                {

                    Logger.Error(ex, $"Failed to process cell element");

                    BaseParagraph emptyElement = PdfReportHelper.EmptyPhrase;
                    tableCell.Paragraphs.Add(emptyElement);
                }
            }

        }

        _page.Paragraphs.Add(pdfTable);

hope its will help

@amdiei

Can you please provide the working sample example and source PDF file (If there is any) that we may use on our end to try to reproduce the issue. The sample code that you have shared has many unknown or undefined segments. Please share the working example that we may use on our end to proceed further.

image.png (146.7 KB)

      _page = AddPage();//func witch return Page from the document
        AddHeader(Settings);
        HorizontalAlignment alignment =HorizontalAlignment.Left;

        AddTableTitle(table, _page);
        List<TableHeader> tableHeaders = table.Headers.ToList();

        Table pdfTable = new Table
        {
            Margin = new MarginInfo(2f, 2f, 2f, 3f)
        };

        pdfTable.DefaultCellPadding = new MarginInfo(2f, 2f, 2f, 3f);
        float[] widths = tableHeaders.Select(th => (float)th.Width).ToArray();

        SetTableConfigurations(pdfTable, alignment, widths);

        AddTableHeader(tableHeaders.Select(th => th.Title), pdfTable);

        foreach (IList<FieldOutputDescriptor> row in table)//FieldOutputDescriptor is string
        {
            Row tableRow = pdfTable.Rows.Add();

            foreach (FieldOutputDescriptor cell in row)
            {
                Cell tableCell = tableRow.Cells.Add();
                tableCell.VerticalAlignment = VerticalAlignment.Top;
                try
                {
                    BaseParagraph element = _fieldElementCreatorProxy.GetFieldElementCreator(cell)?
                            .CreateElement(cell, (int)alignment);

                    if (element == null)
                    {
                        BaseParagraph emptyElement = PdfReportHelper.EmptyPhrase;//retunrnig BaseParagraph 
                        tableCell.Paragraphs.Add(emptyElement);
                        continue;
                    }
                    tableCell.Paragraphs.Add(element);
                    tableCell.IsWordWrapped = true;
                }
                catch (Exception ex)
                {

                    Logger.Error(ex, $"Failed to process cell element");

                    BaseParagraph emptyElement = PdfReportHelper.EmptyPhrase;
                    tableCell.Paragraphs.Add(emptyElement);
                }
            }

        }

        _page.Paragraphs.Add(pdfTable);
       _doc.Save(Stream);
    }

this is the code for creating the table and add it to the document (the _page is part of the document)
the code stuck in _doc.Save(Stream) for large table(over 200k row).

hope its will help

@amdiei

Unfortunately, we are unable to use the code as it is or even make assumptions in the sample code by our selves to reproduce the actual scenario that is happening on your end. We really ought to investigate and proceed further with the investigation but need a working sample code along with source file that is reproducing issue on your end and that we may try on our end. For reference, I have attached the image showing missing declarations in the code.

image.png (312.9 KB)

can we set a call or something? in google meetings

@amdiei

I regret to share that may not be possible. We need to investigate the issue locally on our end and in case, it is reproduced then we will have to log that in our issue tracking system for investigation and resolution. Therefore, I would request you to please share the workable sample project along with source file reproducing issue with us. If you have any concerns sharing the information in this thread then you can share that privately with us by following the guidelines below.