Skip to content

Commit

Permalink
#208 Customizable PDF Metadata -> Additionally using FPDF-BuiltIn-Met…
Browse files Browse the repository at this point in the history
…adata methods
  • Loading branch information
HorstOeko committed Dec 11, 2024
1 parent 7a9ade1 commit 17edaa7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ private function updatePdfMetadata(): void
$xmpNodes->{'CreateDate'} = $pdfMetadataInfos['createdDate'];
$xmpNodes->{'ModifyDate'} = $pdfMetadataInfos['modifiedDate'];
$this->pdfWriter->addMetadataDescriptionNode($descXmp->asXML());

$this->pdfWriter->SetAuthor($pdfMetadataInfos['author']);
$this->pdfWriter->SetKeywords($pdfMetadataInfos['keywords']);
$this->pdfWriter->SetTitle($pdfMetadataInfos['title']);
$this->pdfWriter->SetSubject($pdfMetadataInfos['subject']);
}

/**
Expand Down
63 changes: 63 additions & 0 deletions tests/testcases/PdfBuilderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public function testPdfMetaData(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails); //"FPDF 1.84"
$this->assertArrayHasKey("CreationDate", $pdfDetails); //"2020-12-09T05:19:39+00:00"
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails); //"1"
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -183,6 +187,9 @@ public function testPdfMetaData(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("FacturX/ZUGFeRD Invoice 471102 dated 2018-03-05 issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -542,6 +549,10 @@ public function testDeterministicMode(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -557,6 +568,9 @@ public function testDeterministicMode(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString('2000-01-01', $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("FacturX/ZUGFeRD Invoice 471102 dated 2018-03-05 issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -586,6 +600,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -601,6 +619,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("FacturX/ZUGFeRD Invoice 471102 dated 2018-03-05 issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -628,6 +649,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -643,6 +668,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("FacturX/ZUGFeRD Invoice 471102 dated 2018-03-05 issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -671,6 +699,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -686,6 +718,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("FacturX/ZUGFeRD Invoice 471102 dated 2018-03-05 issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Issued by seller with name Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -715,6 +750,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -730,6 +769,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("Invoice-Document, Issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Issued by seller with name Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -780,6 +822,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -795,6 +841,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("DummyTitle", $pdfDetails["Title"]);
$this->assertEquals("DummySubject", $pdfDetails["Subject"]);
$this->assertEquals("DummyAuthor", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -835,6 +884,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -850,6 +903,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("Invoice-Document, Issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Issued by seller with name Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down Expand Up @@ -880,6 +936,10 @@ public function testCustomMetaInformation(): void
$this->assertIsArray($pdfDetails);
$this->assertArrayHasKey("Producer", $pdfDetails);
$this->assertArrayHasKey("CreationDate", $pdfDetails);
$this->assertArrayHasKey("Title", $pdfDetails);
$this->assertArrayHasKey("Subject", $pdfDetails);
$this->assertArrayHasKey("Author", $pdfDetails);
$this->assertArrayHasKey("Keywords", $pdfDetails);
$this->assertArrayHasKey("Pages", $pdfDetails);
$this->assertArrayHasKey("fx:documenttype", $pdfDetails);
$this->assertArrayHasKey("fx:documentfilename", $pdfDetails);
Expand All @@ -895,6 +955,9 @@ public function testCustomMetaInformation(): void
$this->assertArrayHasKey("xmp:modifydate", $pdfDetails);
$this->assertStringContainsString('FPDF', $pdfDetails["Producer"]);
$this->assertStringContainsString(date("Y-m-d"), $pdfDetails["CreationDate"]);
$this->assertEquals("Lieferant GmbH : Invoice 471102", $pdfDetails["Title"]);
$this->assertEquals("Invoice-Document, Issued by Lieferant GmbH", $pdfDetails["Subject"]);
$this->assertEquals("Issued by seller with name Lieferant GmbH", $pdfDetails["Author"]);
$this->assertEquals("1", $pdfDetails["Pages"]);
$this->assertEquals("INVOICE", $pdfDetails["fx:documenttype"]);
$this->assertEquals("factur-x.xml", $pdfDetails["fx:documentfilename"]);
Expand Down

0 comments on commit 17edaa7

Please sign in to comment.