Hello,
I am generating pdf with bathc API . I need to get also total page number created pdf.
BatchInput batchInput = batchBuilderFactory.getBatchInputBuilder().setData(inputJSONArray).setTemplatePath(templatePath).build();
BatchConfig batchConfig = batchBuilderFactory.getBatchConfigBuilder().setBatchType(BatchType.PRINT).build();
BatchResult batchResult = batchGeneratorService.generateBatch(batchInput, batchConfig);
RecordResult recordResult = checkOneElement(batchResult.getRecordResults(), "generated record");
RenditionResult renditionResult = checkOneElement(recordResult.getRenditionResults(), "generated result");
I tried to get PAGE_COUNT of Document object but is null, i also checked if rendition result has some meta data but it is null also.
Document doc = renditionResult.getDocumentStream();
log.info("doc PAGE_COUNT [{}]", doc.getAttribute("PAGE_COUNT"));
if (renditionResult.getMetadata() != null) {
for (Entry<String, Object> e : renditionResult.getMetadata().entrySet()) {
log.info("Entry {} : {}", e.getKey(), e.getValue());
}
}
Is there any meta data or api for getting total number of page for pdf please?
Views
Replies
Total Likes
It seems like you’re trying to get the total number of pages in a PDF document. Unfortunately, the batch API you’re using might not provide this feature directly. However, there are a few workarounds you can consider:
const pdfjsLib = require('pdfjs-dist'); ... pdfjsLib.getDocument(pdfPath).then(function (doc) { var numPages = doc.numPages; console.log('# Document Loaded'); console.log('Number of Pages: ', numPages); });
2. Using Power Platform: If you’re using Microsoft Power Platform, you can get the file content of a PDF file and then create a compose action with an expression that returns the count of pages within the PDF file
https://powerusers.microsoft.com/t5/Building-Flows/Number-of-pages-in-a-PDF-file/td-p/811707
Thanks @pulkitvashisth ,
Dou you know if any other aem Api can get get page number from Document or InputStream?
Hi @hugo_wuse
You can also probably try out the Apache PDFBox library.
import org.apache.pdfbox.pdmodel.PDDocument; public class GetPageCount { public static void main(String[] args) { try { PDDocument document = PDDocument.load(new File("path/to/your/document.pdf")); int numberOfPages = document.getNumberOfPages(); System.out.println("The PDF document has " + numberOfPages + " pages."); document.close(); } catch (IOException e) { e.printStackTrace(); } } }
<dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.24</version> </dependency>
Realy thank you @pulkitvashisth but i am trying to find it an aem form api.
I could not find a solution for getting total page number of generated pdf with batch Api. The answer given by @pulkitv56841125 works but this solution is not what i need. I dont understand how batch Api can not give the number of page for un generated pdf. Thsi is a basic futur.
@hugo_wuse Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies