Development: Acrobat plugins

1. Toolbar icons
Q: I've created my own ToolButton in the default ToolBar but I'm not able to load the icon I've designed. I'm using the AVToolButtonNew method. [Q25]
2. Embedding a font into a PDF
Q: I have a plug-in that adds a text banner to the foot of each page in a PDF. How do I correctly add a font resource, e.g. Arial, to the PDF so that the banner prints correctly. The PDFs are straight bitmap conversions so have not font info. [Q78]
3. Copying a PDF with Acrobat with JavaScript
Q: Does anyone know of a tool that will dump the complete contents of a PDF file as a text file, perhaps in some XML format? My need is to analyze the structure of some PDF documents. I'm not looking for a document conversion tool but a developer tool for analyzing the PDF format itself. [Q175]

1. Toolbar icons

Q: I've created my own ToolButton in the default ToolBar but I'm not able to load the icon I've designed. I'm using the AVToolButtonNew method. [Q25]

A: What are the attributes of the icon: - type (bitmap, icon, ...) - size - colours?

Aandi Inston (quite@dial.pipex.com) [A45]

A: The icon type is Icon the size is 18x18 with 256 colours.

Giacomo (x-ray69@usa.net) [A46]

A: In my project it is a Bitmap, not Icon. This may be critical. Mine is also 20 x 20 with 16 colours. This may be less important. Refer to (I think) the ImageSel project; the documentation on this point is poor.

Aandi Inston (quite@dial.pipex.com) [A47]

A: It displays just a question mark insted of my icon. I've also tryed to convert the .ico file into a bitmap and load it using the same procedure as shown in ImageSel project. No way. I'm banging my head on the wall... I need it to work out!

Giacomo (x-ray69@usa.net) [A48]

2. Embedding a font into a PDF

Q: I have a plug-in that adds a text banner to the foot of each page in a PDF. How do I correctly add a font resource, e.g. Arial, to the PDF so that the banner prints correctly. The PDFs are straight bitmap conversions so have not font info. [Q78]

A: If you are using the Cos layer this is an interesting and serious challenge. If you are using the PDFEdit layer, this does include options to create and embed a font from a "system" (i.e. installed) font. Since Arial is a virtual clone of Helvetica, that particular example would not be worthwhile. The base fonts like Helvetica are guaranteed to print without embedding.

Aandi Inston (quite@dial.pipex.com) [A132]

3. Copying a PDF with Acrobat with JavaScript

Q: Does anyone know of a tool that will dump the complete contents of a PDF file as a text file, perhaps in some XML format? My need is to analyze the structure of some PDF documents. I'm not looking for a document conversion tool but a developer tool for analyzing the PDF format itself. [Q175]

A: The following JS code, when used as an Acrobat plugin will add an Acrobat menu item (under Document) to do a code dump of the active PDF and place the code in a new PDF document. Warning: This can be a bit slow on older systems or with very large PDF files. Start by trying it out on a smaller file.

 
app.addMenuItem({
 cName: "Dump PDF source code",
 cParent: "Document",
 cExec:"dump()",
 cEnable:"if (app.activeDocs.length==0) event.rc=false"
});


function dump()
{
try {
 var r= new Report();
 var f = addTheField(this);
 if (!f) {
  app.alert("Original doc may have security prohibitions.");
  return;
  }
 var lastText = ';
 var text = "x";
 r.writeText(f.name);

 var i = 0;
 var mark = 0;
 while (lastText != text) {
  lastText = text;
  this.importTextData(this.path,i++);
  text = f.value;
  mark += isNaN(Number(text.length)) ? 0 : text.length;

  if (lastText != text)
     r.writeText(text);

  if (i % 150 == 0)
   if (!goAhead(i,mark)) break;
  } // end loop


 if (mark < this.filesize)
  app.alert("Entire doc may not have been processed.");

 var docRep = r.open("dump.pdf");

  } catch(e) { app.alert("Operation could not be accomplished.
 " + e); }



}  // dump()



function addTheField(theDoc) {

 var f = null;
      for (var i = 4; i > 0; i--) {
  var str = '%PDF-1.' + i;
  f = theDoc.addField(str ,'text',theDoc.pageNum,[0,0,1,1]);
  theDoc.importTextData(theDoc.path,0);
  if (f)
   if (f.value != ' && f.value != null)
              return f;
 }
      return f;
}



function goAhead(n,bytes) {

 var reply = app.alert(n + " lines and " + bytes + " bytes processed so far.
More to do. Hit OK to continue, otherwise Cancel.",2,1);
     return (reply != 2);
}

 

Bryan Guignard (bryang@sympatico.ca) [A268]