C#에서 XPS를 JPG로 변환하는 방법

C#에서 XPS를 JPG로 변환하는 방법

XPS 문서 형식을 사용하면 디지털 문서를 쉽게 공유, 생성, 인쇄 및 저장할 수 있지만 지원 소프트웨어를 설치해야 할 수 있습니다. .NET 프로그래머이고 프로그래밍 방식으로 XPS 파일을 JPG/JPEG 형식으로 내보내려는 경우 이 문서에서는 **C#**에서 XPS를 JPG로 변환하는 방법을 설명합니다.

이 기사에서 다룰 내용은 다음과 같습니다.

XPS를 JPG로 변환하는 C# .NET API

이 문서에서는 Conholdate.Total for .NET을 사용하여 XPS를 JPG로 변환합니다. 이 라이브러리를 사용하면 기존 및 새 XPS 문서를 생성, 편집 및 저장할 수 있습니다. 따라서 DLL을 다운로드하거나 NuGet을 사용하여 이 XPS 변환 API를 설치할 수 있습니다.

Install-Package Conholdate.Total 

C#에서 프로그래밍 방식으로 XPS를 JPG/JPEG로 변환하는 방법

XPS 변환 API를 사용하면 XPS 파일을 JPG로 변환할 수 있습니다.

다음은 XPS 파일을 JPG 이미지로 변환하는 단계입니다.

다음 코드 샘플은 C#을 사용하여 XPS를 JPG 변환으로 변환하는 방법을 보여줍니다.

string inputFileName = "input.xps";
//Outut file
string outputFileName = "XPStoImage_out.jpg";
// Initialize XPS input stream
using (Stream xpsStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read))
{
// Load XPS document form the stream
XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
// Initialize options object with necessary parameters.
JpegSaveOptions options = new JpegSaveOptions()
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
Resolution = 300,
PageNumbers = new int[] { 1, 2, 6 }
};
// Create rendering device for image
ImageDevice device = new ImageDevice();
document.Save(device, options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int i = 0; i < device.Result.Length; i++)
// Iterate through partition pages
for (int j = 0; j < device.Result[i].Length; j++)
{
// Initialize image output stream
using (Stream imageStream = System.IO.File.Open(Path.GetDirectoryName(outputFileName) +
Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) +
Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write))
// Write image
imageStream.Write(device.Result[i][j], 0, device.Result[i][j].Length);
}
}

무료 라이선스 받기

무료 임시 라이선스를 획득하여 평가 제한 없이 API를 테스트할 수 있습니다.

결론

이 기사를 마치기 위해 XPS 변환 API를 사용하여 C#에서 XPS를 JPG로 변환하는 방법을 배웠기를 바랍니다. 문서를 방문하여 XPS 변환 라이브러리의 다른 기능을 탐색할 수 있습니다.

질문하기

포럼에서 질문이나 쿼리를 알려주세요.

또한보십시오