←Select platform

CodecsRasterPdfInfo Structure

Summary

Contains information for a raster PDF file created using the support available in the LEADTOOLS PDF Pro, Pro Suite, Document or Medical products.

Syntax
C#
VB
Objective-C
C++
Java
public struct CodecsRasterPdfInfo 
Public Structure CodecsRasterPdfInfo  
   Inherits System.ValueType 
@interface LTCodecsRasterPdfInfo : NSObject 
public final class CodecsRasterPdfInfo 
public value class CodecsRasterPdfInfo : public System.ValueType  

Remarks

The various RasterCodecs.GetInformation methods are used to return information about a raster image file on disk or stream. Information such as the format, size, dimension, bits per pixel are returned as members of the CodecsImageInfo object returned from RasterCodecs.GetInformation.

Raster Adobe PDF saved with the various Save methods (using any of the RasterImageFormat.RasPdfXyz flavors), contain extra information that can be obtained using RasterCodecs.GetRasterPdfInfo. This method returns an instance of CodecsRasterPdfInfo filled with these extra information as follows:

Member Description
IsLeadPdf

true if the source file was created with the PDF support available in the LEADTOOLS PDF Pro, Pro Suite, Document or Medicalproducts; otherwise, false. If the value of this property is true, then other members of this structure are guaranteed to contain accurate information. If the value of this property is false and Format is one of the PDF flavors (RasterImageFormat.RasPdfXyz, then the source file is a PDF not created with LEADTOOLS, and the other members of this structure may not be guaranteed to contain accurate information (except for Width, Height, XResolution and YResolution). If this property is true, then calling RasterCodecs.DeletePage is guaranteed to work on this file.

BitsPerPixel

The bits per pixel value of the raster PDF page. This is the same value used as the bitsPerPixel parameter value to the RasterCodecs.Save method used to create this file. Set the value of CodecsPdfLoadOptions.DisplayDepth to this value to load a PDF page in the original bits per pixel value it was saved at.

Format

The format (compression type) of the raster PDF page, one of RasterImageFormat.RasPdfXyz. This is the same value used as the format parameter value to the RasterCodecs.Save method used to create this file.

Width

The width of the page in pixels. This is the same width of the RasterImage object to the RasterCodecs.Save method used to create this file.

Height

The height of the page in pixels. This is the same height of the RasterImage object to the RasterCodecs.Save method used to create this file.

XResolution

The horizontal resolution of the page in dots per inch. This is the same horizontal resolution of the RasterImage object to the RasterCodecs.Save method used to create this file if CodecsPdfSaveOptions.UseImageResolution was set to true.

YResolution

The vertical resolution of the page in dots per inch. This is the same vertical resolution of the RasterImage object to the RasterCodecs.Save method used to create this file. if CodecsPdfSaveOptions.UseImageResolution was set to true.

Version

The version of the PDF file. This is the same value as CodecsPdfSaveOptions.Version used when saving this file with the RasterCodecs.Save method.

Example

This example will create a multipage raster PDF file with each page having its own size, compression and bits/pixel. Then uses CodecsRasterPdfInfo to split this file into several pages with each page saved with the original compression, size and dimension obtained from the file directly.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
 
private static void CodecsRasterPdfInfoExample() 
{ 
   string multiPageRasterPdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "MultiPageRasterPdf.pdf"); 
   string pagesPdfFileNames = Path.Combine(LEAD_VARS.ImagesDir, "Page{0}.pdf"); 
 
   // Create a 4 pages PDF file 
   CreateMultiPageRasterPdfFile(multiPageRasterPdfFileName); 
 
   // Without prior information, we will split this multi-page PDF file into 
   // multiple single page PDF files with original size, resolution, bit-depth and compression 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      int pagesSaved = 0; 
 
      // Get the file information 
      using (CodecsImageInfo imageInfo = codecs.GetInformation(multiPageRasterPdfFileName, true)) 
      { 
         Console.WriteLine( 
            "Information: Format:\n Format: {0}\n Pages: {1}\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}", 
            imageInfo.Format, imageInfo.TotalPages, imageInfo.BitsPerPixel, imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution); 
         Console.WriteLine("-----------------------"); 
 
         // Now show the PDF specific information 
         // Notice: GetInformation will return RasPdf as the format for all PDF files 
         // regardless of the actual compression 
         if (imageInfo.Format == RasterImageFormat.RasPdf) 
         { 
            Console.WriteLine("Image is PDF, getting the specific info for each page"); 
 
            for (int i = 0; i < imageInfo.TotalPages; i++) 
            { 
               int pageNumber = i + 1; 
 
               CodecsRasterPdfInfo pdfInfo = codecs.GetRasterPdfInfo(multiPageRasterPdfFileName, i + 1); 
               if (pageNumber == 1) 
               { 
                  Console.WriteLine(" LEAD PDF?: {0}", pdfInfo.IsLeadPdf); 
                  Console.WriteLine(" Version: {0}", pdfInfo.Version); 
               } 
 
               if (pdfInfo.IsLeadPdf) 
               { 
                  Console.WriteLine( 
                     "Page {0} of {1} info:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}\n Format: {7}", 
                     pageNumber, imageInfo.TotalPages, pdfInfo.BitsPerPixel, pdfInfo.Width, pdfInfo.Height, pdfInfo.XResolution, pdfInfo.YResolution, pdfInfo.Format); 
                  Console.WriteLine("-----------------------"); 
 
                  // Load this page with its original parameters 
                  codecs.Options.RasterizeDocument.Load.XResolution = pdfInfo.XResolution; 
                  codecs.Options.RasterizeDocument.Load.YResolution = pdfInfo.YResolution; 
                  codecs.Options.Pdf.Load.DisplayDepth = pdfInfo.BitsPerPixel; 
 
                  using (RasterImage pageImage = codecs.Load(multiPageRasterPdfFileName, 0, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber)) 
                  { 
                     Console.WriteLine( 
                        "Page {0} of {1} loaded:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}", 
                        pageNumber, imageInfo.TotalPages, pageImage.BitsPerPixel, pageImage.Width, pageImage.Height, pageImage.XResolution, pageImage.YResolution); 
                     Console.WriteLine("-----------------------"); 
 
                     // Setup the PDF save options 
                     codecs.Options.Pdf.Save.UseImageResolution = true; 
                     codecs.Options.Pdf.Save.Version = pdfInfo.Version; 
 
                     // Save this page to a separate file 
                     string pagePdfFileName = string.Format(pagesPdfFileNames, pageNumber); 
                     codecs.Save(pageImage, pagePdfFileName, pdfInfo.Format, pdfInfo.BitsPerPixel); 
                     pagesSaved++; 
                  } 
               } 
            } 
         } 
      } 
 
      // We are done, now show the info of the generated files 
      for (int i = 0; i < pagesSaved; i++) 
      { 
         int pageNumber = i + 1; 
         string pagePdfFileName = string.Format(pagesPdfFileNames, pageNumber); 
 
         CodecsRasterPdfInfo pdfInfo = codecs.GetRasterPdfInfo(pagePdfFileName, 1); 
         Console.WriteLine( 
            "Page {0} of {1} info:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}\n Format: {7}", 
            pageNumber, pagesSaved, pdfInfo.BitsPerPixel, pdfInfo.Width, pdfInfo.Height, pdfInfo.XResolution, pdfInfo.YResolution, pdfInfo.Format); 
         Console.WriteLine("-----------------------"); 
      } 
   } 
} 
 
private static void CreateMultiPageRasterPdfFile(string pdfFileName) 
{ 
   string sourceFile = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"); 
 
   // Delete the destination PDF file if exists 
   if (System.IO.File.Exists(pdfFileName)) 
   { 
      System.IO.File.Delete(pdfFileName); 
   } 
 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      // Save to PDF v1.4 
      codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14; 
      // Save using image resolution 
      codecs.Options.Pdf.Save.UseImageResolution = true; 
 
      // Load the source file to use for each page 
      using (RasterImage pageImage = codecs.Load(sourceFile, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         Console.WriteLine( 
            "Original image dimension:\n Size: {0} by {1}\n Resolution: {2} by {3}", 
            pageImage.Width, pageImage.Height, pageImage.XResolution, pageImage.YResolution); 
 
         // Array of bits/pixel and compression to use when saving the pages 
         int[] bitsPerPixel = 
         { 
            1, 
            8, 
            24 
         }; 
         RasterImageFormat[] formats = 
         { 
            RasterImageFormat.RasPdfG4, 
            RasterImageFormat.RasPdfLzw, 
            RasterImageFormat.RasPdfJpeg422 
         }; 
 
         int pageCount = bitsPerPixel.Length; 
         for (int i = 0; i < pageCount; i++) 
         { 
            // Append this page with given format 
            Console.WriteLine("Saving page {0} of {1} using {2} at {3}", i + 1, pageCount, bitsPerPixel[i], formats[i]); 
            codecs.Save(pageImage, pdfFileName, formats[i], bitsPerPixel[i], 1, 1, -1, CodecsSavePageMode.Append); 
         } 
      } 
 
      Console.WriteLine("-----------------------"); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
Private Shared Sub CodecsRasterPdfInfoExample() 
   Dim multiPageRasterPdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MultiPageRasterPdf.pdf") 
   Dim pagesPdfFileNames As String = Path.Combine(LEAD_VARS.ImagesDir, "Page{0}.pdf") 
 
   ' Create a 4 pages PDF file 
   CreateMultiPageRasterPdfFile(multiPageRasterPdfFileName) 
 
   ' Without prior information, we will split this multi-page PDF file into 
   ' multiple single page PDF files with original size, resolution, bit-depth and compression 
   Using codecs As New RasterCodecs() 
      Dim pagesSaved As Integer = 0 
 
      ' Get the file information 
      Using imageInfo As CodecsImageInfo = codecs.GetInformation(multiPageRasterPdfFileName, True) 
         Console.WriteLine( 
            "Information: Format:\n Format: {0}\n Pages: {1}\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}", 
            imageInfo.Format, imageInfo.TotalPages, imageInfo.BitsPerPixel, imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution) 
         Console.WriteLine("-----------------------") 
 
         ' Now show the PDF specific information 
         ' Notice: GetInformation will return RasPdf as the format for all PDF files 
         ' regardless of the actual compression 
         If imageInfo.Format = RasterImageFormat.RasPdf Then 
            Console.WriteLine("Image is PDF, getting the specific info for each page") 
 
            For i As Integer = 0 To imageInfo.TotalPages - 1 
               Dim pageNumber As Integer = i + 1 
 
               Dim pdfInfo As CodecsRasterPdfInfo = codecs.GetRasterPdfInfo(multiPageRasterPdfFileName, i + 1) 
               If pageNumber = 1 Then 
                  Console.WriteLine(" LEAD PDF?: {0}", pdfInfo.IsLeadPdf) 
                  Console.WriteLine(" Version: {0}", pdfInfo.Version) 
               End If 
 
               If pdfInfo.IsLeadPdf Then 
                  Console.WriteLine( 
                     "Page {0} of {1} info:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}\n Format: {7}", 
                     pageNumber, imageInfo.TotalPages, pdfInfo.BitsPerPixel, pdfInfo.Width, pdfInfo.Height, pdfInfo.XResolution, pdfInfo.YResolution, pdfInfo.Format) 
                  Console.WriteLine("-----------------------") 
 
                  ' Load this page with its original parameters 
                  codecs.Options.RasterizeDocument.Load.XResolution = pdfInfo.XResolution 
                  codecs.Options.RasterizeDocument.Load.YResolution = pdfInfo.YResolution 
                  codecs.Options.Pdf.Load.DisplayDepth = pdfInfo.BitsPerPixel 
 
                  Using pageImage As RasterImage = codecs.Load(multiPageRasterPdfFileName, 0, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber) 
                     Console.WriteLine( 
                        "Page {0} of {1} loaded:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}", 
                        pageNumber, imageInfo.TotalPages, pageImage.BitsPerPixel, pageImage.Width, pageImage.Height, pageImage.XResolution, pageImage.YResolution) 
                     Console.WriteLine("-----------------------") 
 
                     ' Setup the PDF save options 
                     codecs.Options.Pdf.Save.UseImageResolution = True 
                     codecs.Options.Pdf.Save.Version = pdfInfo.Version 
 
                     ' Save this page to a separate file 
                     Dim pagePdfFileName As String = String.Format(pagesPdfFileNames, pageNumber) 
                     codecs.Save(pageImage, pagePdfFileName, pdfInfo.Format, pdfInfo.BitsPerPixel) 
                     pagesSaved = pagesSaved + 1 
                  End Using 
               End If 
            Next 
         End If 
      End Using 
 
      ' We are done, now show the info of the generated files 
      For i As Integer = 0 To pagesSaved - 1 
         Dim pageNumber As Integer = i + 1 
         Dim pagePdfFileName As String = String.Format(pagesPdfFileNames, pageNumber) 
 
         Dim pdfInfo As CodecsRasterPdfInfo = codecs.GetRasterPdfInfo(pagePdfFileName, 1) 
         Console.WriteLine( 
            "Page {0} of {1} info:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}\n Format: {7}", 
            pageNumber, pagesSaved, pdfInfo.BitsPerPixel, pdfInfo.Width, pdfInfo.Height, pdfInfo.XResolution, pdfInfo.YResolution, pdfInfo.Format) 
         Console.WriteLine("-----------------------") 
      Next 
   End Using 
End Sub 
 
Private Shared Sub CreateMultiPageRasterPdfFile(ByVal pdfFileName As String) 
   Dim sourceFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp") 
 
   ' Delete the destination PDF file if exists 
   If System.IO.File.Exists(pdfFileName) Then 
      System.IO.File.Delete(pdfFileName) 
   End If 
 
   Using codecs As New RasterCodecs() 
      ' Save to PDF v1.4 
      codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14 
      ' Save using image resolution 
      codecs.Options.Pdf.Save.UseImageResolution = True 
 
      ' Load the source file to use for each page 
      Using pageImage As RasterImage = codecs.Load(sourceFile, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1) 
         Console.WriteLine( 
            "Original image dimension:\n Size: {0} by {1}\n Resolution: {2} by {3}", 
            pageImage.Width, pageImage.Height, pageImage.XResolution, pageImage.YResolution) 
 
         ' Array of bits/pixel and compression to use when saving the pages 
         Dim bitsPerPixel() As Integer = 
         { 
            1, 
            8, 
            24 
         } 
         Dim formats() As RasterImageFormat = 
         { 
            RasterImageFormat.RasPdfG4, 
            RasterImageFormat.RasPdfLzw, 
            RasterImageFormat.RasPdfJpeg422 
         } 
 
         Dim pageCount As Integer = bitsPerPixel.Length 
         For i As Integer = 0 To pageCount - 1 
            ' Append this page with given format 
            Console.WriteLine("Saving page {0} of {1} using {2} at {3}", i + 1, pageCount, bitsPerPixel(i), formats(i)) 
            codecs.Save(pageImage, pdfFileName, formats(i), bitsPerPixel(i), 1, 1, -1, CodecsSavePageMode.Append) 
         Next 
      End Using 
 
      Console.WriteLine("-----------------------") 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly