Table of Contents

PDF Macro extension

Description

This plugin provides PDF creation functions to the ImageJ macro language using the iText library .

Author

Jerome Mutterer (email)

Provided functions

 Ext.newPDF(path); 

→ creates a new pdf document.

 Ext.addMetadata(title, author, subject, keywords); 

→ sets pdf's metadata.

  Ext.setFont(font, size, style);

→ sets the active font face.

  Ext.addParagraph(string);

→ adds a new paragrah to the pdf document.

  Ext.addImage(align, scale);

→ adds the active image to the pdf.

  Ext.fitImage(x,y,w,h);

→ draws an w*h fitted copy of the active image at x,y.

  Ext.addPage();

→ adds a new page to the document.

  Ext.closePDF();

→ finishes and closes the pdf being built.

Installation

  1. Download iText library to the plugins folder.
  2. Download this file to the plugins folder.
  3. Update menus or restart ImageJ.
  4. Try the test macro in the following section.

Example macro

The following macro should create a 2 pages test.pdf document in ImageJ/output/

example

// test macro for the pdf macro extensions
 
// a sample text
lorem ="Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
+" Sed non risus. Suspendisse lectus tortor, dignissim sit amet,"
+" adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam."
+" Maecenas ligula massa, varius a, semper congue, euismod non, mi."
+" Proin porttitor, orci nec nonummy molestie, enim est eleifend mi,"
+" non fermentum diam nisl sit amet erat. Duis semper.";
 
setBatchMode(true);
// create an 'output' folder in the ImageJ folder
startup = getDirectory("startup");
output = startup+"output"+File.separator;
if (!File.exists(output)) File.makeDirectory(output);
// make the new functions available
run ("pdf macro ext");
// open a test image
run("AuPbSn 40 (56K)");
// start a new PDF document
Ext.newPDF(output+"test.pdf");
// add information about this document
Ext.addMetadata("my title","jerome","pdf test","pdf,report,imagej");
// add a first paragraph
Ext.addParagraph("PDF Macro Extensions !");
// try different fonts and styles
Ext.setFont("times",10,"");
Ext.addParagraph(lorem+"\n\n");
Ext.setFont("courier",10,"bold");
Ext.addParagraph("PDF Macro Extensions !");
Ext.setFont("helvetica",12,"bold italic underlined");
Ext.addParagraph("PDF Macro Extensions !");
// add the sample image with different alignments and scales
Ext.addImage("center",0.2);
Ext.addImage("left",0.3);
Ext.addImage("right",0.3);
// add a new page
Ext.addPage();
Ext.setFont("times",16,"bold italic");
Ext.addParagraph(getTitle);
Ext.addParagraph(getWidth+"x"+getHeight);
run("Clown (14K)");
// place 8 copies of an image at different positions and sizes
for (i=0;i<8;i++) {
	Ext.fitImage(15+i*40,200+i*10,10+i*40,400);
}
// close the PDF file.
Ext.closePDF();

Licence

This plugin relies on iText.
iText is published under 2 different licenses: MPL and LGPL. See iText website for details.