How to insert text in current Pdf?


i try insert text current pdf getting unexepected error

 

    pdecontent pdecontent;

    avdoc avdoc = avappgetactivedoc();

    pddoc pddoc = avdocgetpddoc (avdoc);

    pdpage pdpage = pddocacquirepage(pddoc,avpageviewgetpagenum(avdocgetpageview(avappgetactivedoc())));

    pdecontent = pdpageacquirepdecontent(pdpage, null);

   

    //create pdetext object

    pdetext pdetext = pdetextcreate();

  //  create degraphicstate object , set attributes

    asfixedmatrix textmatrix;

    //create asfixedmatrix object

    memset(&textmatrix, 0, sizeof(textmatrix)); /* set buffer size */

    textmatrix.a = int16tofixed(24); /* set font width , height */

    textmatrix.d = int16tofixed(24); /* 24 point size */

    textmatrix.h = int16tofixed(1*72); /* x,y coordinate on page */

    textmatrix.v = int16tofixed(2*72); /* in case, 1" x 2" */

                                       

   

    pdegraphicstate gstate;

    pdecolorspace pdecolorspace = pdecolorspacecreatefromname(asatomfromstring(colour_space.c_str()));

    memset(&gstate, 0, sizeof(pdegraphicstate));

    gstate.strokecolorspec.space = gstate.fillcolorspec.space = pdecolorspace;

    gstate.miterlimit = fixedten;

    gstate.flatness = fixedone;

    gstate.linewidth = fixedone;

   

    pdsysfont sysfont;

    pdefont pdefont;

    pdefontattrs pdefontattrs;

   

    //set size of pdsysfont , set attributes

    memset(&pdefontattrs, 0, sizeof(pdefontattrs));

    pdefontattrs.name = asatomfromstring("courierstd");

    pdefontattrs.type = asatomfromstring("type1");

    //get system font

    sysfont = pdfindsysfont(&pdefontattrs, sizeof(pdefontattrs), 0);

    //create font used draw text on page

    pdefont = pdefontcreatefromsysfont(sysfont, kpdefontdonotembed);

   

    char *chrnewfilepath = "doc.pdf";

    astext  asfilepath =  astextfromunicode(reinterpret_cast <asutf16val *> (chrnewfilepath), kutf8);

    //create character pointer

    char *helloworldstr = "hello there";

    //create new text run

    pdetextadd(pdetext, //text container add to

               kpdetextrun, // kpdetextrun

               0, // in

               (unsigned char*)helloworldstr, // text add

               strlen(helloworldstr),// length of text

               pdefont, // font apply text

               &gstate, //address of pdegraphicstate object

               sizeof(gstate), //size of graphic state apply text

               null,

               0,

               &textmatrix, //transformation matrix text

               null); //stroke matrix

   

    ::free(chrnewfilepath);

   

   

   

    asfilesys  asfilesys =  asgetdefaultfilesysforpath(asatomfromstring( "astextpath" ), asfilepath);

   

   

   

    aspathname asnewpath =  asfilesyscreatepathname(asfilesys,  asatomfromstring( "astextpath" ), asfilepath, 0);

   

    pddocsave(pddoc, pdsavefull , asnewpath , asfilesys, null, null);

what unexpected error, , on line happen?

you should have error trap in code (during...handler...end_handler) absence not cause error.



More discussions in Acrobat SDK


adobe

Comments