XPS 패키지 내의 패키지 간 연산
C++를 통해 XPS 패키지 내의 페이지, 색상 및 글리프 조작하기
Aspose.Page for C++ API는 XPS 파일 처리를 위한 별도의 라이브러리를 제공하여, XPS 파일을 고유한 형식으로 다룰 수 있게 해줍니다. 이 라이브러리는 XPS 문서 병합, 다른 형식으로의 변환, 그리고 그 안의 그래픽 조작 등 다양하고 유용한 기능을 자랑합니다.
XPS 파일의 핵심적인 특징 중 하나는 단일 문서 내에 여러 파일을 포함할 수 있다는 것입니다. 결과적으로 Aspose.Page XPS 라이브러리는 이러한 내부 파일과 해당 페이지들을 관리하기 위한 기능을 제공합니다. "패키지 간 연산(cross-package operations)"으로 알려진 이러한 작업에는, 서로 다른 XPS 문서 간의 콘텐츠를 조작하는 과정이 포함됩니다.
이 섹션에서는 단일 XPS 문서 내의 페이지 관리 및 특정 색상의 텍스트(글리프) 추가와 같은 패키지 간 연산의 구체적인 예제를 자세히 다룹니다.
그러나 이 기능을 사용해 보려면 먼저 솔루션을 가져와야 합니다:
NuGet 패키지 관리자를 열고 Aspose.Page를 검색하여 설치하십시오. 패키지 관리자 콘솔(Package Manager Console)에서 다음 명령을 사용할 수도 있습니다.
XPS 패키지 C++에서 페이지를 조작하는 단계.
- 문서 디렉토리의 경로를 설정합니다.
- XpsDocument Class 를 사용하여 XPS 파일을 생성합니다.
- 한 문서의 활성 페이지를 다른 문서의 시작 부분에 삽입하려면 InsertPage() 메서드를 사용합니다.
- 한 문서의 활성 페이지를 다른 문서의 끝에 삽입하려면 AddPage() 메서드를 사용합니다.
- 빈 페이지를 제거하려면 RemovePage() 메서드를 사용합니다.
- 한 문서에서 다른 문서로 페이지를 제거(이동)하려면 InsertPage() 및 SelectActivePage() 메서드를 사용합니다.
- XPsDocument.Save 메서드를 사용하여 변경된 XPS 문서를 저장합니다.
페이지 조작
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
System::SharedPtr<XpsDocument> doc1 = System::MakeObject<XpsDocument>(dataDir + u"input1.xps");
// Create the second XPS Document
System::SharedPtr<XpsDocument> doc2 = System::MakeObject<XpsDocument>(dataDir + u"input2.xps");
// Create the third XPS Document
System::SharedPtr<XpsDocument> doc3 = System::MakeObject<XpsDocument>(dataDir + u"input3.xps");
// Create the fourth XPS Document
System::SharedPtr<XpsDocument> doc4 = System::MakeObject<XpsDocument>();
// Insert active page (1 in this case) from the second document to the beginning of the fourth document
doc4->InsertPage(1, doc2->get_Page(), false);
// Insert active page (1 in this case) from the third document to the end of the fourth document
doc4->AddPage(doc3->get_Page(), false);
// Remove page 2 from the fourth document. This is an empty page that was created when document has been created.
doc4->RemovePageAt(2);
// Insert page 3 from the first document to the second postion of the fourth document
doc4->InsertPage(2, doc1->SelectActivePage(3), false);
// Save the fourth XPS document
doc4->Save(dataDir + u"output/" + u"out.xps");
XPS 패키지 C++ 내에 글리프 클론을 추가하는 단계.
- 문서 디렉토리의 경로를 설정합니다.
- XPS 파일의 스트림을 엽니다.
- XpsDocument Class를 사용하여 XPS 파일을 생성합니다.
- AddGlyphs() 메서드를 사용하여 문서에 글리프를 추가합니다.
- XpsDocument Class를 사용하여 두 번째 XPS 파일을 생성합니다.
- 첫 번째 파일에서 두 번째 파일로 글리프를 복제(클론)하려면 Add() 및 Clone() 메서드를 사용합니다.
- XPsDocument.Save() 메서드를 사용하여 두 XPS 문서를 모두 저장합니다.
글리프 클론 추가 및 색상 변경
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
System::SharedPtr<XpsDocument> doc1 = System::MakeObject<XpsDocument>();
// Add glyphs to the first document
System::SharedPtr<XpsGlyphs> glyphs = doc1->AddGlyphs(u"Times New Roman", 200.0f, System::Drawing::FontStyle::Bold, 50.0f, 250.0f, u"Test");
// Fill glyphs in the first document with one color
glyphs->set_Fill(doc1->CreateSolidColorBrush(System::Drawing::Color::get_Green()));
// Create the second XPS Document
System::SharedPtr<XpsDocument> doc2 = System::MakeObject<XpsDocument>();
// Add glyphs cloned from the one's from the first document
glyphs = doc2->Add<System::SharedPtr<XpsGlyphs>>(glyphs->Clone());
// Fill glyphs in the second document with another color
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsSolidColorBrush>(glyphs->get_Fill()))->set_Color(doc2->CreateColor(System::Drawing::Color::get_Red()));
// Save the first XPS document
doc1->Save(dataDir + u"output/" + u"out1.xps");
// Save the second XPS document
doc2->Save(dataDir + u"output/" + u"out2.xps");
C++에서 이미지로 채워진 글리프를 추가하는 단계.
- 문서 디렉토리의 경로를 설정합니다.
- XPS 파일의 스트림을 엽니다.
- XpsDocument Class를 사용하여 XPS 파일을 생성합니다.
- AddGlyphs() 메서드를 사용하여 문서에 글리프를 추가합니다.
- 글리프를 이미지 브러시(image brush)로 채우려면 CreateImageBrush() 메서드를 사용합니다.
- XpsDocument Class를 사용하여 두 번째 XPS 파일을 생성합니다.
- AddGlyphs() 메서드를 사용하여 첫 번째 문서의 글꼴이 있는 글리프를 두 번째 문서에 추가합니다.
- 첫 번째 문서의 채우기에서 이미지 브러시를 생성하고 CreateImageBrush() 메서드를 사용하여 두 번째 문서의 글리프를 채웁니다.
- XPsDocument.Save() 메서드를 사용하여 두 XPS 문서를 모두 저장합니다.
이미지로 채워진 글리프 및 외부 이미지 추가
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
System::SharedPtr<XpsDocument> doc1 = System::MakeObject<XpsDocument>();
// Add glyphs to the first document
System::SharedPtr<XpsGlyphs> glyphs1 = doc1->AddGlyphs(u"Times New Roman", 200.0f, System::Drawing::FontStyle::Bold, 50.0f, 250.0f, u"Test");
// Fill the glyphs with an image brush
glyphs1->set_Fill(doc1->CreateImageBrush(dataDir + u"R08SY_NN.tif", System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f), System::Drawing::RectangleF(0.f, 0.f, 64.f, 96.f)));
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(glyphs1->get_Fill()))->set_TileMode(Aspose::Page::XPS::XpsModel::XpsTileMode::Tile);
// Create the second XPS Document
System::SharedPtr<XpsDocument> doc2 = System::MakeObject<XpsDocument>();
// Add glyphs with the font from the first document to the second document
System::SharedPtr<XpsGlyphs> glyphs2 = doc2->AddGlyphs(glyphs1->get_Font(), 200.0f, 50.0f, 250.0f, u"Test");
// Create an image brush from the fill of the the first document and fill glyphs in the second document
glyphs2->set_Fill(doc2->CreateImageBrush((System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(glyphs1->get_Fill()))->get_Image(), System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f), System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f)));
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(glyphs2->get_Fill()))->set_TileMode(Aspose::Page::XPS::XpsModel::XpsTileMode::Tile);
// Save the first XPS document
doc1->Save(dataDir + u"output/" + u"out1.xps");
// Save the second XPS document
doc2->Save(dataDir + u"output/" + u"out2.xps");XPS XPS 파일 형식이란 무엇입니까?
XPS (XML Paper Specification) は、Microsoft が提供する PDF の代替フォーマットです。XML/HTML ベースで、プラットフォームに依存せずレイアウトを保持します。