Get PDF Metadata in C++
Contents
[
Hide
]
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.
- Create PdfFileInfo with the input PDF path.
- Read subject through PdfFileInfo.
- Read title through PdfFileInfo.
- Read keywords through PdfFileInfo.
- Read creator through PdfFileInfo.
- Read creation date through PdfFileInfo.
- Read mod date through PdfFileInfo.
- Read is pdf file through PdfFileInfo.
- Read is encrypted through PdfFileInfo.
- Read has open password through PdfFileInfo.
- Read has edit password through PdfFileInfo.
- Read has collection through PdfFileInfo.
- Read custom metadata with PdfFileInfo::GetMetaInfo().
- Close the facade with PdfFileInfo::
Close(). - 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