ZUGFeRD: nicht nach \documentclass, sondern \begin{document} suchen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 2 Mar 2020 16:21:52 +0000 (17:21 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 2 Mar 2020 16:21:52 +0000 (17:21 +0100)
\documentclass steht evtl. in einem Include.

SL/Template/LaTeX.pm

index 303fb7f..422a293 100644 (file)
@@ -428,39 +428,22 @@ sub _force_mandatory_packages {
     if ($line =~ m/\\usepackage[^\{]*{(.*?)}/) {
       $used_packages{$1} = 1;
 
-    } elsif (($line =~ m/\\documentclass/) && $self->{pdf_a}) {
-      my $version = $self->{pdf_a}->{version}   // '3a';
-
-      if ($self->{pdf_a}->{xmp}) {
+    } elsif ($line =~ m/\\begin\{document\}/) {
+      if ($self->{pdf_a} && $self->{pdf_a}->{xmp}) {
+        my $version       = $self->{pdf_a}->{version}   // '3a';
         my $xmp_file_name = $self->{userspath} . "/pdfa.xmp";
         my $out           = IO::File->new($xmp_file_name, ">:encoding(utf-8)") || croak "Error creating ${xmp_file_name}: $!";
         $out->print(Encode::encode('utf-8', $self->{pdf_a}->{xmp}));
         $out->close;
 
-      } else {
-        my $meta = $self->{pdf_a}->{meta_data} // {};
-
         push @new_lines, (
-          "\\RequirePackage{filecontents}\n",
-          "\\begin{filecontents*}{\\jobname.xmpdata}\n",
-          ($meta->{title}    ? sprintf("\\Title{%s}\n",    $meta->{title})    : ""),
-          ($meta->{author}   ? sprintf("\\Author{%s}\n",   $meta->{author})   : ""),
-          ($meta->{language} ? sprintf("\\Language{%s}\n", $meta->{language}) : ""),
-          "\\end{filecontents*}\n",
+          "\\usepackage[a-${version},mathxmp]{pdfx}[2018/12/22]\n",
+          "\\usepackage[genericmode]{tagpdf}\n",
+          "\\tagpdfsetup{activate-all}\n",
+          "\\hypersetup{pdfstartview=}\n",
         );
       }
 
-      push @new_lines, (
-        $line,
-        "\\usepackage[a-${version},mathxmp]{pdfx}[2018/12/22]\n",
-        "\\usepackage[genericmode]{tagpdf}\n",
-        "\\tagpdfsetup{activate-all}\n",
-        "\\hypersetup{pdfstartview=}\n",
-      );
-
-      next;
-
-    } elsif ($line =~ m/\\begin\{document\}/) {
       push @new_lines, map { "\\usepackage{$_}\n" } grep { !$used_packages{$_} } @required_packages;
       push @new_lines, $line;
       push @new_lines, map { $self->_embed_file_directive($_) } @{ $self->{pdf_attachments} // [] };