C++에서 프레젠테이션 속성 관리

소개

Aspose.Slides for C++는 built-in 및 custom 문서 속성을 지원합니다. 이러한 속성을 사용하여 작성자, 제목 및 사용자 정의 값과 같은 프레젠테이션 메타데이터를 읽고 업데이트할 수 있습니다.

Aspose.Slides는 IDocumentProperties 인터페이스를 통해 프레젠테이션 문서 속성을 작업할 수 있게 합니다. 이 인터페이스의 인스턴스는 IPresentation::get_DocumentProperties에 의해 반환됩니다. 다음 예제에서는 이러한 속성을 읽고, 수정하고, 관리하는 방법을 보여줍니다.

프레젠테이션 속성 관리

문서 속은 프레젠테이션 콘텐츠와 함께 설명 정보를 저장합니다. 두 가지 범주로 나뉩니다:

  • Built-in properties는 제목, 작성자 및 문서 통계와 같은 표준 메타데이터를 포함합니다.
  • Custom properties는 사용자 정의 이름/값 쌍을 저장합니다.

Aspose.Slides for C++는 두 범주 모두에 대한 액세스를 제공합니다. PowerPoint에서 File → Info → Properties → Advanced Properties를 선택하여 문서 메타데이터를 검사합니다. 대화 상자는 정보를 Summary, Statistics, Contents, Custom과 같은 탭으로 그룹화합니다. 사용자 정의 속성을 관리하려면 Custom 탭을 사용하십시오.

암호화된 프레젠테이션에서 공개 속성 읽기

열기 암호는 일반적으로 프레젠테이션 콘텐츠와 문서 속성 모두를 보호합니다. 프레젠테이션이 IProtectionManager::set_EncryptDocumentProperties에 false를 전달하여 암호화될 경우, 문서 속성은 공개된 상태로 유지됩니다. 그런 다음 애플리케이션은 LoadOptions::set_OnlyLoadDocumentProperties에 true를 전달하여 열기 암호 없이 공개 메타데이터를 읽을 수 있습니다.

LoadOptions::set_OnlyLoadDocumentProperties는 Aspose.Slides가 로드하는 내용을 제어합니다; 복호화는 수행되지 않습니다. 속성이 암호화에 포함된 경우, 암호 없이 로드하면 실패합니다. 프레젠테이션이 암호화되지 않은 경우 이 옵션은 무시되고 전체 프레젠테이션이 로드됩니다.

이 예제는 문서 속성이 공개된 상태로 남아 있는 암호화된 프레젠테이션이 필요합니다. IProtectionManager::get_IsOnlyDocumentPropertiesLoaded를 통해 로드 모드를 확인하고, 이어서 IPresentation::get_DocumentProperties를 통해 내장 속성을 읽습니다:

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <DOM/LoadOptions.h>
#include <DOM/IProtectionManager.h>

using namespace Aspose::Slides;

auto loadOptions = System::MakeObject<LoadOptions>();
loadOptions->set_OnlyLoadDocumentProperties(true);

auto presentation = System::MakeObject<Presentation>(u"public-properties-encrypted.pptx", loadOptions);

if (presentation->get_ProtectionManager()->get_IsOnlyDocumentPropertiesLoaded())
{
    auto documentProperties = presentation->get_DocumentProperties();

    System::Console::WriteLine(u"Author: {0}", documentProperties->get_Author());
    System::Console::WriteLine(u"Title: {0}", documentProperties->get_Title());
    System::Console::WriteLine(u"Keywords: {0}", documentProperties->get_Keywords());
}
else
{
    System::Console::WriteLine(u"The presentation was not loaded in document-properties-only mode.");
}

이 모드에서는 슬라이드 콘텐츠가 로드되지 않습니다. 슬라이드, 마스터, 레이아웃, 도형, 미디어 및 기타 프레젠테이션 객체를 사용할 수 없습니다. 전체 프레젠테이션 객체 모델이 필요한 작업을 수행하기 전에 항상 IProtectionManager::get_IsOnlyDocumentPropertiesLoaded를 확인해야 합니다.

암호화된 프레젠테이션 속성 업데이트

암호화된 PPTX 파일의 경우, LoadOptions::set_OnlyLoadDocumentProperties에 true를 전달하여 로드된 프레젠테이션은 공개 메타데이터를 읽기 위한 것입니다. Aspose.Slides는 해당 메타데이터 전용 객체에서 변경된 속성을 저장할 수 없습니다. 공개 속성은 암호화된 프레젠테이션 내부의 해당 데이터와 일관성을 유지해야 하기 때문입니다. 따라서 속성을 업데이트하려면 올바른 열기 암호와 전체 로드가 필요합니다.

이 예제는 공개 문서 속성이 있는 암호화된 PPTX 프레젠테이션과 알려진 열기 암호가 필요합니다. LoadOptions::set_Password를 사용해 전체 프레젠테이션을 열고, 공개 내장 속성을 업데이트한 뒤 결과를 저장합니다. 이어서 IPresentationInfo::get_IsEncrypted를 사용해 암호화가 유지되는지 확인하고, 암호 없이 공개 메타데이터를 다시 열어 새로운 값을 검증합니다:

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <DOM/LoadOptions.h>
#include <DOM/IProtectionManager.h>
#include <DOM/PresentationFactory.h>
#include <DOM/IPresentationInfo.h>
#include <Export/SaveFormat.h>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

const System::String inputPath = u"public-properties-encrypted.pptx";
const System::String outputPath = u"updated-public-properties-encrypted.pptx";

auto loadOptions = System::MakeObject<LoadOptions>();
loadOptions->set_Password(u"open_password");

auto presentation = System::MakeObject<Presentation>(inputPath, loadOptions);

auto documentProperties = presentation->get_DocumentProperties();
documentProperties->set_Title(u"Updated Product Roadmap");
documentProperties->set_Keywords(u"roadmap, planning, indexed");

presentation->Save(outputPath, SaveFormat::Pptx);

auto presentationInfo = PresentationFactory::get_Instance()->GetPresentationInfo(outputPath);
System::Console::WriteLine(u"The presentation is encrypted: {0}", presentationInfo->get_IsEncrypted());

auto metadataLoadOptions = System::MakeObject<LoadOptions>();
metadataLoadOptions->set_OnlyLoadDocumentProperties(true);

auto metadataPresentation = System::MakeObject<Presentation>(outputPath, metadataLoadOptions);

if (metadataPresentation->get_ProtectionManager()->get_IsOnlyDocumentPropertiesLoaded())
{
    System::Console::WriteLine(u"Title: {0}", metadataPresentation->get_DocumentProperties()->get_Title());
    System::Console::WriteLine(u"Keywords: {0}", metadataPresentation->get_DocumentProperties()->get_Keywords());
}
else
{
    System::Console::WriteLine(u"The presentation was not loaded in document-properties-only mode.");
}

응용 프로그램이 프레젠테이션 콘텐츠를 복호화하거나 로드할 수 없는 경우, 암호화된 PPTX 파일의 공개 속성을 읽기 전용으로 처리해야 합니다.

내장 속성 접근

IDocumentProperties 인터페이스는 get_Author, get_Title, get_CreatedTime와 같은 형식화된 getter를 통해 내장 메타데이터를 제공합니다. 이 예제는 기존 프레젠테이션을 열고 저장된 메타데이터를 콘솔에 출력합니다. 값은 입력 프레젠테이션에 따라 다르며, 일부 필드는 비어 있을 수 있습니다.

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>

using namespace Aspose::Slides;

auto presentation = System::MakeObject<Presentation>(u"AccessBuiltInProperties.pptx");

auto documentProperties = presentation->get_DocumentProperties();

System::Console::WriteLine(u"Category: {0}", documentProperties->get_Category());
System::Console::WriteLine(u"Content status: {0}", documentProperties->get_ContentStatus());
System::Console::WriteLine(u"Creation date: {0}", documentProperties->get_CreatedTime());
System::Console::WriteLine(u"Author: {0}", documentProperties->get_Author());
System::Console::WriteLine(u"Comments: {0}", documentProperties->get_Comments());
System::Console::WriteLine(u"Keywords: {0}", documentProperties->get_Keywords());
System::Console::WriteLine(u"Last modified by: {0}", documentProperties->get_LastSavedBy());
System::Console::WriteLine(u"Manager: {0}", documentProperties->get_Manager());
System::Console::WriteLine(u"Modified date: {0}", documentProperties->get_LastSavedTime());
System::Console::WriteLine(u"Presentation format: {0}", documentProperties->get_PresentationFormat());
System::Console::WriteLine(u"Last print date: {0}", documentProperties->get_LastPrinted());
System::Console::WriteLine(u"Is shared between producers: {0}", documentProperties->get_SharedDoc());
System::Console::WriteLine(u"Subject: {0}", documentProperties->get_Subject());
System::Console::WriteLine(u"Title: {0}", documentProperties->get_Title());

내장 속성 수정

내장 메타데이터를 업데이트하려면 IPresentation::get_DocumentProperties가 반환하는 객체의 setter를 사용합니다. 이 예제는 기존 프레젠테이션을 열고 set_Author, set_Title, set_Subject, set_Comments, set_Manager를 호출한 후 Presentation::Save로 업데이트된 프레젠테이션을 저장합니다. 저장된 PPTX에는 새로운 메타데이터가 포함됩니다.

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <Export/SaveFormat.h>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

auto presentation = System::MakeObject<Presentation>(u"ModifyBuiltInProperties.pptx");

auto documentProperties = presentation->get_DocumentProperties();

documentProperties->set_Author(u"Aspose.Slides for C++");
documentProperties->set_Title(u"Manage PowerPoint Presentation Properties");
documentProperties->set_Subject(u"Modify Built-in Properties");
documentProperties->set_Comments(u"Aspose description");
documentProperties->set_Manager(u"Aspose manager");

presentation->Save(u"DocumentProperties_output.pptx", SaveFormat::Pptx);

하이퍼링크 기본값 관리

IDocumentProperties::get_HyperlinkBase는 상대 하이퍼링크를 위한 문서 수준 기본값을 읽습니다. 이는 프레젠테이션과 연결된 파일을 다른 위치로 이동할 때 유용합니다. 이는 개별 하이퍼링크의 IHyperlink::get_ExternalUrl와 별개이며, 기본값을 변경해도 저장된 링크 주소가 다시 쓰이거나 절대 목적지가 변경되지 않습니다.

이 예제는 target.html와 같은 상대 링크와 https://example.org/absolute.html와 같은 절대 링크를 모두 포함하는 프레젠테이션이 필요합니다. 기존 기본값을 읽고 IDocumentProperties::set_HyperlinkBase를 사용해 새 기본 주소를 할당한 뒤 프레젠테이션을 저장하고 다시 열어 값을 확인합니다. 그런 다음 u""로 기본값을 지우고 별도의 저장 파일에서 빈 값을 검증합니다. 예제 기본 주소를 연결된 파일이 위치한 경로로 교체하십시오.

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <Export/SaveFormat.h>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

auto presentation = System::MakeObject<Presentation>(u"hyperlinks.pptx");

System::Console::WriteLine(u"Original base: {0}", presentation->get_DocumentProperties()->get_HyperlinkBase());

const System::String newBase = u"https://example.com/new/";
presentation->get_DocumentProperties()->set_HyperlinkBase(newBase);
presentation->Save(u"hyperlinks-updated.pptx", SaveFormat::Pptx);

auto updatedPresentation = System::MakeObject<Presentation>(u"hyperlinks-updated.pptx");
System::Console::WriteLine(u"Base preserved: {0}", (updatedPresentation->get_DocumentProperties()->get_HyperlinkBase() == newBase));

updatedPresentation->get_DocumentProperties()->set_HyperlinkBase(u"");
updatedPresentation->Save(u"hyperlinks-cleared.pptx", SaveFormat::Pptx);

auto clearedPresentation = System::MakeObject<Presentation>(u"hyperlinks-cleared.pptx");
System::Console::WriteLine(u"Base cleared: {0}", (clearedPresentation->get_DocumentProperties()->get_HyperlinkBase() == u""));

두 검증 메시지는 True를 출력해야 합니다. 기본값을 지워도 개별 하이퍼링크 주소는 그대로 유지됩니다.

target.pptx에 대한 상대 링크는 기본값이 old 폴더를 가리킬 때 old/target.pptx를 열었습니다. 기본값을 new 폴더로 변경하고 저장 및 프레젠테이션을 다시 열면 동일한 링크가 new/target.pptx를 엽니다. 절대 링크는 동일한 파일을 계속 엽니다. 프레젠테이션을 이동하거나 기본값을 변경하기 전후에 PowerPoint에서 상대 링크를 테스트하십시오.

사용자 정의 프레젠테이션 속성 추가

사용자 정의 속성은 해당하는 내장 필드가 없는 메타데이터를 저장합니다. IDocumentProperties::idx_set을 사용하면 속성 이름으로 값을 할당할 수 있습니다. 이 예제는 프레젠테이션을 생성하고 두 개의 텍스트 값과 정수 버전 값을 추가한 뒤 Presentation::Save으로 저장합니다. 기존 이름에 값을 할당하면 해당 속성의 값이 교체됩니다.

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

auto presentation = System::MakeObject<Presentation>();

auto documentProperties = presentation->get_DocumentProperties();

documentProperties->idx_set(u"Reviewed by", System::ObjectExt::Box<System::String>(u"John Smith"));
documentProperties->idx_set(u"Confidentiality level", System::ObjectExt::Box<System::String>(u"Internal"));
documentProperties->idx_set(u"Document version", System::ObjectExt::Box(2));

presentation->Save(u"CustomDocumentProperties_output.pptx", SaveFormat::Pptx);

사용자 정의 속성 접근 및 수정

이 예제는 사용자 정의 속성을 포함한 프레젠테이션을 열고 get_CountOfCustomProperties을 사용해 이를 순회합니다. GetCustomPropertyName은 0부터 시작하는 인덱스를 받아 IDocumentProperties::idx_get 및 idx_set에서 사용되는 이름을 반환합니다. 예제는 각 원래 이름과 값을 출력하고, 원래 유형에 관계없이 번호가 매겨진 문자열로 모든 값을 교체한 뒤 변경 사항을 저장합니다. 사용자 정의 속성이 없으면 루프는 아무 변경도 하지 않습니다.

#include <DOM/IDocumentProperties.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

auto presentation = System::MakeObject<Presentation>(u"AccessAndModifyProperties.pptx");

auto documentProperties = presentation->get_DocumentProperties();

for (auto i = 0; i < documentProperties->get_CountOfCustomProperties(); i++)
{
    auto propertyName = documentProperties->GetCustomPropertyName(i);
    auto propertyValue = documentProperties->idx_get(propertyName);

    System::Console::WriteLine(u"Custom property name: {0}", propertyName);
    System::Console::WriteLine(u"Custom property value: {0}", propertyValue);

    documentProperties->idx_set(propertyName, System::ObjectExt::Box(System::String::Format(u"New Value {0}", i + 1)));
}

presentation->Save(u"CustomProperties_output.pptx", SaveFormat::Pptx);

실시간 예제

Aspose.Slides API를 사용하여 문서 속성을 다루는 방법을 보려면 온라인 앱인 PowerPoint 메타데이터 보기 및 편집를 사용해 보십시오:

PowerPoint 메타데이터 보기 및 편집

자주 묻는 질문

프레젠테이션에서 내장 속성을 제거하려면 어떻게 해야 하나요?

내장 속성은 프레젠테이션의 필수 요소이며 완전히 제거할 수 없습니다. 그러나 특정 속성이 허용한다면 값을 변경하거나 빈 값으로 설정할 수 있습니다.

이미 존재하는 사용자 정의 속성을 추가하면 어떻게 되나요?

이미 존재하는 사용자 정의 속성을 추가하면 기존 값이 새 값으로 덮어쓰기됩니다. 속성을 미리 제거하거나 확인할 필요가 없으며, Aspose.Slides가 자동으로 속성 값을 업데이트합니다.

프레젠테이션을 완전히 로드하지 않고도 속성에 접근할 수 있나요?

예. PresentationFactory::GetPresentationInfo를 사용하고 이어서 IPresentationInfo::ReadDocumentProperties를 호출하면 Presentation 인스턴스를 생성하지 않고도 저장된 문서 메타데이터를 읽을 수 있습니다. 전체 보고 예제와 형식별 제한 사항은 Build a Lightweight Presentation Inventory를 참조하십시오.

암호화된 프레젠테이션의 공개 속성을 열기 암호 없이 읽을 수 있나요?

예. 프레젠테이션이 IProtectionManager::set_EncryptDocumentProperties에 false를 전달하여 암호화되었고, LoadOptions::set_OnlyLoadDocumentProperties에 true를 전달하여 로드된 경우에 가능합니다.

문서-속성 전용 모드에서 암호화된 PPTX 파일을 업데이트할 수 있나요?

아니요. 공개 속성과 암호화된 속성 데이터는 일관성을 유지해야 하므로, 암호화된 PPTX 파일을 업데이트하려면 올바른 열기 암호를 사용해 전체 프레젠테이션을 로드해야 합니다.