Quantcast
Channel: Adobe Community : All Content - Acrobat SDK
Viewing all articles
Browse latest Browse all 2571

how to insert an image in a pdf document

$
0
0

I used the "Stamper" example and modified the fuction to insert image to my pdf doc.

PDAnnot CreateStampAnnotationAt(AVPageView pageView, AVDevRect *rect)

to add a picture Annotation into page.

when system calling the callback function "AnnotDraw" to draw the Cos Object in that Annotation ,the function "AVPageViewDrawCosObj(pageView, coApp, &avdr)" doesn't work.Here is the code:

ASFixedRect pdLocation;
PDAnnot annot = {0,0};
CosObj cAnnotObj, cIntObj, cStmObj, attributesDict, LengthEntry, cNullObj;
CosObj cAPDictObj, cStmDictObj, cBBoxObj, cProcSetObj, cResObj;
CosObj fontResObj, fontResObj2, cObj;
CosDoc cdoc;
ASStm stm;
char buf[512];
PDPage pdPage;
ASUns32 s;
ASFile picFile = NULL;
DURING
        //handle clicks (with no drag, or only in one direction), by creating a default size annot
        if((rect->top == rect->bottom) || (rect->right == rect->left))
        {
                rect->top +=75;
                rect->right += 150;
        }       
        pdPage = AVPageViewGetPage(pageView);
        AVDoc avDoc = AVPageViewGetAVDoc(pageView);
        AVPageViewDeviceRectToPage ( pageView, rect, &pdLocation);
        // Add the new annotation to the page.
        annot = PDPageAddNewAnnot(pdPage, -1, Stamper_K, &pdLocation);
        cAnnotObj = PDAnnotGetCosObj(annot);
        cdoc = PDDocGetCosDoc(PDPageGetDoc(pdPage));
        // See PDF Specification for more information on the Flags key.
        cIntObj = CosNewInteger (cdoc, false, 4L);
        CosDictPutKeyString(cAnnotObj, Flags_KStr, cIntObj);


        cAPDictObj = CosNewDict(cdoc, false, 1L);
        cNullObj = CosNewNull();

        ASFileSysOpenFile (ASGetDefaultFileSys (),ASPathFromPlatformPath("c:\\test.jpeg"), ASFILE_READ, &picFile);


        stm = ASFileStmRdOpen (picFile, 4096);
        attributesDict        = CosNewDict(cdoc, false, 5);

        LengthEntry = CosNewInteger(cdoc, false,11594 );


        CosDictPutKeyString(attributesDict, Length_KStr, LengthEntry);
        cStmObj = CosNewStream(cdoc, true, stm, 0, true, attributesDict, cNullObj, s);
        cStmDictObj = CosStreamDict(cStmObj);
        CosDictPutKeyString(cStmDictObj, "Type", CosNewNameFromString(cdoc, false, "XObject"));

        CosDictPutKeyString(cStmDictObj, "Subtype", CosNewNameFromString(cdoc, false, "Image"));

        CosDictPutKeyString(cStmDictObj, "Width", CosNewInteger(cdoc, false , 151));

        CosDictPutKeyString(cStmDictObj, "Height", CosNewInteger(cdoc, false , 151));

        CosDictPutKeyString(cStmDictObj, "ColorSpace", CosNewNameFromString(cdoc, false, "DeviceRGB"));

        CosDictPutKeyString(cStmDictObj, "BitsPerComponent", CosNewInteger(cdoc, false , 8));


        cBBoxObj = CosNewArray(cdoc, false, 4L);
        CosArrayInsert(cBBoxObj, 0L, CosNewInteger(cdoc, false, 0L));
        CosArrayInsert(cBBoxObj, 1L, CosNewInteger(cdoc, false, 0L));
        CosArrayInsert(cBBoxObj, 2L, CosNewInteger(cdoc, false, 100L));
        CosArrayInsert(cBBoxObj, 3L, CosNewInteger(cdoc, false, 100L));
        CosDictPutKeyString(cStmDictObj, "BBox", cBBoxObj);

        CosDictPut(cAPDictObj, FaceNormal_K, cStmObj);

        CosDictPutKeyString(cAnnotObj, Appearance_KStr, cAPDictObj);

HANDLER

        AVAlertNote(ASGetErrorString(ERRORCODE, buf, sizeof(buf)));

END_HANDLER

 

Please help.


Viewing all articles
Browse latest Browse all 2571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>