Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, When I run the below code, I am getting junk characters as output. Any solution to avoid this? I need last modified date from PDF document properties. I tried stat function but it is giving different date. I need modified date from document properties. After opening PDF, press Ctrl+D, it throws the properties and I want that modified date.

my $pdf = PDF::API2->open("$file"); print Dumper { $pdf->info }

Replies are listed 'Best First'.
Re: PDF::API2 module prints junk characters
by poj (Abbot) on Sep 01, 2015 at 10:17 UTC
    try
    #!perl use strict; use PDF::API2; use Data::Dump 'pp'; my $file = 'file.pdf'; my $pdf = PDF::API2->open($file); my %h = $pdf->info(); pp $pdf->info; print $h{'ModDate'};
    poj

      Hello poj, Thanks for your response. When I run your code, I got output like this,

      ( "ModDate", pack("H*","4a7878cbbb7bff8a4b3b937b7fe3d5e12664278a100905"), "Subject", "L\27}\xCB\xBBs\xE2\x89JN\xFDz\x7F\xE4", "CreationDate", pack("H*","4a7878cbbb75ff87493a92737eedd6ed51"), "Producer", pack("H*","4f213894e923bb9f3d62d13e23b889b179742683101717f1abd548ddd +a263b6365d adb6e92"), "Title", pack("H*","4c372697ee36a6d1593c927a7bf9d3e74e7433e96c1971b4bfd35f8eb +7063b696ed dc77288250087"), "Author", pack("H*","572d2194ec23b8de594ece2f29a097bd687450c252494da3acce5392f +9"), ) JxxË»{ÿŠK;“{ãÕá&d'Š 

      When I extracted the xmp meta file in xml format using this module, it is completely having junk characters. When I open the document properties, it is showing the modified data clearly. Any Idea?

      Hello Poj, I think the problem is with the PDF, some of the files throwing the date perfectly, for some files I am getting junk characters. So If you have some idea to rectify, please let me know.

Re: PDF::API2 module prints junk characters ( CAM::PDF / pdfinfo.pl)
by Anonymous Monk on Sep 02, 2015 at 00:17 UTC

    Apparently, PDF::API2 is for creating PDFs, it will read them, but a lot of the fields/records will just be binary junk ... which you can replace with various calls

    What you're after is CAM::PDF/https://metacpan.org/pod/distribution/CAM-PDF/bin/pdfinfo.pl

    $ pdfinfo Test-Results-Cookstove-Performance.pdf File: Test-Results-Cookstove-Performance.pdf File Size: 16123625 bytes Pages: 128 CreationDate: Thu Nov 3 01:02:54 2011 Creator: Adobe Acrobat Pro 9.4.6 ModDate: Thu Jan 5 00:52:01 2012 Producer: Adobe PDF Library 9.9 Trapped: False Page Size: variable Optimized: yes PDF version: 1.7 Security Passwd: none Print: yes Modify: yes Copy: yes Add: yes