Unable to handle 200 MB PDF Files

We are getting “because it is being used by another process.” issue with the following code. Please check and give solution ASAP.

string filePathooo = @“F:\Sample Pdf files\validated Files\LargeSizeFiles\414mb.pdf”;
using (Aspose.Pdf.Document documentFast = new Aspose.Pdf.Document(filePathooo))
{
if (documentFast.IsLinearized == false)
{
documentFast.IsLinearized = true;
}
documentFast.Save(filePathooo);

}

@kranthireddyr

Thank you for contacting support.

Please make sure that the PDF file you are working with, is not open in any other program or application, any PDF reader for instance. Please also ensure using Aspose.Pdf for .NET 18.1 in your environment. In case the issue persists, please share source PDF file with us, by uploading it to any file sharing server, Google Drive, Dropbox etc, so that we may investigate further to help you out.

Thank you Farhan for the update.

We have tested with Latest Aspose PDF for .Net 18.1 also. Please check with any file more than 250 MB.

Thanks in advance

Please download PDF File from the following link

@kranthireddyr

Thank you for sharing requested data.

I have worked with the data shared by you and have been able to notice the behavior of API as mentioned by you. It is not really an issue as the API can not simultaneously read from and write to a same file in parallel. You need to change the name of generated document to avoid such a problem, append some string with the file name, for instance.

I hope this will clarify the concept. Please feel free to let us know if you need any further assistance.

Thank you Farhan for the update.

In our application we have to change pdf properties for every PDF file, if we create new file for every pdf file it will create big problem for us. Without creating new file please provide us any solution.

Thanks in advance

One more thing we don’t have any issues with the below 200 MB files using above code.

@kranthireddyr

I would like to share with you that only the file having more than 200MB size reproduces this issue because smaller files are completely loaded in memory and Document Object Model (DOM) of Aspose.PDF before the API starts writing it on the disk. Therefore, it is necessary to have separate documents while working with bigger files. To avoid this issue, you may delete the former file by using [File.Delete] method in your program.

I hope this will be helpful. Please let us know if you need any further assistance.

For each file we will perform different operations(properties,bookmarks and Hyperlinks update). So every time we cannot create new file and we cannot delete former file. We will get performance issues if we follow like this.

We have to support up to 400 MB files , so please give any solution to load PDF file into memory up to 400 MB. We have to fix this issue ASAP, other wise it will be big problem for us. Please take this as high priority

@kranthireddyr

We are investigating this scenario in our environment. Please spare us little time and we will get back to you, with our findings, soon.

I would like to share with you that we were unable to delete file as well, So please find solution for the 400 MB file ASAP.

@kranthireddyr

Please try using below code snippet in your environment and then share your kind feedback with us.

        String path = dataDir + "307Mb.pdf";
        byte[] data = File.ReadAllBytes(path);
        MemoryStream stream = new MemoryStream(data);
        Document documentFast = new Document(stream);
        if (documentFast.IsLinearized == false)
        {
            documentFast.IsLinearized = true;
        }
        FileStream file = new FileStream(path, FileMode.Create);
        documentFast.Save(file);

I hope this will be helpful. Please let us know if you need any further assistance.

Hello Farhan,

We have tested with the above code and same file which we have shared with you, we are getting “OutOfMemoryException” , please check.

@kranthireddyr

Please make sure to execute the code in x64 Debug Mode. The code snippet in my previous reply as well as the code snippet below, both are working fine as per your requirements.

        String path = dataDir + "307Mb.pdf";
        MemoryStream memoryStream = new MemoryStream();
        System.IO.FileStream InputStream = new FileStream(path, FileMode.Open);
        InputStream.CopyTo(memoryStream);
        InputStream.Dispose();
        Document documentFast = new Document(memoryStream);
        if (documentFast.IsLinearized == false)
        {
            documentFast.IsLinearized = true;
        }
        FileStream file = new FileStream(path, FileMode.Create);
        documentFast.Save(file);

I hope this will be helpful. Please let us know if you need any further assistance.

Hi Farhan,

Im also facing the same issue with the files with more than 200MB pdf files.
Error: The process cannot access the pdf file because it is being used by another process.

I have tried changing the debug mode to x64 option as well. Can you help on this?

Thanks in advance,
Satish

@satishd83

Thank you for contacting support.

We have replied you in the thread created by you. Kindly follow up in respective thread.

Hi Farhan,

We are still facing same issue with above two solutions.

Exception msg: An exception of type ‘System.OutOfMemoryException’ occurred in mscorlib.dll but was not handled in user code :face_with_monocle:

Note: we are not able to convert the Platform target to 64 bit. My project all the references are 32, so we can’t.

Can you help me as soon as possible,

@kranthireddyr

I would like to share with you that we do not have access to full memory installed in a system while working with x84 mode of debug. In order to deal with larger files, you need to have full access to installed memory. So, it is imperative to change debug mode from x86 to x64 to work with single file, and without creating any additional file, as per your requirements.

@Farhan.Raza

Thanks for the clarification, after converting to 64 it working fine.

@kranthireddyr

Thank you for your kind feedback.

We are glad to hear that the suggested approach has resolved the problem. Feel free to contact us if you need any further assistance.