LEADTOOLS PDF Segmentation (Leadtools.PdfCompressor assembly)
LEAD Technologies, Inc

Insert(RasterImage,PdfCompressorOptions) Method

Example 





Image to be inserted into the PDF file.
The PdfCompressorOptions structure that contains the options to be used to write the image to the PDF file.
Segments the specified image using Mixed Raster Content (MRC segmentation) and then compresses it and inserts it into the PDF file.
Syntax
public void Insert( 
   RasterImage image,
   PdfCompressorOptions options
)
'Declaration
 
Public Overloads Sub Insert( _
   ByVal image As RasterImage, _
   ByVal options As PdfCompressorOptions _
) 
'Usage
 
Dim instance As PdfCompressorEngine
Dim image As RasterImage
Dim options As PdfCompressorOptions
 
instance.Insert(image, options)
public void Insert( 
   RasterImage image,
   PdfCompressorOptions options
)
 function Leadtools.PdfCompressor.PdfCompressorEngine.Insert(RasterImage,PdfCompressorOptions)( 
   image ,
   options 
)
public:
void Insert( 
   RasterImage^ image,
   PdfCompressorOptions options
) 

Parameters

image
Image to be inserted into the PDF file.
options
The PdfCompressorOptions structure that contains the options to be used to write the image to the PDF file.
Remarks
This method will use segmentation for inserting the image into the Pdf file. If the SetCompression method is used, the segments will be compressed using the compression options specified by the method's PdfCompressorCompressionTypes structure.

For more information, refer to Creating a Compressed PDF File.

Example
 
Public Sub pdfCompressor_SegmentImage_MrcDocument(ByVal sender As Object, ByVal e As PdfCompressorSegmentImageEventArgs)
      'This will prevent addition to any segment with type background 
      If e.Segment.Type = SegmentTypeFlags.Background Then
         e.Cancel = True
      Else
         e.Cancel = False
      End If
   End Sub

   Public Sub PdfCompressorExample_MrcDocument()
      ' Load an image
      Dim codecs As RasterCodecs = New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "MRCSegmentation.mrc"))

      Dim pdfCompressor As New PdfCompressorEngine()
      Dim compressionTypes As PdfCompressorCompressionTypes = New PdfCompressorCompressionTypes()
      Dim pdfCompressorOptions As PdfCompressorOptions = New PdfCompressorOptions()

      'Sets compression types needed for each segment
      compressionTypes.Comp1Bit = PdfCompressor1BitCompression.Zip1Bit
      compressionTypes.Comp2Bit = PdfCompressor2BitCompression.Lzw2Bit
      compressionTypes.CompPicture = PdfCompressorPictureCompression.JpgPic
      compressionTypes.QFactor = 2

      'Flags for used compression types should be set
      compressionTypes.Flags = EnabledCompressionsFlags.EnableOneBit Or EnabledCompressionsFlags.EnableTwoBit Or EnabledCompressionsFlags.EnablePicture

      pdfCompressor.SetCompression(compressionTypes)

      'Specify suitable profiles for input and output image
      pdfCompressorOptions.ImageQuality = PdfCompressorImageQuality.ComputerGenerated
      pdfCompressorOptions.OutputQuality = PdfCompressorOutputQuality.Excellent
      pdfCompressorOptions.Flags = SegmentationOptionsFlags.FavorOneBit Or SegmentationOptionsFlags.WithBackground

      AddHandler pdfCompressor.SegmentImage, AddressOf pdfCompressor_SegmentImage_MrcDocument
      pdfCompressor.Insert(image, pdfCompressorOptions)

      pdfCompressor.Write(Path.Combine(LEAD_VARS.ImagesDir, "Image.pdf"))
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void pdfCompressor_SegmentImage_MrcDocument(object sender, PdfCompressorSegmentImageEventArgs e)
   {
      //This will prevent addition to any segment with type background 
      if(e.Segment.Type == SegmentTypeFlags.Background)
         e.Cancel = true; 
      else
         e.Cancel = false; 
   }

   public void PdfCompressorExample_MrcDocument()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;

      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"MRCSegmentation.mrc"));

      PdfCompressorEngine pdfCompressor = new PdfCompressorEngine();
      PdfCompressorCompressionTypes compressionTypes = new PdfCompressorCompressionTypes();
      PdfCompressorOptions pdfCompressorOptions = new PdfCompressorOptions();

      //Sets compression types needed for each segment
      compressionTypes.Comp1Bit = PdfCompressor1BitCompression.Zip1Bit;
      compressionTypes.Comp2Bit = PdfCompressor2BitCompression.Lzw2Bit;
      compressionTypes.CompPicture = PdfCompressorPictureCompression.JpgPic;
      compressionTypes.QFactor = 2;

      //Flags for used compression types should be set
      compressionTypes.Flags = EnabledCompressionsFlags.EnableOneBit |
         EnabledCompressionsFlags.EnableTwoBit |
         EnabledCompressionsFlags.EnablePicture;

      pdfCompressor.SetCompression(compressionTypes);

      //Specify suitable profiles for input and output image
      pdfCompressorOptions.ImageQuality = PdfCompressorImageQuality.ComputerGenerated;
      pdfCompressorOptions.OutputQuality = PdfCompressorOutputQuality.Excellent;
      pdfCompressorOptions.Flags = SegmentationOptionsFlags.FavorOneBit |
         SegmentationOptionsFlags.WithBackground;

      pdfCompressor.SegmentImage += new EventHandler<PdfCompressorSegmentImageEventArgs>(pdfCompressor_SegmentImage_MrcDocument);
      pdfCompressor.Insert(image, pdfCompressorOptions);

      pdfCompressor.Write(Path.Combine(LEAD_VARS.ImagesDir,"Out_Image.pdf"));
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PdfCompressorEngine Class
PdfCompressorEngine Members
Overload List
SetCompression Method
InsertSegments Method
PdfCompressorOptions Structure

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.PdfCompressor requires a PDF Plug-in license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features