XPS Converter per a .NET

Introducció a XPS Converter per a .NET

El XPS Converter per a .NET és una potent biblioteca que permet als desenvolupadors convertir els arxius de xps (XML Paper Specification) en diversos formats d’imatge, incloent PNG, JPEG, TIFF, i més.

Convertir XPS a PDF

La conversió d’un arxiu XPS és un procés senzill que implica carregar el fitxer xps i especificar el format de sortida. l’exemple de codi següent demostra com convertir un fitxer xPS en un document PDF:

XpsConverter converter = new XpsConverter();
XpsConverterToPdfOptions opt = new XpsConverterToPdfOptions();
opt.AddDataSource(new FileDataSource("input.xps"));
opt.AddSaveDataSource(new FileDataSource("output.pdf"));
converter.Process(opt);

In this example, we load the XPS file from a stream and create a new XpsConverter object. We then specify the output format as PDF and save the document to a new stream.

Convertir XPS en imatges

La conversió d’un arxiu XPS és un procés senzill que implica carregar el fitxer xps i especificar el format de sortida. l’exemple de codi següent demostra com convertir un fitxer xPS a una imatge PNG:

XpsConverter converter = new XpsConverter();
PsConverterToImageOptions opt = new PsConverterToImageOptions();
opt.AddDataSource(new FileDataSource("input.xps"));
opt.AddSaveDataSource(new FileDataSource("output.png"));
converter.Process(opt);

In this example, we load the XPS file from a stream and create a new XpsConverter object. We then specify the output format as PNG and save the document to a new stream.

Formats de sortida suportats

El XPS Converter per a .NET suporta una àmplia gamma de formats de sortida, incloent:

  • PNG (Grafica de xarxes portàtils)
  • JPEG (Grup d’Experts Fotogràfics Comú)
  • TIFF (Format de fitxers d’imatge etiquetat)
  • El mapa (Bitmap)
  • GIF (Format d’intercanvi gràfic)

Resoldre errors i excepcions

El XPS Converter per a .NET llança excepcions si es produeix un error durant el procés de conversió.

try
{
    XpsConverter converter = new XpsConverter();
    XpsConverterToPdfOptions opt = new XpsConverterToPdfOptions();
    opt.AddDataSource(new FileDataSource("input.xps"));
    opt.AddSaveDataSource(new FileDataSource("output.pdf"));
    converter.Process(opt);
}
catch (NotSupportedException ex)
{
    Console.WriteLine($"Error converting file: {ex.Message}");
}

Note that the NotSupportedException class provides additional information about the error, such as the error code and message.

 Català