/** * @file pdf_metadata.h * @brief Minimal PDF metadata extraction * * This provides basic PDF metadata extraction by parsing the trailer /Info dictionary. * zpdf focuses on text extraction and doesn't expose metadata, so we implement * a minimal parser for common metadata fields. */ #pragma once #include #include #include #include #include #include namespace yams::zyp { namespace detail { /** * Find the final occurrence of a byte sequence. * * Returns nullptr when either input is empty or the sequence is absent. */ [[nodiscard]] const uint8_t* findBackwards(std::span data, std::string_view needle); } // namespace detail /** * PDF document metadata. */ struct PdfMetadata { std::optional title; std::optional author; std::optional subject; std::optional keywords; std::optional creator; /**< Application that created the original */ std::optional producer; /**< PDF producer application */ std::optional creationDate; std::optional modDate; /** * Convert metadata to a key-value map. * Only includes fields that have values. */ [[nodiscard]] std::unordered_map toMap() const; /** * Check if any metadata fields are present. */ [[nodiscard]] bool empty() const; }; /** * Extract metadata from a PDF buffer. * * This is a minimal parser that: * 1. Finds the trailer dictionary * 2. Locates the /Info reference * 3. Parses the info dictionary for standard fields * * @param data PDF file content * @return Metadata if found, nullopt on parse error */ [[nodiscard]] std::optional extractMetadata(std::span data); } // namespace yams::zyp