0 Replies Latest reply on May 31, 2010 1:30 AM by BKD2012

    page number in template

    BKD2012

      Hi,


      I was trying to add a page number in a template,but the same number is written.


      I'm not too familiarized with the API, but I tried in this way:


      var rep = new Report();


      rep.size = 0.8;


      rep.style = "DefaultNoteText";


              var aRect = new Array(4);


              aRect[0] = 5;


              aRect[2] = 115;


              aRect[1] = 5;


              aRect[3] = 25;

       


      rep.writeText(util.printf("Page: %d", this.pageNum));


      rep.divide();


      rep.save("/path/to/file/myreport.pdf");


      var nDoc = app.openDoc("/path/to/file/myreport.pdf");


      nDoc.zoom = 100;


      nDoc.layout = "OneColumn";


      var t = nDoc.createTemplate({cName:"myTemplate", nPage:0 });

      var a = nDoc.templates;
      var nPag;
      var T = a[0];
      var XO = T.spawn(nDoc.numPages, false, false);
      for (var i=0; i<5; i++){
          T.spawn(nDoc.numPages, false, false, XO);


      }


      I tried to use a field.page property because I read a post in this forums that I can use it to generate a page number like with watermarks.

       

       

      var rep = new Report();
      rep.size = 0.8;
      rep.style = "DefaultNoteText";

        var aRect = new Array(4);
        aRect[0] = 5;// from upper left hand corner of page.
        aRect[2] = 115;// Make it .5 inch wide
        aRect[1] = 5;
        aRect[3] = 25;// and 24 points high

        var txtField = this.addField({
        cName: "mFld",
        cFieldType: "text",
        nPageNum: this.pageNum,
        oCoords: aRect
        });

      var nPag = txtField.page;

      app.alert({
      cMsg: "nPag: "+nPag,
      cTitle: "Test"
      });

      rep.writeText(util.printf("Pagina: %d", nPag));
      rep.divide();
      rep.save("/path/to/file/myreport.pdf");
      var nDoc = app.openDoc("/path/to/file/myreport.pdf");
      nDoc.zoom = 101;
      nDoc.layout = "OneColumn";

      var t = nDoc.createTemplate({cName:"myTemplate", nPage:0 });
      var a = nDoc.templates;
      var T = a[0];
      var fld;
      var XO = T.spawn(nDoc.numPages, false, false);
      for (var i=0; i<5; i++){

          T.spawn(nDoc.numPages, false, false, XO);
          fld = this.getField("mFld");
          app.alert({
          cMsg: "fld: "+fld.page,
          cTitle: "Test"
          });
      }

       

      Is not working properly, I can't get the page number in the myreport.pdf.

       

      I tried in debugger and is showing always the same page number.

       

      I tried in a file using trusted function and I am getting different errors that are showed alternated.

       

      The file is already opened

      The function doesn't exist

      and I don't have security privileges

       

      The 2 last errors are unexpected because I have inserted the code inside a app.trustedFunction.

       

      Any help would be apreciated

      Thanks