Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge XMP Metadata if dc:format tag not found #722

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Smalot/PdfParser/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function extractXMPMetadata(string $content): void
}

// Only use this metadata if it's referring to a PDF
if (isset($metadata['dc:format']) && 'application/pdf' == $metadata['dc:format']) {
if (!isset($metadata['dc:format']) || 'application/pdf' == $metadata['dc:format']) {
// According to the XMP specifications: 'Conflict resolution
// for separate packets that describe the same resource is
// beyond the scope of this document.' - Section 6.1
Expand Down
32 changes: 32 additions & 0 deletions tests/PHPUnit/Integration/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,36 @@ public function testGetPagesMissingCatalog(): void
$document = $this->getDocumentInstance();
$document->getPages();
}

/**
* @see https://github.com/smalot/pdfparser/issues/721
*/
public function testExtractXMPMetadataIssue721(): void
{
$document = $this->getDocumentInstance();

// Check that XMP metadata is parsed even if missing a dc:format tag
$content = '<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c015 84.159810, 2016/09/10-02:41:30">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description>
<dc:creator>
<rdf:Seq>
<rdf:li>PdfParser</rdf:li>
</rdf:Seq>
</dc:creator>
<xmp:CreateDate>2018-02-07T11:51:44-05:00</xmp:CreateDate>
<xmp:ModifyDate>2019-10-23T09:56:01-04:00</xmp:ModifyDate>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>';

$document->extractXMPMetadata($content);
$document->init();
$details = $document->getDetails();

$this->assertEquals(4, \count($details));
$this->assertEquals('PdfParser', $details['dc:creator']);
$this->assertEquals('2019-10-23T09:56:01-04:00', $details['xmp:modifydate']);
}
}
Loading