NAME
DateTime::Format::PDF - PDF DateTime Parser and Formatter.
SYNOPSIS
my
$obj
= DateTime::Format::PDF->new;
my
$dt
=
$obj
->parse_datetime(
$pdf_date
);
my
$pdf_date
=
$obj
->format_datetime(
$dt
);
DESCRIPTION
This module understands the formats used by PDF file. It can be used to parse these formats in order to create DateTime objects, and it can take a DateTime object and produce a string representing it in a format accepted by PDF.
METHODS
new
my
$obj
= DateTime::Format::PDF->new(
%params
);
Constructor.
Returns instance of object.
parse_datetime
my
$dt
=
$obj
->parse_datetime(
$pdf_date
);
Parse PDF datetime string.
Possible valid strings:
D:YYYY
D:YYYYMM
D:YYYYMMDD
D:YYYYMMDDHH
D:YYYYMMDDHHmm
D:YYYYMMDDHHmmSS
D:YYYYMMDDHHmmSSZ
D:YYYYMMDDHHmmSSOHHmm
D:YYYYMMDDHHmmSSOHH'mm
D:YYYYMMDDHHmmSSOHH'mm'
D:YYYYMMDDHHmmSSOHHmm'
Returns DateTime object.
format_datetime
my
$pdf_date
=
$obj
->format_datetime(
$dt
);
Format DateTime object to PDF datetime string. Output value is D:YYYYMMDDHHmmSSOHHmm
.
Returns string.
ERRORS
format_datetime():
Bad DateTime object.
Value:
%s
parse_datetime():
Invalid date
format
:
%s
EXAMPLE1
EXAMPLE2
EXAMPLE3
use
strict;
use
warnings;
use
PDF::Builder;
if
(
@ARGV
< 1) {
STDERR
"Usage: $0 pdf_file\n"
;
exit
1;
}
my
$pdf_file
=
$ARGV
[0];
# Open file.
my
= PDF::Builder->
open
(
$pdf_file
);
# Parser.
my
$pdf_date_parser
= DateTime::Format::PDF->new;
my
(
$dt_created
,
$dt_modified
);
my
$print_format
=
"%a, %d %b %Y %H:%M:%S %z"
;
if
(
defined
->created) {
$dt_created
=
$pdf_date_parser
->parse_datetime(
->created);
"Created: "
.
$dt_created
->strftime(
$print_format
).
"\n"
;
}
if
(
defined
->modified) {
$dt_modified
=
$pdf_date_parser
->parse_datetime(
->modified);
"Modified: "
.
$dt_modified
->strftime(
$print_format
).
"\n"
;
}
# Output:
# Created: Fri, 15 May 2009 08:40:48 +0200
# Modified: Fri, 15 May 2009 08:44:00 +0200
EXAMPLE4
use
strict;
use
warnings;
use
PDF::API2;
if
(
@ARGV
< 1) {
STDERR
"Usage: $0 pdf_file\n"
;
exit
1;
}
my
$pdf_file
=
$ARGV
[0];
# Open file.
my
= PDF::API2->
open
(
$pdf_file
);
# Get meta info.
my
%meta
=
->info;
# Parser.
my
$pdf_date_parser
= DateTime::Format::PDF->new;
my
(
$dt_created
,
$dt_modified
);
my
$print_format
=
"%a, %d %b %Y %H:%M:%S %z"
;
if
(
exists
$meta
{
'CreationDate'
}) {
$dt_created
=
$pdf_date_parser
->parse_datetime(
$meta
{
'CreationDate'
});
"Created: "
.
$dt_created
->strftime(
$print_format
).
"\n"
;
}
if
(
exists
$meta
{
'ModDate'
}) {
$dt_modified
=
$pdf_date_parser
->parse_datetime(
$meta
{
'ModDate'
});
"Modified: "
.
$dt_modified
->strftime(
$print_format
).
"\n"
;
}
# Output:
# Created: Fri, 15 May 2009 08:40:48 +0200
# Modified: Fri, 15 May 2009 08:44:00 +0200
DEPENDENCIES
DateTime::Format::Builder, Error::Pure, Scalar::Util.
REPOSITORY
https://github.com/michal-josef-spacek/DateTime-Format-PDF
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2024 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.02