From: Michal H. <ms...@gm...> - 2007-06-18 18:11:01
|
On Thu, Jun 14, 2007 at 11:16:43PM +0200, jdm wrote: > Hello, Hi. > > 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? We can discuss it in the list and put this version on the web so everybody can download it (and add it to the release when it is ready). > > I have also created an icon. Both files are attached to this mail. Thanks for your effort. I haven't written many scripts but here are my comments: > // 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. This can be a problem because it is hard to find out what is the page number and what is the real document text. > // - 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. > // If you want to use dialog box(es) see the http://pdfedit.petricek.net/pdfedit.appendix#id2505805 which discusses details about dialogs construction. > > > // 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) { I think that page parameter is good idea for this function. I will talk with Martin (or we can discuss it here) to use it in some new release. > /** 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 var mediabox = page().mediabox(); var xleft = mediabox[0]; var yleft = mediabox[1]; var xright = mediabox[2]; var yright = mediabox[3]; Use this value for whatever calculations for position. > > // 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)) } What is the intention here? > > // write the text, using my modified version. > operatorAddTextLine2 (thepage, textout, x_pos, y_pos, currentFontId, currentFontSize, createOperator_transformationMatrix( ctm ), col); > > } > print("Ready"); > > // Reload > go(); > } > Best regards -- Michal Hocko |