How to get total pages of a document in Java

Hello,


I have tried to use GroupDocs Conversion for Java 3.0.0. Can you please show me how to get total pages of document? I couldn’t find any way to do it.

Thanks.

Hi Agustino,


Thanks for taking interest in GroupDocs.Conversion for Java 3.0.0 and posting the query.

Surely, you can get or count total pages of any document. While converting a document into any format, you can count number of the pages. For instance, see the code given below:

ConversionHandler conversionHandler = new ConversionHandler(Utilities.getConfiguration());
SaveOptions saveOption = new ImageSaveOptions();
saveOption.setConvertFileType(ImageSaveOptions.ImageFileType.Jpg);
saveOption.setOutputType(OutputType.String);
int count = 0;
List convertedDocumentPath = conversionHandler.<List> convert(fileName, saveOption);
for (int i = 0; i < convertedDocumentPath.size(); i++) {
count++;
}
System.out.println(count);

In this example snippet, I am converting a document to image. You can find count/list of the pages in convertedDocumentPath.
Hope it will help you.

Many Thanks

Hi Atir,


Thank you for the snippet code.
My use case is: I need to convert certain page only when user request for it, However we need to show total pages for the given document when user show first page.

Is there any way to get total pages without converting entire document? In the previous version of GroupDocs conversion (1.3.0), I can call conversionHandler.getPageCount(InputStream is, String fileName).

Thanks

Hi Agustino,


In the previous version of GroupDocs conversion (1.3.0), I can call conversionHandler.getPageCount(InputStream is, String fileName).
In Next Generation GroupDocs.Conversion for Java 3.0.0, you cannot count number of pages of a document like you do in older version. However, we have added your request in our internal issue tracking system with ID : CONVERSIONJAVA-165. As we get any update from the concerned team, we will notify you.
Please stay tuned.

Many Thanks

Greetings Agustino,


We are pleased to apprise you that GroupDocs.Conversion for Java 17.3.0 is on-board. Please follow this article in order to get pages count.
We’d recommend you to integrate this latest version of the API in your project and share your valuable feedback.

Warm wishes

Hi,


May I know what the status of this issue?

Thanks

Hi Atir,


Thank you for the information. We will try it out.

Hi There,


We’d like to apprise you that this feature will be added in upcoming release of the API.
We’ll appreciate your patience.

Kind regards

Greetings Agustino!


You’re welcome. We’d like to hear your valuable feedback.

Kind regards

Hi, do you mean in version 16.10.1 ? this feature is really important to us too.

Hi There,


This feature will be added in upcoming release of the API that is 17.3.0. As release gets on-board, we’ll notify you.
We’ll appreciate your patience.

Kind regards

Hi Atir,

Can you please give us an estimated timeline for the 17.3.0 release? This feature is critical for us.

Regards,
Sudhi

Hi Sudhi,


We got an update from the concerned team. The release is expected in 3-4 weeks. As it gets on-board, we’ll notify you.

Kind regards

That’s great. Thanks!

Hi Sudhi,


You are welcome.

Have a nice weekend ahead.
Best wishes