Get PDF Metadata in C++

Use PdfFileInfo for this task. The examples below retain the original C++ code and API Reference steps.

Get PDF metadata

Print document information, file-status flags, and the custom Reviewer metadata value when available.

  1. Create PdfFileInfo with the input PDF path.
  2. Read subject through PdfFileInfo.
  3. Read title through PdfFileInfo.
  4. Read keywords through PdfFileInfo.
  5. Read creator through PdfFileInfo.
  6. Read creation date through PdfFileInfo.
  7. Read mod date through PdfFileInfo.
  8. Read is pdf file through PdfFileInfo.
  9. Read is encrypted through PdfFileInfo.
  10. Read has open password through PdfFileInfo.
  11. Read has edit password through PdfFileInfo.
  12. Read has collection through PdfFileInfo.
  13. Read custom metadata with PdfFileInfo::GetMetaInfo().
  14. Close the facade with PdfFileInfo::Close().
  15. Print the results or diagnostic messages shown in the example.
#include <Aspose.PDF.Cpp/Facades/PdfFileInfo.h>
#include <iostream>
#include <system/string.h>

namespace Facades::Examples::PDF_FileInfo
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void GetPdfMetadata(String inputFile)
{
    auto pdfInfo = MakeObject<PdfFileInfo>(inputFile);
    std::cout << "Subject: " << pdfInfo->get_Subject() << std::endl;
    std::cout << "Title: " << pdfInfo->get_Title() << std::endl;
    std::cout << "Keywords: " << pdfInfo->get_Keywords() << std::endl;
    std::cout << "Creator: " << pdfInfo->get_Creator() << std::endl;
    std::cout << "Creation Date: " << pdfInfo->get_CreationDate() << std::endl;
    std::cout << "Modification Date: " << pdfInfo->get_ModDate() << std::endl;
    std::cout << "Is Valid PDF: " << pdfInfo->get_IsPdfFile() << std::endl;
    std::cout << "Is Encrypted: " << pdfInfo->get_IsEncrypted() << std::endl;
    std::cout << "Has Open Password: " << pdfInfo->get_HasOpenPassword() << std::endl;
    std::cout << "Has Edit Password: " << pdfInfo->get_HasEditPassword() << std::endl;
    std::cout << "Is Portfolio: " << pdfInfo->get_HasCollection() << std::endl;
    auto reviewer = pdfInfo->GetMetaInfo(u"Reviewer");
    std::cout << "Reviewer: " << (reviewer.IsNullOrEmpty() ? String(u"No Reviewer metadata found.") : reviewer) << std::endl;
    pdfInfo->Close();
}
} // namespace  Facades::Examples::PDF_FileInfo