Insert(RasterImage,PdfCompressorOptions) Method (original) (raw)

Summary

Segments the specified image using Mixed Raster Content (MRC segmentation) and then compresses it and inserts it into the PDF file.

Syntax

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.

Example

This example inserts an image into a PDF document and uses the MRC to make a proper segment for this image.

using Leadtools; using Leadtools.PdfCompressor; using Leadtools.Codecs; 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:\LEADTOOLS22\Resources\Images"; }