I have a 50MB PDF with 100 pages and I want to know the size of PDF on passing any page number. from 1 to 99. Can someone please help with any existing API or solution?
We have already shared a sample code snippet with you to achieve same requirements in C#. It turned out you are not able to use it in Java. Please try to replace the MemoryStream with ByteArrayOutputStream like in below code snippet to get the file size before saving or further processing it:
import java.io.ByteArrayOutputStream;
// ...
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
destinationPdfDocument.save(byteArrayOutputStream);
long fileSize = byteArrayOutputStream.size();
byteArrayOutputStream.flush();
In case, it still doesn’t work, please let us know by sharing your sample file and expected output. We will work with the data provided and share our feedback with you.