Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Sep 21, 2022 9:58 pm

I see the examples that break into multiple PDF's by page numbers (i.e. 1-10, 11-20) but is there a way to check the file size and break into multiple files if the file is greater than say 10 Mb?

colinmhart
 
Posts: 14
Joined: Thu Aug 18, 2022 7:19 pm

Thu Sep 22, 2022 8:47 am

Hello,

Thanks for your inquiry.
For your requirement, you can refer to the following code.
If you have any issue, just feel free to contact us.

Code: Select all
using Spire.Pdf;
using System;
using System.IO;


namespace FileSize
{
    internal class Program
    {
        static void Main(string[] args)
        {

            string filePath = @"C:\Users\Administrator\Desktop\8-29测试文件\Original.pdf";

            //load the pdf document
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(filePath);

            //Get the file size of pdf document
            FileInfo fileInfo = new FileInfo(filePath);
            double filesize = fileInfo.Length / 1024.0/1024.0;
            if (filesize > 0.1)
            {
                String pattern = "SplitDocument-{0}.pdf";
                //Split document
                pdf.Split(pattern);

                pdf.Close();
            }
        }
    }
}


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 948
Joined: Tue Mar 08, 2022 2:02 am

Thu Feb 09, 2023 8:32 pm

thanks for the reply. Can I add a bit more onto this
I need to make sure all the PDF's are less than 10MB
so if I 31MB file, I need Spire to break that into 4 files so each PDF is < 10 MB
the max would be 100MB, so how could I make it so that it would detect the file size and then break it the number of files needed to be < 10 MB per PDF?

colinmhart
 
Posts: 14
Joined: Thu Aug 18, 2022 7:19 pm

Fri Feb 10, 2023 9:55 am

Hello,

Thanks for your feedback.
For your requirement, you can split the entire document into multiple one-page documents and then merge the documents. For example, if the sum of document1’size and document2’size after splitting don’t more than 10mb, you can merge document1 and document2 into a new document, and so on.
For how to merge Pdf file, you can refer to the help document from the following link:
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html

Sincerely,
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 948
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF