PDF/A-Erzeugung: die XMP-Metadaten selber erzeugen
[kivitendo-erp.git] / SL / DB / Helper / PDF_A.pm
index 4f52844..f3388a3 100644 (file)
@@ -5,6 +5,27 @@ use strict;
 use parent qw(Exporter);
 our @EXPORT = qw(create_pdf_a_print_options);
 
+use Carp;
+use Template;
+
+sub _create_xmp_data {
+  my ($self, %params) = @_;
+
+        use Cwd;
+  my $template = Template->new({
+    INTERPOLATE  => 0,
+    EVAL_PERL    => 0,
+    ABSOLUTE     => 1,
+    PLUGIN_BASE  => 'SL::Template::Plugin',
+    ENCODING     => 'utf8',
+  }) || croak;
+
+  my $output = '';
+  $template->process(SL::System::Process::exe_dir() . '/templates/pdf/pdf_a_metadata.xmp', \%params, \$output) || croak $template->error;
+
+  return $output;
+}
+
 sub create_pdf_a_print_options {
   my ($self) = @_;
 
@@ -20,13 +41,23 @@ sub create_pdf_a_print_options {
     $::instance_conf->get_company
   };
 
+  my $timestamp =  DateTime->now_local->strftime('%Y-%m-%dT%H:%M:%S%z');
+  $timestamp    =~ s{(..)$}{:$1};
+
   return {
-    version   => '3b',
-    meta_data => {
-      title    => $self->displayable_name,
-      author   => $author,
-      language => $pdf_language,
-    },
+    version => '3b',
+    xmp     => _create_xmp_data(
+      $self,
+      pdf_a_version     => '3',
+      pdf_a_conformance => 'B',
+      producer          => 'pdfTeX',
+      timestamp         => $timestamp, # 2019-11-05T15:26:20+01:00
+      meta_data => {
+        title    => $self->displayable_name,
+        author   => $author,
+        language => $pdf_language,
+      },
+    ),
   };
 }