Get count of pages from in pdf from stream

Hi

I'm using PdfFileEditor.concatenate(inStreams, outStream) to combine a number of pdfs taken from a database. What I would like to do is get a count of the pages of the resulting pdf. Then as a final step if there are an odd number of pages in the new pdf then add a blank page.

Can you help me?

Thanks

Anthony.

antheg:
I’m using PdfFileEditor.concatenate(inStreams, outStream) to combine a number of pdfs taken from a database. What I would like to do is get a count of the pages of the resulting pdf.
Hi Anthony,

Thanks for using our products.

Once the resultant/concatenated PDF file is generated, please try using getNumberofPages() method of PdfFileInfo class to accomplish your requirement.

antheg:
Then as a final step if there are an odd number of pages in the new pdf then add a blank page.
In order to fulfill this requirement, first create a blank PDF file using Aspose.Pdf for Java and then insert it by following the steps specified over Insert Pages into a PDF Document

You may create a simple blank Pdf file using instructions specified over Create a Hello World PDF document through API (in Text constructor, remove the string “Hello World”).

Hello Nayyer,

Thanks for your reply. I found the getNumberofPages() method. I can explain a bit more on what I'm doing. I have say 3 pdf store as blobs on an Oracle database. I select the blobs from the database and put them on and array of type ByteArrayInputStream (inStreams).

I then call pdfEditor.concatenate(inStreams, outStream); to concatenate the pdfs. I then put the concatenated pdf back into the database. So I tried creating a PdfFileInfo class for each stream in the array and getting the number of pages. It does give me the correct number of pages. So far I haven't tried adding a page. However I find that when I now call pdfEditor.concatenate(inStreams, outStream); I'm getting an error "PDF header signature error".

Also if I create a new pdf can I just concatenate it onto the stream for the individual document before creating the concatenation of the 3 pdfs.

So my steps are.

1. Retrive the 3 documents from the database,

2. Check if an odd number of pages.

3. If odd number of pages add a blank page.

4 Join the 3 documents together and save back to the database.

This may seem a bit strange but the purpose is that we want to distribute one document printed on both sides of the page but we don't want the first page of the second..n documents to appear on the back of the last page of the previous document.

Thanks

Anthony

Hi Anthony,


Thanks for sharing the details. I am working over this query and will get back to you soon.

antheg:
I then call pdfEditor.concatenate(inStreams, outStream); to concatenate the pdfs. I then put the concatenated pdf back into the database. So I tried creating a PdfFileInfo class for each stream in the array and getting the number of pages. It does give me the correct number of pages. So far I haven’t tried adding a page. However I find that when I now call pdfEditor.concatenate(inStreams, outStream); I’m getting an error “PDF header signature error”.
Hi Anthony,

Sorry for the delayed response.

As per my understanding, once you have retrieved individual PDF files, you are able to get the page count using getNumberofPages(…) method of pdfFileInfo class. Then as per your requirement, you need to concatenate the PDf files and the problem is appearing during concatenation. I am not sure why the concatenate method is causing issue because once you have been able to sucessfully use getNumberofPages() method and you did not encounter any issue while manipulating individual PDF documents, then why the problem is appearing for concatenate method. Once you have retrieved the PDF files, can you please save the individual documents over system and share the resource files so that we can test the scenario at our end. We are really sorry for this inconvenience.