Hello,

The PDFedit program is very useful.
I have created a script for adding page numbers 
(in the upper-right corner of A4 papers), 
but the scripting language is hard to understand for me.
Perhaps it can be finished by someone else, and be added to the program?

I have also created an icon. Both files are attached to this mail.

kind regards,
jdm

<<attachment: pagenumber.png>>

// pagenumber plugin
//
// 14 june 2007: start of this script by jdm, although I don't know what I am doing.
//
// This script is placed in ~/.pdfedit/scripts
// An icon 'pagenumber.png' is placed in ~/.pdfedit/icon
//
// In case of an error, the plugin is not shown in the 'tools' menu. 
// Create a test pdf file and use the next commandline to see 
// if the script has an error during loading. 
//       pdfedit -d 4 test.pdf
//


// Todo:
//    Use a dialog box with:
//      - position (top|bottom, left|middel|right) and margin to border.
//      - font, font size, font color, and font style (like outline, etc.)
//        Or use the current selected font, size, color.
//      - remove previous added pagenumbers.
//      - number style (e.g. leading zero's)
//      - place a rectangle under the number (set color and padding),
//        so the text for the number is always visible.
//



// The function operatorAddTextLine() from pdfoperator.qs uses the current page.
// This function uses a page variable. So text can be written on other pages too.
// Perhaps the addText() function from dialogs.qs can be used?
function operatorAddTextLine2 (thepage,text,x,y,fname,fsize,opToPutBefore,col) {
	//
	// q
	// BT
	// rg col
	// fname fsize Tf
	// x y Td
	// text Tj
	// ET
	// Q
	//
	var q = createCompositeOperator("q","Q");
	var BT = createCompositeOperator("BT","ET");
	
	if ((undefined != opToPutBefore) && (opToPutBefore.type() == "PdfOperator"))
		q.pushBack( opToPutBefore, q );
	q.pushBack (BT,q);
	
	putfont(BT,fname,fsize);
	puttextrelpos (BT,x,y);
	if (undefined != col)
		putnscolor (BT,col.red,col.green,col.blue);
	puttext (BT,text);
	putendtext (BT);
	putendq(q);

	var ops = createPdfOperatorStack();
	ops.append (q);
//	page().prependContentStream(ops);             // original
	thepage.prependContentStream(ops);              // new
}




/** Function to invoke the pluigin functionality */
function pagenumber() {

  pages=document.getPageCount();                // get total number of pages

  for (i=1;i<=pages;i++) {
    print(tr("Busy with page: %1").arg(i));

    thepage=document.getPage(i);

    // The next lines are taken from the function editFontProps from dialogs.qs

  	// gets current font from font tool, if this font is not
  	// page part, adds it to the page
  	currentFont=getEditText("fontface");

    currentFont="Helvetica";                     // override for now

//  	print(currentFont);
  	currentFontId=thepage.getFontId(currentFont);
  	if(!currentFontId)
  	{
  		// this font is unknown for page, we have to add it
  		thepage.addSystemType1Font(currentFont);
  		currentFontId=thepage.getFontId(currentFont);
//  		print(tr("%1 added to page").arg(currentFont));
  	}

  	// gets current font size from font tool
  	currentFontSize=getNumber("fontsize");      // get size as selected in the toolbar
    
    currentFontSize=12;                         // override for now

    col=getColor("fg");

  	var ctm = getDetransformationMatrix( thepage );
    
    // coordinates ??
    x_pos = 558;                 // upper on page, determined by reverse engineering
    y_pos = 813;                 // right on page

    // make some (very ugly) right align, by placing zero's in front.
    text = tr("%1".arg(i));
    testout = text;
    if (i<100) { textout = tr("0%1".arg(text)) }
    if (i<10) { textout = tr("00%1".arg(text)) }

    // write the text, using my modified version.
    operatorAddTextLine2 (thepage, textout, x_pos, y_pos, currentFontId, currentFontSize, createOperator_transformationMatrix( ctm ), col);
    
  }
  print("Ready");

  // Reload
  go();
}

//Install the plugin

// install the menu/toolbar items that are used by the plugin 
createMenuItem('toolsmenu','pagenumber',tr('Pagenumber'),'pagenumber()','','pagenumber.png');

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Pdfedit-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdfedit-support

Reply via email to