←Select platform

DecodeImage Method

Summary
Decodes the specified PDF image object embedded in this PDFDocument.
Syntax
C#
C++/CLI
Java
Python
public RasterImage DecodeImage( 
   string imageObjectNumber 
) 
public RasterImage decodeImage( 
   java.lang.String imageObjectNumber 
); 
public: 
RasterImage^ DecodeImage(  
   String^ imageObjectNumber 
)  
def DecodeImage(self,imageObjectNumber): 

Parameters

imageObjectNumber
String that specifies the PDF image object number to decode.

Return Value

A Leadtools.RasterImage object.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
 
public void PDFDocumentDecodeImageExample() 
{ 
   string sourceFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
   string destinationFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_pdfDecodeImage.tif"); 
 
   using (PDFDocument document = new PDFDocument(sourceFileName)) 
   { 
      document.Resolution = 200; 
 
      // Parse the objects in all pages 
      document.ParsePages(PDFParsePagesOptions.Objects, 1, -1); 
 
      RasterCodecs codecs = new RasterCodecs(); 
      foreach (PDFDocumentPage page in document.Pages) 
         if (page.Objects != null && page.Objects.Count > 0) 
            foreach (PDFObject obj in page.Objects) 
               if (obj.ObjectType == PDFObjectType.Image) 
                  using (RasterImage image = document.DecodeImage(obj.ImageObjectNumber)) 
                     codecs.Save(image, destinationFileName, RasterImageFormat.TifLzw, image.BitsPerPixel, 1, 1, -1, CodecsSavePageMode.Append); 
 
      codecs.Dispose(); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.BufferedWriter; 
import java.io.Console; 
import java.io.File; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.OutputStream; 
import java.io.OutputStreamWriter; 
import java.nio.Buffer; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.nio.file.StandardOpenOption; 
import java.sql.Date; 
import java.text.SimpleDateFormat; 
import java.time.LocalDateTime; 
import java.util.ArrayList; 
import java.util.List; 
 
import javax.xml.validation.Schema; 
 
import org.apache.lucene.store.Directory; 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
import leadtools.pdf.*; 
import leadtools.svg.*; 
 
 
public void pdfDocumentDecodeImageExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String sourceFileName = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf"); 
   String destinationFileName = combine(LEAD_VARS_ImagesDir, "LEAD_pdfDecodeImage.tif"); 
 
   PDFDocument document = new PDFDocument(sourceFileName); 
   document.setResolution(200); 
 
   // Parse the objects in all pages 
   document.parsePages(PDFParsePagesOptions.OBJECTS.getValue(), 1, -1); 
 
   RasterCodecs codecs = new RasterCodecs(); 
   int numObjects = 0; 
   for (PDFDocumentPage page : document.getPages()) { 
      for (PDFObject obj : page.getObjects()) { 
         numObjects++; 
      } 
   } 
   for (PDFDocumentPage page : document.getPages()) { 
      if (page.getObjects() != null && numObjects > 0) 
         for (PDFObject obj : page.getObjects()) { 
            if (obj.getObjectType() == PDFObjectType.IMAGE) { 
               RasterImage image = document.decodeImage(obj.getImageObjectNumber()); 
               codecs.save(image, destinationFileName, RasterImageFormat.TIFLZW, image.getBitsPerPixel(), 1, 1, -1, 
                     CodecsSavePageMode.APPEND); 
            } 
         } 
      codecs.dispose(); 
   } 
   assertTrue(new File(destinationFileName).exists()); 
} 
Requirements

Target Platforms

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

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.