캔버스 작업

XPS 파일의 캔버스 자르기 및 변환

 

문서에서 캔버스 관리는 Aspose.Page for .NET에서 제공하는 기능 중 하나입니다. 이것은 다른 페이지 설명 언어, 특히 XPS XPS로 작업하기 위한 솔루션입니다. 아래 예에서 다음을 수행하는 방법을 확인할 수 있습니다.

  • XPS 파일에 캔버스를 만듭니다.

  • 기본 캔버스에서 왼쪽 및 위쪽 오프셋을 만듭니다.

  • 변환된 변환이 있는 새 캔버스를 기본 캔버스에 추가합니다.

  • 기본 캔버스에 점 변환을 중심으로 회전하는 새 캔버스를 추가합니다.

  • 클립 캔버스. XPS 파일의 캔버스로 더 많은 조작이 가능합니다.

XPS 파일의 캔버스를 변환하려면 다음 가이드를 따르십시오.

  1. XpsDocument Class 를 사용하여 XPS 파일을 만듭니다.
  2. AddCanvas() 메서드를 사용하여 모든 페이지 요소에 공통인 기본 캔버스를 만듭니다.
  3. CreateMatrix() 메서드를 사용하여 기본 캔버스에서 왼쪽 및 위쪽 오프셋을 만듭니다.
  4. CreatePathGeometry() 메서드를 사용하여 사각형 경로 지오메트리를 만듭니다.
  5. XpsBrush 클래스를 사용하여 사각형 채우기를 만듭니다.
  6. 캔버스 2에서 사각형을 만들고 채우려면 XpsPath 클래스를 사용합니다.
  7. 이전 사각형 아래에 새 사각형을 배치하도록 캔버스 3을 변환하려면 CreateMatrix() 메서드를 사용합니다.
  8. 이 캔버스를 페이지 오른쪽으로 번역하려면 Translate() 메서드입니다.
  9. 캔버스 4의 크기를 조정하려면 Scale() 메서드를 호출합니다.
  10. 45도 지점을 중심으로 캔버스 5를 회전하려면 RotateAround() 메서드가 진행됩니다. 편리한.
  11. XPsDocument.Save() 메서드를 사용하여 변경된 XPS 문서를 저장합니다.

XPS 파일 캔버스 변환 C# 코드

    using Aspose.Page.Xps;
    using Aspose.Page.Xps.XpsModel;
    using System.Drawing;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Create main canvas, common for all page elemnts
    XpsCanvas canvas1 = doc.AddCanvas();

    // Make left and top offsets in the main canvas
    canvas1.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 20, 10);

    // Create the rectangle path geometry
    XpsPathGeometry rectGeom = doc.CreatePathGeometry("M 0,0 L 200,0 200,100 0,100 Z");

    // Create a fill for rectangles
    XpsBrush fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));
            
    // Add new canvas without any transformations to the main canvas
    XpsCanvas canvas2 = canvas1.AddCanvas();
    // Create rectangle in this canvas and fill it
    XpsPath rect = canvas2.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with translate transformation to the main canvas
    XpsCanvas canvas3 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas3.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 200);
    // Translate this canvas to the right side of the page
    canvas3.RenderTransform.Translate(500, 0);
    // Create the rectangle in this canvas and fill it
    rect = canvas3.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with the double scale transformation to the main canvas
    XpsCanvas canvas4 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas4.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 400);
    // Scale this canvas
    canvas4.RenderTransform.Scale(2, 2);
    // Create a rectangle in this canvas and fill it
    rect = canvas4.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with rotation around a point transformation to the main canvas
    XpsCanvas canvas5 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas5.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 800);
    // Rotate this canvas aroud a point on 45 degrees
    canvas5.RenderTransform.RotateAround(45, new PointF(100, 50));
    rect = canvas5.AddPath(rectGeom);
    rect.Fill = fill;
            
    // Save the resultant XPS document
    doc.Save(dataDir + "output1.xps");
다음 코드 조각은 .NET Api 솔루션용 Aspose.Page 내에서 XPS 파일의 캔버스를 자르는 방법을 보여줍니다.

XPS 파일의 캔버스를 자르려면 다음 가이드를 따르십시오.

  1. XpsDocument Class를 사용하여 XPS 파일을 만들거나 엽니다.
  2. AddCanvas() 메서드를 사용하여 모든 페이지 요소에 공통인 기본 캔버스를 만듭니다.
  3. CreateMatrix() 메서드를 사용하여 기본 캔버스에서 왼쪽 및 위쪽 오프셋을 만듭니다.
  4. CreatePathGeometry() 메서드를 사용하여 사각형 경로 지오메트리를 만듭니다.
  5. XpsBrush 클래스를 사용하여 사각형 채우기를 만듭니다.
  6. 기본 캔버스에 클립이 있는 다른 캔버스를 추가하려면 AddCanvas() 메서드를 다시 호출합니다.
  7. XpsPathGeometry 클래스를 사용하여 클립에 대한 원 형상을 만듭니다.
  8. 이 캔버스에 사각형을 만들고 채우려면 XpsPath 클래스를 사용합니다.
  9. AddCanvas() 메서드를 사용하여 다른 캔버스를 추가한 다음 이 캔버스에 사각형을 만들고 XpsPathGeometry 클래스로 획을 그립니다.
  10. XPsDocument.Save() 메서드를 사용하여 변경된 XPS 문서를 저장합니다.

XPS 파일 캔버스 클리핑 C# 코드

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Create main canvas, common for all page elemnts
    XpsCanvas canvas1 = doc.AddCanvas();

    // Make left and top offsets in the main canvas
    canvas1.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 20, 10);

    // Create the rectangle path geometry
    XpsPathGeometry rectGeom = doc.CreatePathGeometry("M 0,0 L 500,0 500,300 0,300 Z");

    // Create a fill for rectangles
    XpsBrush fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));
            
    // Add another canvas with the clip to the main canvas
    XpsCanvas canvas2 = canvas1.AddCanvas();

    // Create circle geometry for the clip
    XpsPathGeometry clipGeom = doc.CreatePathGeometry("M250,250 A100,100 0 1 1 250,50 100,100 0 1 1 250,250");
    canvas2.Clip = clipGeom;

    // Create rectangle in this canvas and fill it
    XpsPath rect = canvas2.AddPath(rectGeom);
    rect.Fill = fill;

    // Add the second canvas with stroked rectangle to the main canvas
    XpsCanvas canvas3 = canvas1.AddCanvas();

    // Create rectangle in this canvas and stroke it
    rect = canvas3.AddPath(rectGeom);
    rect.Stroke = fill;
    rect.StrokeThickness = 2;

    // Save resultant XPS document
    doc.Save(dataDir + "output2.xps");



자주하는 질문

1. XPS 파일에 캔버스를 어떻게 추가할 수 있나요?

문서 디렉터리의 경로를 설정합니다. 캔버스를 추가하려면 AddCanvas() 메서드를 사용하세요.

2. XPS 파일에서 캔버스 오프셋을 조작하는 방법은 무엇입니까?

문서 디렉터리의 경로를 설정하고 캔버스를 추가합니다. 오프셋을 만들려면 CreateMatrix() 메서드를 사용하세요.

3. XPS 파일의 캔버스에 어떤 작업이 지원됩니까?

캔버스를 만들고, 자르고, 추가할 수 있을 뿐만 아니라 캔버스의 오프셋을 조작할 수도 있습니다.

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

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