XPS 파일 생성 및 수정
XPS 파일을 생성하고 변경하기 위한 C# .NET API 솔루션.
Aspose.Page for .NET API 솔루션을 사용하면 다른 페이지 기술 언어 형식 파일과 함께 XPS 파일을 조작할 수 있습니다. 풍부한 기능을 통해 문서에 다양한 도형을 추가하거나, 여러 파일을 하나로 병합하거나, 더 나은 형식으로 변환할 수 있습니다. 여기서는 새 XPS 파일을 생성하고 기존 파일을 수정(서명 추가)하는 방법을 설명합니다. 이해를 돕기 위해 코드 스니펫이 추가되었습니다.
XPS 파일을 조작하려면 다음이 필요합니다.
C# 플랫폼을 위한 기능이 풍부하고 강력하며 사용하기 쉬운 문서 조작 및 변환 API인 Aspose.Page for .NET API.
NuGet 패키지 관리자를 열고 Aspose.Page를 검색하여 설치합니다. 패키지 관리자 콘솔에서 다음 명령을 사용할 수도 있습니다.
Package Manager Console Command
PM> Install-Package Aspose.Page
C# .NET으로 XPS 파일을 생성하는 단계.
- 문서 디렉토리 경로를 설정합니다.
- XpsDocument 클래스 를 사용하여 XPS 파일을 생성합니다.
- 필요한 경우 AddGlyphs() 메서드를 사용하여 문서에 글리프를 추가합니다.
- XPsDocument.Save() 메서드를 사용하여 변경된 XPS 문서를 저장합니다.
XPS 파일을 만들기 위한 C# 코드
using Aspose.Page.XPS;
using Aspose.Page.XPS.XpsModel;
using System.Drawing; // The path to the documents directory.
string dir = RunExamples.GetDataDir_WorkingWithDocument();
// Create a new XPS Document
XpsDocument xDocs = new XpsDocument();
// Add the glyph to the document
var glyphs = xDocs.AddGlyphs("Arial", 12, FontStyle.Regular, 300f, 450f, "Hello World!");
glyphs.Fill = xDocs.CreateSolidColorBrush(Color.Black);
// Save the result
xDocs.Save(dir + "output.xps");C# .NET으로 XPS 파일을 수정하는 단계.
- 문서 디렉토리 경로를 설정합니다.
- XPS 파일의 스트림을 엽니다.
- XpsDocument 클래스를 사용하여 XPS 파일을 생성합니다.
- 서명 텍스트의 채우기를 생성하려면 CreateSolidColorBrush() 메서드를 사용합니다.
- 서명이 설정될 페이지를 정의하려면 PageNumbers 속성을 사용합니다.
- SelectActivePage 및 AddGlyphs() 메서드를 사용하여 서명을 조정합니다.
- XPsDocument.Save() 메서드를 통해 변경된 XPS 문서를 저장합니다.
XPS 파일을 편집하기 위한 C# 코드
// The path to the documents directory.
string dir = RunExamples.GetDataDir_WorkingWithDocument();
// Open a stream of XPS file
using (FileStream xpsStream = File.Open(dir + "input1.xps", FileMode.Open, FileAccess.Read))
{
// Create an XPS document from stream
XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
// Create the fill of the signature text
XpsSolidColorBrush textFill = document.CreateSolidColorBrush(Color.BlueViolet);
// Define pages where the signature will be set
int[] pageNumbers = new int[] {1, 2, 3};
// For every defined page set signature "Confirmed" at coordinates x=650 and y=950
for (int i = 0; i < pageNumbers.Length; i++)
{
// Define an active page
document.SelectActivePage(pageNumbers[i]);
// Create a glyphs object
XpsGlyphs glyphs = document.AddGlyphs("Arial", 24, FontStyle.Bold, 650, 900, "Confirmed");
// Define the fill for glyphs
glyphs.Fill = textFill;
}
// Save the changed XPS document
document.Save(dir + "input1_out.xps");
}자주하는 질문
1. XPS 파일을 어떻게 편집할 수 있나요?
이 API 솔루션을 사용하여 XPS 파일을 수정하려면 먼저 파일 경로를 설정한 다음 XpsDocument 클래스의 엔터티를 사용하여 변경 사항을 구현합니다.
2. XPS 파일을 만드는 방법은 무엇입니까?
Aspose.Page를 사용하여 새 XPS 파일을 만들려면 문서 경로를 설정한 다음 XpsDocument 클래스의 XpsDocument 생성자를 사용해야 합니다.
3. XPS를 DOCX로 어떻게 변환하나요?
XPS 파일에서 DOCX 파일을 얻으려면 무료 크로스 플랫폼 변환기 를 사용하세요.
XPS What is XPS File Format
XPS (XML Paper Specification) は、Microsoft が提供する PDF の代替フォーマットです。XML/HTML ベースで、プラットフォームに依存せずレイアウトを保持します。