1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27:45 +00:00

LibPDF: Add accessor for the document's info dict

This dict contains some metadata in some files.

Newer files also contain XMP metadata, but it's recommended to
still include this dict as well, for compatibility with older readers.
And it's much less complex than XMP, so let's support it.
This commit is contained in:
Nico Weber 2023-07-10 08:59:03 -04:00 committed by Sam Atkins
parent 826c0426f3
commit c5c940b1c9
3 changed files with 93 additions and 0 deletions

View file

@ -34,6 +34,46 @@ DeprecatedString OutlineItem::to_deprecated_string(int indent) const
return builder.to_deprecated_string();
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::title() const
{
return get(CommonNames::Title);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::author() const
{
return get(CommonNames::Author);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::subject() const
{
return get(CommonNames::Subject);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::keywords() const
{
return get(CommonNames::Keywords);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::creator() const
{
return get(CommonNames::Creator);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::producer() const
{
return get(CommonNames::Producer);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::creation_date() const
{
return get(CommonNames::CreationDate);
}
PDFErrorOr<Optional<DeprecatedString>> InfoDict::modification_date() const
{
return get(CommonNames::ModDate);
}
PDFErrorOr<NonnullRefPtr<Document>> Document::create(ReadonlyBytes bytes)
{
auto parser = adopt_ref(*new DocumentParser({}, bytes));
@ -189,6 +229,14 @@ PDFErrorOr<Value> Document::resolve(Value const& value)
return value;
}
PDFErrorOr<Optional<InfoDict>> Document::info_dict()
{
if (!trailer()->contains(CommonNames::Info))
return OptionalNone {};
return InfoDict(this, TRY(trailer()->get_dict(this, CommonNames::Info)));
}
PDFErrorOr<void> Document::build_page_tree()
{
auto page_tree = TRY(m_catalog->get_dict(this, CommonNames::Pages));