Merge PDF based on size using Aspose

As I am new to Aspose, I need help in below case.
I want to merge multiple PDF into 1 PDF using Aspose, I can do it easily but the problem is, I want to limit the PDF size to 200MB.
That means, If my merged PDF size is greater than 200MB, then I need to split the PDF into multiple PDF. For Example, If my merged PDF is of 300MB, then first PDF should be of 200MB and second one PDF should be 100MB.

Main problem is, I am not able to find the size of the document in below code. I am using below code.

        //Merge PDF one by one
       Document destinationPdfDocument = new Document();
            Document sourcePdfDocument = new Document();

        for (int i = 0; i < filesFromDirectory.Count(); i++)
        {
            if (i == 0)
            {
                destinationPdfDocument = new Document(filesFromDirectory[i].FullName);
            }
            else
            {
                // Open second document
                sourcePdfDocument = new Document(filesFromDirectory[i].FullName);

                // Add pages of second document to the first
                destinationPdfDocument.Pages.Add(sourcePdfDocument.Pages);


                //** I need to check size of destinationPdfDocument over here to limit the size of resultant PDF**

            }
        }

        // Encrypt PDF
        destinationPdfDocument.Encrypt("userP", "ownerP", 0, CryptoAlgorithm.AESx128);

        string finalPdfPath = Path.Combine(destinationSourceDirectory, destinatedPdfPath);

        // Save concatenated output file
        destinationPdfDocument.Save(finalPdfPath);

Other way of merging PDF based on size also be appreciated.
Thanks in Advance

@Trusha

Thanks for contacting support.

I am afraid that there is no direct way to determine PDF file size before saving it physically. Therefore, we have already logged a feature request as PDFNET-43073 in our issue tracking system and product team has been investigating the feasibility of the feature. As soon as we have some significant updates regarding availability of the feature, we will definitely inform you. Please spare us little time.

However, as a workaround, you may save document into a memory stream and place a check on the size of that memory stream, whether it exceeds from your desired PDF size or not. Please check following code snippet, where we have generated PDFs with desired size of 200MBs:

Document destinationPdfDocument = new Document();
Document sourcePdfDocument = new Document();

var filesFromDirectory = Directory.GetFiles(dataDir, "*.pdf");

for (int i = 0; i < filesFromDirectory.Count(); i++)
{
  if (i == 0)
  {
    destinationPdfDocument = new Document(filesFromDirectory[i]);
  }
  else
  {
   // Open second document
   sourcePdfDocument = new Document(filesFromDirectory[i]);
   // Add pages of second document to the first
   destinationPdfDocument.Pages.Add(sourcePdfDocument.Pages);
   //** I need to check size of destinationPdfDocument over here to limit the size of resultant PDF**
   MemoryStream ms = new MemoryStream();
   destinationPdfDocument.Save(ms);
   long filesize = ms.Length;
   ms.Flush();
   // Compare the filesize with MBs
   if (i == filesFromDirectory.Count() - 1)
   {
     destinationPdfDocument.Save(dataDir + "PDFOutput_" + i + ".pdf");
   }
   else if ((filesize / (1024 * 1024)) < 200)
     continue;
   else
   {
      destinationPdfDocument.Save(dataDir + "PDFOutput_" + i.ToString() + ".pdf");
      destinationPdfDocument = new Document();
   }
 }
}