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

 

C++ 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 LPDFCompressorKidIM : public LPDFCompressor 
{
protected: 
   L_INT ImageCallBack(L_INT nPage, LPSEGMENTINFO pSegment) 
   {
      UNREFERENCED_PARAMETER(nPage);
      if(pSegment->uSegmentType == SEGTYPE_BACKGROUND) 
         return FAILURE; 
      else
         return SUCCESS; 
   }
};
L_INT LPDFCompressor__InsertMRCExample(HWND hwnd) 
{
   LPDFCompressorKidIM  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, TEXT("Couldn't initialize pdf compressor"), TEXT("Error"), MB_OK) ; 
      return nRet;
   }
   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 nRet;
   }
   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; 
   nRet = LEADBitmap.Load(TEXT("C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 16\\Images\\IMAGE4.CMP"));
   if(nRet != SUCCESS)
   {
      MessageBox(hwnd, TEXT("Failed to load source image \"C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 16\\Images\\IMAGE4.CMP\""), TEXT("Error"), MB_OK); 
      pdf.Free();
      return nRet;
   }
   nRet = pdf.InsertMRC(&LEADBitmap, &PDFOptions); 
   if(nRet != SUCCESS)
      return nRet;
   nRet = pdf.Write (TEXT("C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 16\\Images\\Output(InsertMRC).pdf"));
   if (nRet ==SUCCESS) 
      MessageBox( hwnd, TEXT("Result saved to C:\\Program Files\\LEAD Technologies, Inc\\LEADTOOLS 16\\Images\\Output(InsertMRC).pdf"), TEXT("Error"), MB_OK); 
   else
   {
      MessageBox( hwnd, TEXT("Failed to save result"), TEXT("Error"), MB_OK); 
      return nRet;
   }
   pdf.Free ();
   return SUCCESS;
}