I am trying to use this code:
FileStream stream = new FileStream(@“pathToFile”, FileMode.Open);
Pdf pdf = new Pdf(stream);
int pageCount = pdf.PageCount;
First of all, the pageCount does not work. It returns always 0. After the Close call, it returns 1. And this one page is now destroyed -> can not be opened anymore with Acrobat PDF reader.
Thanks for using our products.
You can only get the page count once the document is saved. In fact, until or unless the document is saved, you might not be certain about the number of pages a PDF file may have.
However, can you please share that either you need to generate a PDF document from scratch or you are trying to open any existing PDF file ?
FYI, Aspose.Pdf is a component which is used to generate PDF documents from scratch where as have a component named Aspose.Pdf.Kit which is used to manipulate/edit any existing PDF documents.
yes sorry, I tryed implizit to say, that I am using an existing PDF. Otherwise it would not be possible to say, that it is destroyed now.
Now a little bit more clear: I have any PDF, with 1 to n pages. When I open this, as described in the first post, the PageCounter is always returning 0. Even if the document has more than one page. After the Close() call, you can not open the first page of the document anymore. Which means that if you had a document with just 1 page, the hole document. If there were more pages, the first is destroyed.
Thanks for sharing the information.
As I have shared in my earlier post, Aspose.Pdf.Kit is used to manipulate/edit existing PDF document so I am going to move this thread to Aspose.Pdf.Kit forum where I believe our team of experts taking care of this product would be in better position to answer these queries.
You can use PdfFileInfo class of the Aspose.Pdf.Kit to get the page numbers of an existing PDF file. The NumberOfPages property can give you the total page count.
I hope this helps. If you find any further questions, please do let us know.
The PageCount was just an example. It was not the idea to get this information, just for demonstration purposes. What I tryed to say is, that the Close() call will destroy existing PDF’s which is in fact a bug.
Please allow me to share some more details over the difference between Aspose.Pdf and Aspose.Pdf.Kit.
- Aspose.Pdf is a component which is used to generate the PDF documents from scratch. You can use this product to create a document through its API, while converting an image file (JPEG, BMP, TIFF, PNG etc) into PDF format, transform an XML or XSL-FO file into PDF, convert a text file and even convert the HTML page into PDF format. The Pdf class in Aspose.Pdf has a method named Save(…) which is used to save the resulting PDF document. However, we have a mode called Direct-to-File, in which PDF document is directly saved over target location, and Aspose.Pdf writes every new paragraph directly to the Pdf file and frees the memory used by the Paragraph. This working mode can be of great help for developers to save their system’s memory usage when the document is large. When using this mode, you have to call Pdf.Close() method. Otherwise in normal procedure, you have to simply call the save(…) method and Aspose.Pdf automatically makes the document free once saved over system. For more information over this topic, please visit Writing PDF directly
- Whereas, Aspose.Pdf.Kit is a component which is used to manipulate/edit any existing PDF document. As shahzad has already mentioned, it provided a large number of classes that are used to edit and work with existing PDF files. Depending upon the class, there are numerous properties and methods to open and close the PDF file (after performing any activity). For a complete list of classes and Numerations offered by Aspose.Pdf.Kit, please visit Aspose.Pdf.Kit for .NET API Reference
Can you please share some sample resource PDF files and your exact requirement that you are trying to perform, so that we can test the scenario at our end. We are really sorry for your inconvenience.