LPDFCompressor::InsertMRC

#include "ltwrappr.h"

#include "LTCPDFComp.h"

L_INT LPDFCompressor::InsertMRC(pBitmap, pPDFOptions)

LBitmapBase* pBitmap;

/* pointer to an LBitmapBase object */

LPPDFCOMPOPTIONS pPDFOptions;

/* pointer to the PDFCOMPOPTIONS structure */

Segments the specified image using MRC segmentation, compresses it, and inserts the image in the PDF file in memory.

Parameter

Description

pBitmap

Pointer to the bitmap object that references the image to be inserted in the PDF file.

pPDFOptions

Pointer to the PDFCOMPOPTIONS structure that contains options used to write the image to the PDF file in memory.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

To insert the bitmap without using MRC segmentation, use LPDFCompressor::InsertNormal.

This function calls the LPDFCompressor::ImageCallBack, if LBase::EnableCallBack was set to TRUE, to allow the user to accept or reject the addition of any segment to the PDF document.

Required DLLs and Libraries

LCMRC
LCPDF
LCENC
LCZIB
LTSGM

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LPDFCompressor::InsertNormal, LPDFCompressor::ImageCallBack, Class Members

Topics:

Creating a Compressed PDF File

 

Class Library Function Groups

Example

/* This example inserts an image in a pdf document and uses MRC segmentation to segment this image. In this sample we don't need to add a background segment. */
class LPDFCompressorKid : public LPDFCompressor 
{
protected: 
   L_INT ImageCallBack(L_INT nPage, LPSEGMENTINFO pSegment) 
   {
      if(pSegment->uSegmentType == SEGMENT_BACKGROUND) 
         return FAILURE; 
      else
         return SUCCESS; 
   }
};

void PdfcompressorinsertmrcExample(HWND hwnd) 
{
   LPDFCompressorKid pdf ; 
   L_INT nRet; 
   LBitmap LEADBitmap; 
   PDFCOMPOPTIONS PDFOptions; 
   PDFCOMPRESSION pdfComp; 
   
   memset(&PDFOptions,0,sizeof(&PDFOptions)); 
   
   pdf.EnableCallBack (TRUE); 
   
   nRet = pdf.Init ();
   if (nRet != SUCCESS) 
   {
      MessageBox(hwnd, "Couldn't initialize pdf compressor","Error", MB_OK) ; 
      return ; 
   }
   
   pdfComp.uStructSize = sizeof( pdfComp ); 
   pdfComp.dwFlags = PDFCOMP_1BITCOMPTYPE_ENABLED | PDFCOMP_2BITCOMPTYPE_ENABLED | PDFCOMP_PICTURECOMPTYPE_ENABLED; 
   pdfComp.comp1Bit = PDFCOMP_1BITCOMPTYPE_JBIG2; 
   pdfComp.comp2Bit = PDFCOMP_2BITCOMPTYPE_ZIP; 
   pdfComp.compPicture = PDFCOMP_PICTURECOMPTYPE_JPEG; 
   pdfComp.nQFactor =50; 
   
   nRet = pdf.SetCompression ( &pdfComp ); 
   if(nRet != SUCCESS) 
   {
      pdf.Free ();
      return ; 
   }
   
   
   PDFOptions.uStructSize = sizeof(PDFCOMPOPTIONS); 
   PDFOptions.dwFlags = PDFCOMP_FAVOR_ONEBIT | PDFCOMP_WITH_BACKGROUND; 

   PDFOptions.imageQuality = PDFCOMP_IMAGEQUALITY_USER; 
   PDFOptions.outputQuality = PDFCOMP_OUTPUTQUALITY_USER; 
   
   PDFOptions.uCleanSize = 7;   
   PDFOptions.uBackGroundThreshold = 15; 
   PDFOptions.uCombineThreshold = 100; 
   PDFOptions.uSegmentQuality = 50; 
   PDFOptions.uColorThreshold = 25; 
   
   if (LEADBitmap.Load(TEXT("C:\\IMAGE4.CMP")) != SUCCESS) 
   {
      MessageBox(hwnd, TEXT("Failed to load source image \"C:\\IMAGE4.CMP\""),"Error", MB_OK); 
      pdf.Free();
      return ; 
   }
   nRet = pdf.InsertMRC(&LEADBitmap, &PDFOptions); 
   
   nRet = pdf.Write (TEXT("C:\\Output(InsertMRC).pdf"));
   if (nRet ==SUCCESS) 
      MessageBox( hwnd, TEXT("Result saved to C:\\Output(InsertMRC).pdf"),"Error", MB_OK); 
   else
      MessageBox( hwnd, TEXT("Failed to save result"),"Error", MB_OK); 
   
   pdf.Free ();
}