Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible to get pdf page count?
#1
Rainbow 
Hi, LA is so powerful, and I would like to ask if it is possible to pull the pdf information without opening it? say page count and creating time (huge number of pdfs). Thanks 

Any response is appreciated.
#2
1. Go to NuGet and search for pdf.

2. Click for example PDFsharp and copy the PM text. Also look at Frameworks (must support .NET 6), License (MIT means it's free), Source repository (isn't it abandoned etc).

3. In LA open the NuGet tool, paste, click Install. Wait, click Add /*/. Close the tool.

4. Now you can use the library in current script. Press Ctrl+Space and you'll find PdfSharp.

If need examples and other info, in the NuGet page click link "Project website" or "Source repository". Also google.
 
Code:
Copy      Help
// script ""
/*/ nuget -\PDFsharp; /*/
using PdfSharp.Pdf.IO;

var doc = PdfReader.Open(@"C:\Downloads\p.pdf");
print.it(doc.PageCount, doc.Info.CreationDate);
#3
Heart 
This is fantastic. Thank you so much for the detailed information and the code.
#4
There is also itextsharp-lgpl. This will get the number of pages for you and the creation date. Sorry, no error checking, just bare bones.

 
Code:
Copy      Help
/*/ nuget PDF\iTextSharp-LGPL; /*/

using iTextSharp.text;
using iTextSharp.text.pdf;

string inpath = @"C:\Users\Your_User\Documents\LibreAutomate\Documents\Your_Test_Dummy.pdf";
FileInfo file = new FileInfo(inpath);
// string name = file.Name.Substring(0, file.Name.LastIndexOf("."));

PdfReader reader = new PdfReader(inpath);

var info = reader.Info;
DateTime creationDate = PdfDate.Decode(info["CreationDate"].ToString());
// print.it(info); // for reference
// print.it(info["CreationDate"]); // for reference

print.it("Pdf created: " + creationDate);
print.it("Number of pages: " + reader.NumberOfPages);

reader = null;
#5
Wonderful. Thanks and it worked.


Forum Jump:


Users browsing this thread: 1 Guest(s)