How to Convert the Pages of a File to PNG Images
This guide explains how to convert the pages of a file to PNG images.
First, create a PrizmDocServerClient:
var prizmDocServer = new PrizmDocServerClient(/* your connection info */);
Then, call ConvertAsync to take a local file, such as
"project-proposal.docx"
, and have PrizmDoc Server convert each page of the
document to a PNG:
IEnumerable<ConversionResult> results = await prizmDocServer.ConvertAsync("project-proposal.docx", DestinationFileFormat.Png);
This will upload the file to PrizmDoc Server, ask PrizmDoc Server to convert the pages to PNGs, and then return once the conversion is complete.
The returned results are just metadata about the output; the actual output
files have not been downloaded yet. To actually download the results from
PrizmDoc Server, iterate through each of the results and call
SaveAsync
on each result:
for (var i=0; i < results.Count(); i++)
{
await results[i].RemoteWorkFile.SaveAsync($"page-{i+1}.png");
}
Here is a complete example:
using System;
using System.Linq;
using System.Threading.Tasks;
using Accusoft.PrizmDocServer;
namespace Demos
{
class Program
{
static void Main(string[] args)
{
MainAsync().GetAwaiter().GetResult();
}
static async Task MainAsync()
{
var prizmDocServer = new PrizmDocServerClient(/* your connection info */);
// Take a DOCX file and convert each of its pages to a PNG.
IEnumerable<ConversionResult> results = await prizmDocServer.ConvertAsync("project-proposal.docx", DestinationFileFormat.Png);
// Save each result to a PNG file.
for (var i=0; i < results.Count(); i++)
{
await results.ElementAt(i).RemoteWorkFile.SaveAsync($"page-{i+1}.png");
}
}
}
}
There are additional overloads of ConvertAsync which provide more flexibility. See the PrizmDocServerClient API reference for more information.