Articles in this section
Category / Section

How to export the pages in PDF document to multi-page tiff image in WPF PDFViewer?

1 min read

You can export the pages in the PDF document to images and then convert the exported images to multi-page tiff image in WPF PDF Viewer.

The following code snippet illustrates the conversion of pages in the PDF document to multi-page tiff image:

C#:

//create an instance for PdfLoadedDocument
PdfLoadedDocument ldoc = new PdfLoadedDocument("../../Data/Manual.pdf");
//ExportAsImage method returns specified page in the PDF document as Bitmap image 
Bitmap[] images = ldoc.ExportAsImage(0, ldoc.Pages.Count - 1);
//Tiff conversion
ImageCodecInfo encoderInfo = GetEncoderInfo("image/tiff");
//Initialize EncoderParameters that contain specified number of Encoderparameter objects
EncoderParameters encoderParams = new EncoderParameters(2);
//Initialize EncoderParameter
EncoderParameter parameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionNone);
encoderParams.Param[0] = parameter;
//Initialize the new instance for EncoderParameter
parameter = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
encoderParams.Param[1] = parameter;
System.Drawing.Image tiff = null;
for (int i = 0; i < images.Length; i++)
{
   if (i == 0)
   {
      tiff = images[i];
      //Save the tiff image into local disk
      tiff.Save("../../Output/output.tiff", encoderInfo, encoderParams);
   }
   else
   {
      System.Drawing.Image image = images[i];
      //Initialize the new instance for EncoderParameter
      parameter = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);
      encoderParams.Param[1] = parameter;
      //Add the subsequent image to save into the local disk
      tiff.SaveAdd(image, encoderParams);
   }
}

View sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied