XPS 패키지 내에서 패키지 간 작업

C#을 통해 XPS 패키지 내에서 페이지, 색상 및 글리프 조작

 

.NET용 Aspose.Page API 솔루션에는 XPS 파일 작업을 위한 별도의 라이브러리로 XPS 패키지가 포함되어 있습니다. 풍부한 기능에는 파일 병합, 변환, 그래픽 작업 등과 같은 많은 유용하고 인기 있는 기능이 포함되어 있습니다.

XPS는 하나의 문서에 여러 파일을 저장할 수 있습니다. 따라서 모든 XPS 패키지에는 문서 내부와 다른 XPS 문서 간에 해당 파일과 페이지를 조작하는 기능이 있어야 합니다. 이러한 조작을 패키지 간 작업이라고 합니다. 별도로 설명해야 합니다.

여기에서 페이지 조작, 글리프 및 색상 추가와 같은 패키지 간 작업의 예를 찾을 수 있습니다.

XPS 패키지 C# 내에서 페이지를 조작하는 단계입니다.

  1. 문서 디렉토리의 경로를 설정하십시오.
  2. XpsDocument Class 를 사용하여 XPS 파일을 만듭니다.
  3. 한 문서의 활성 페이지를 다른 문서의 시작 부분에 삽입하려면 InsertPage() 방법.
  4. 한 문서에서 다른 문서 끝까지 활성 페이지를 삽입하려면 AddPage() 메서드를 사용합니다.
  5. 빈 페이지를 제거하려면 RemovePage() 메서드를 사용하세요.
  6. 한 문서에서 다른 문서로 페이지를 제거하려면 InsertPage()SelectActivePage() 방법.
  7. XPsDocument.Save 를 사용하여 변경된 XPS 문서를 저장합니다.

페이지를 사용한 패키지 간 조작을 위한 C# 코드

    using Aspose.Page.XPS;
    using Aspose.Page.XPS.XpsModel;
    using System.Drawing;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();

    // Create the first XPS Document
    XpsDocument doc1 = new XpsDocument(dataDir + "input1.xps");

    // Create the second XPS Document
    XpsDocument doc2 = new XpsDocument(dataDir + "input2.xps");

    // Create the third XPS Document
    XpsDocument doc3 = new XpsDocument(dataDir + "input3.xps");

    // Create the fourth XPS Document
    XpsDocument doc4 = new XpsDocument();

    // Insert the active page (1 in this case) from the second document to the beginning of the fourth document
    doc4.InsertPage(1, doc2.Page, false);

    // Insert the active page (1 in this case) from the third document to the end of the fourth document
    doc4.AddPage(doc3.Page, false);

    // Remove page 2 from the fourth document. This is an empty page that was created when the document had 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 + "out.xps");

XPS 패키지 C# 내에 글리프 클론을 추가하는 단계.

  1. 문서 디렉토리의 경로를 설정하십시오.
  2. XPS 파일의 스트림을 엽니다.
  3. XpsDocument 클래스를 사용하여 XPS 파일을 만듭니다.
  4. AddGlyphs() 메서드를 사용하여 문서에 글리프를 추가합니다.
  5. XpsDocument 클래스를 사용하여 두 번째 XPS 파일을 만듭니다.
  6. 첫 번째 파일에서 두 번째 파일로 글리프를 복제하려면 Add()Clone() 메서드.
  7. XPsDocument.Save() 메서드를 사용하여 두 XPS 문서를 모두 저장합니다.

XPS 패키지 내에서 글리스를 복사하는 C# 코드

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();

    // Create the first XPS Document
    XpsDocument doc1 = new XpsDocument();

    // Add glyphs to the first document
    XpsGlyphs glyphs = doc1.AddGlyphs("Times New Roman", 200, FontStyle.Bold, 50, 250, "Test");

    // Fill glyphs in the first document with one color
    glyphs.Fill = doc1.CreateSolidColorBrush(Color.Green);

    // Create the second XPS Document
    XpsDocument doc2 = new XpsDocument();

    // Add glyphs cloned from the one's from the first document
    glyphs = doc2.Add(glyphs.Clone());

    // Fill glyphs in the second document with another color
    ((XpsSolidColorBrush)glyphs.Fill).Color = doc2.CreateColor(Color.Red);

    // Save the first XPS document
    doc1.Save(dataDir + "out1.xps");

    // Save the second XPS document
    doc2.Save(dataDir + "out2.xps");

이미지로 채워진 Glyph C#을 추가하는 단계입니다.

  1. 문서 디렉토리의 경로를 설정하십시오.
  2. XPS 파일의 스트림을 엽니다.
  3. XpsDocument 클래스를 사용하여 XPS 파일을 만듭니다.
  4. AddGlyphs() 메서드를 사용하여 문서에 글리프를 추가합니다.
  5. 이미지 브러시로 글리프를 채우려면 CreateImageBrush() 메서드를 사용합니다.
  6. XpsDocument 클래스를 사용하여 두 번째 XPS 파일을 만듭니다.
  7. AddGlyphs() 메서드를 사용하여 첫 번째 문서의 글꼴이 있는 글리프를 두 번째 문서에 추가합니다.
  8. 첫 번째 문서의 채우기에서 이미지 브러시를 만들고 CreateImageBrush() 메서드를 사용하여 두 번째 문서의 글리프를 채웁니다.
  9. XPsDocument.Save() 메서드를 사용하여 두 XPS 문서를 모두 저장합니다.

XPS 패키지 내에서 이미지로 채워진 글리프를 만드는 C# 코드

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();

    // Create the first XPS Document
    XpsDocument doc1 = new XpsDocument();

    // Add glyphs to the first document
    XpsGlyphs glyphs1 = doc1.AddGlyphs("Times New Roman", 200, FontStyle.Bold, 50, 250, "Test");

    // Fill the glyphs with an image brush
    glyphs1.Fill = doc1.CreateImageBrush(dataDir + "R08SY_NN.tif", new RectangleF(0f, 0f, 128f, 192f),
        new RectangleF(0f, 0f, 64f, 96f));
    ((XpsImageBrush)glyphs1.Fill).TileMode = XpsTileMode.Tile;

    // Create the second XPS Document
    XpsDocument doc2 = new XpsDocument();

    // Add glyphs with the font from the first document to the second document
    XpsGlyphs glyphs2 = doc2.AddGlyphs(glyphs1.Font, 200, 50, 250, "Test");

    // Create an image brush from the fill of the the first document and fill glyphs in the second document
    glyphs2.Fill = doc2.CreateImageBrush(((XpsImageBrush)glyphs1.Fill).Image, new RectangleF(0f, 0f, 128f, 192f),
        new RectangleF(0f, 0f, 128f, 192f));
    ((XpsImageBrush)glyphs2.Fill).TileMode = XpsTileMode.Tile;

    // Save the first XPS document
    doc1.Save(dataDir + "out1.xps");

    // Save the second XPS document
    doc2.Save(dataDir + "out2.xps");



자주하는 질문

1. XPS 패키지란 무엇입니까?

XPS 패키지는 XPS 파일을 관리하기 위한 별도의 라이브러리입니다. 이를 사용하여 자신만의 변환기, 리더 또는 기타 앱을 만들어 XPS를 편집할 수 있습니다.

2. XPS 패키지를 어떻게 얻을 수 있나요?

XPS 패키지는 Aspose.Page 솔루션에 포함되어 있습니다.

3. 어떤 패키지 간 작업을 사용할 수 있나요?

Aspose XPS 패키지를 사용하면 한 문서에서 다른 문서로 페이지를 전송하고 글리프, 스타일 또는 설정과 같은 개체를 복제할 수 있습니다.

4. XPS 문서 간 페이지를 조작하는 방법은 무엇입니까?

이 XPS 패키지로 파일을 전송하려면 XpsDocument 클래스의 InsertPage(), AddPage(), RemovePage()SelectActivePage() 메서드를 사용하십시오.

XPS XPS 파일 형식이란 무엇입니까?

XPS 형식은 PDF 형식과 유사합니다. 둘 다 PDL(페이지 설명 언어) 형식입니다. EPS는 PostScript 언어가 아닌 HTML을 기반으로 합니다. .eps 파일은 문서가 어떻게 생겼는지에 대한 정보와 함께 문서 구조의 마크업을 포함할 수 있습니다. 문서를 인쇄하고 렌더링하는 방법에 대한 지침도 추가되었습니다. 형식의 특징은 문서의 설명을 수정한다는 것입니다. 즉, 누가, 어떤 운영 체제에서 문서를 열더라도 동일하게 보일 것입니다.