DjVu to PDF result in exception: image file format may be not supported at the moment (C# .NET)

i have tried Converted DjVu to PDF Format follow by the guide at link.
https://docs.aspose.com/display/imagingnet/Manipulating+DjVu+Formats
It worked fine with the file sample.djvu But with my djvu file it got this error:
“Exception in thread “main” class com.aspose.imaging.coreexceptions.ImageLoadException: Cannot open an image. The image file format may be not supported at the moment.”

I have debugged and it got error at this line of code :
DjvuImage image = (DjvuImage) Image.load(“E:\SplitPDF\5medbook.com_Теория-информации-и-теририя-алгоритмов_onito217_58f743a876ae4d90aa8773bcd85dc8c8.djvu”);
I very sure that the path is correct. But I don’t know why it has error.

Please help me!

@thieugja,

Can you please share source file along with environment details so that we may further investigate to help you out.

1 Like

I use Java. Here is my source code:

public static void main(String[] args) throws Exception {
        // The path to the documents directory.
        String dataDir = Utils.getSharedDataDir(ConvertFilePdfToImg.class) + "djvu/";
        //ExStart:ConvertDjvuToPdf
        //Load a DjVu image
        DjvuImage image = (DjvuImage) Image.load("E:\SplitPDF\5medbook.com_Теория-информации-и-теририя-алгоритмов_onito217_58f743a876ae4d90aa8773bcd85dc8c8.djvu");

        //Create an instance of PdfOptions
        PdfOptions exportOptions = new PdfOptions();

        //Initialize the metadata for Pdf document
        exportOptions.setPdfDocumentInfo(new PdfDocumentInfo());
        
        //Create an instance of IntRange and initialize it with the range of DjVu pages to be exported
        IntRange range = new IntRange(1, 4); //Export first 3 pages
        
        //Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported 
        exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
        
        //Save the result in PDF format
        image.save("E:\\SplitPDF\\ConvertDjvuToPdf_out.pdf", exportOptions);

        // Display Status.
        System.out.println("File conveted");
    
        //ExEnd:ConvertDjvuToPdf
    }

In Pom.xml

<dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-imaging</artifactId>
        <version>19.2</version>
        <classifier>jdk16</classifier>
</dependency>

Here is my DjVu file:
https:// drive.google.com/open?id=1H7G4NiouFV0fX9AvnUxL5YtzZaYGxAqb

Please help meee!

@thieugja,

I have worked with source file and sample code shared by you. I like to inform that source file you shared is a PDF file with wrong extension. Please change source file extension to PDF and check on your end. This is the reason it is not converting to pdf.5medbook.com_Теория-информации-и-теририя-алгоритмов_onito217_58f743a876ae4d90aa8773bcd85dc8c8.pdf (9.8 MB)

1 Like

Oh my god, you are my hero. I did not expect that file to be a PDF file, I was miserable because it took 3 days without knowing what to do. My life is lucky to meet you. Thank you very much.

So how do you find that PDF file? I still think it’s a DjVu file until you say it.

@thieugja,

I have opened this file in binary form and found PDF header.

1 Like

@Adnan.Ahmad
Thank you very much, my friend. I just tried to convert the DjVu file to a PDF file. Everything is great until I realize that the size after conversion is so large that the error Java heap size occurs. My DjVu file originally had 2mb, after converting to PDF up to 200mb.

Is there a way to minimize the file size when converting. I tried all the way but was really helpless, it was too hard for me. Please help me, please!!!

@thieugja,

Can you please share that DjVu file that is causing issue on your end so that i may further investigate to help you out. Also please share complete environment details.

1 Like

@Adnan.Ahmad
Thank you. Here is my DjVu file got issue. Sorry but I don’t understand the environment details. I use Java and run in Eclipse IDE https://drive.google.com/file/d/12ygBIgjMc6mtBoy_wD5xhTq5u4je6AEE/view?usp=sharing

@thieugja,

I have used Aspose.Imaging for Java 19.2 on my end using JDK 1.7 in Windows 7 environment and have not been able to reproduce the issue. For your kind reference, I have attached the generated PDF as well.

ConvertDjvuToPdf_out.pdf (5.1 MB)

1 Like

@mudassir.fayyaz

Thank you, but unfortunately, we have some misunderstands here (sorry, my fault). The code that i uploaded is only convert 4 pages of the original DjVu file and as you see, the file you attached takes about 5mb size for 4 pages (therefore should be over 300mb for total pdf file). With larger DjVu file size (>6mb), the function would display the error like OutOfmemory - java heap size ( which means it has reached the maximum allowed heap size in memory ) .

The solution i found here is resize the output file when converting djvu file, i guess the resize may be defined after this line of code:

PdfOptions exportOptions = new PdfOptions();

Back to my question, are there anyway to resize the output pdf file while converting from DjVu to PDF (This should be reduced the quality before image.save function ) ?
Please help me to deal this issue,i am so struggled now because of this, thousand thanks for your help!!

@thieugja,

In order to avoid the OutOfMemory heap size exception, I suggest you to please consider increasing the heap size on your end to avoid the exception.

@mudassir.fayyaz

Thanks for your help. I tried your way but there will be extremely large capacity files and the processing problem will be difficult. So I want to ask if there is any way to optimize or compress the file size when converting DjVu to PDF.
The file I have converted from 11Mb to 1.2Gb. It’s so large and time consuming for processing.
Please help me solve this issue. Thousand thanks for your help!!

@thieugja,

I regret to share that there is no way to optimize file loading as it gets loaded in Document Object Model (DOM) of Aspose.Imaging and hold entire image in memory. Increasing of heap size is only option to avoid exception and amount of memory required varies from image to image. You have mentioned that there will be extremely large capacity files but you will loading the files individually and clearing memory after processing one and then loading a new one. I hope the shared elaboration will be helpful.