PDFedit
PDF editor pro UNIX / PDF editor for UNIX

Wiki : ScriptingAddNewScript

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2010-02-17 02:06:08 by AdminX [remove spam]

No differences.


Edited on 2008-03-06 01:29:08 by TimC [typo and word correction]

Additions:

How to add your script to PDFedit (step by step example)

Example 1 - drawing arrows

Step 1: Writing the script

Our aim is to be able to draw simple arrows. We use a simple algorithm which takes 2 coordinates specifying the start and the end of a line and gives us 2
coordinates specifying left and right end point of an arrow. The end point is computed as the 1/10 of the main line width in 45 degree angle.
We use built-in script function operatorDrawLine which takes an array of lines to draw, line width and line colour.
We obtain the line width and the line colour from default menu selectors using built-in functions.
Input coordinates and output coordinates may differ because page can use arbitrary transformation of coordinates. That is why every
coordinate needs to be converted using either convertPixmapPosToPdfPos_x or convertPixmapPosToPdfPos_y function.
An array consists of 3 lines. The main one connecting first two points, then one connecting left end point with
the end of the line, and likewise the right end point with the end of line. We use the input points as the start and end of the main line which is drawn first. Then
the line connecting left end and then the one connecting right end.
Finally reload the page to see the result.
/**
 * Draw an arrow.
  */
// Get the end points
// Convert main line points
// Convert arrow end points
"linewidth"), getColor("fg"));
    // Reload page
    go()
}

Step 2: Adding the script

Open dialogs.qs which should be in your install directory. Add the function drawArrow to the end (optionally write a comment describing the function in doxygen-like style to add the function in command line documentation which is automatically generated) and save the file.
Then after either restarting the application or reloading the script file calling
run ("dialogs.qs")
in command line
we can manually call the function from the command line.

Step 3: (optional) Finding new icon

Try e.g. kde look&feel; to get hicolor icons (32x32).
Add the icon to either icon or icon/something directory to match your actual icon set directory.

Step 4, alternative 1: Connecting button and mouse events with our function

In callback.qs add
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe');
}

These two functions are almost identical (only first is really needed the latter one is for functions that can be even more customized and require a dialog). They set a drawing mode (we use an existing one which draws lines) and when it finished (the user releases the mouse) the function drawArrow is called with two points marking the start and the end
of the input sequence (when the mouse was pressed and when the mouse was released).
In pdfeditrc add
 

which means that an item is created which can be referenced from other items. The item is described by a name, action to take when clicked, button icon, what is needed to
make the button enabled, the mode of the button.
And add the button to the toolbar by adding drawarrowe to
 

the result can look like this
 

this shows the button in the DrawToolbar menu.

Step 4, alternative 2: Creating the script as a plugin script

Take the code from step 1 and append this code to the end of the script.
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe''DrawToolbar','drawarrow',tr('Draw arrow'),'onSelectMode_drawArrow()','','draw_arrow.png',['need_page','mode_button''DrawToolbar','drawarrowe',tr('Draw arrow'),'onSelectMode_drawArrowe()','','draw_arrowe.png',['need_page','mode_button']);

Save it as "arrow.qs" and put the script in "scripts" dicrectory
Installation
You can use easier method of installation by downloading the script file and associated icons.
Put the script file in your home directory in subdirectory .pdfedit/scripts
Put the associated icons into .pdfedit/icon subdirectory in your home directory
No other installation is necessary, the function will be available next time you start the editor. If you do not want to restart editor, you can load the new functions while the editor is running by typing run("scripts/name_of_script.qs") in editor command line.

If you have root privileges, you can install this script for everybody - put the script file into /usr/local/share/pdfedit/scripts and icons into /usr/local/share/pdfedit/icon directory
(Assuming you have not changed default installation path)
  Attachment Size Date Added
      arrow.qs   1.73 KB   15.9.2006 00:00:00
 
 
add new attachment:

Categories
Scripting
Howto


Deletions:

How to add your script to PDFedit (step by step example)



Example 1 - drawing arrows


Step 1: Writing the script


Our aim is to be able to draw simple arrows. We use a stupid algorithm which takes 2 coordinates specifying the start and the end of a line and gives us 2
coordinates specifying left and right end point of an arrow. The end point is computed as the 1/10 of the main line width in 45 degree angle.
We use built-in script function operatorDrawLine which takes an array of lines to draw, line width and line colour.
We obtaing the line width and the line colour from default menu selectors using built-in functions.

Input coordinates and output coordinates may differ because page can use arbitrary transformation of coordinates. That is why every
coordinate needs to be converted using either convertPixmapPosToPdfPos_x or convertPixmapPosToPdfPos_y function.
An array consists of 3 lines. The main one connecting first two points, then one connecting left end point with
the end of the line, and likewise the right end point with the end of line. We use the input points as the start and end of the main line which is drawn first. Then
the line connecting left end and then the one connecting right end.

Finally reload the page to see the result.

/**
 * Draw an arrow.
  */
// Get the end points
// Convert main line points
// Convert arrow end points
"linewidth"), getColor("fg"));
    // Reload page
    go()
}


Step 2: Adding the script


Open dialogs.qs which should be in your install directory. Add the function drawArrow to the end (optionally write a comment describing the function in doxygen-like style to add the function in command line documentation which is automatically generated) and save the file.
Then after either restarting the application or reloading the script file calling
run ("dialogs.qs")
in command line
we can manually call the function from the command line.

Step 3: (optional) Finding new icon


Try e.g. kde look&feel; to get hicolor icons (32x32).
Add the icon to either icon or icon/something directory to match your actual icon set directory.

Step 4, alternative 1: Connecting button and mouse events with our function


In callback.qs add

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe');
}

These two functions are almost identical (only first is really needed the latter one is for functions that can be even more customized and require a dialog). They set a drawing mode (we use an existing one which draws lines) and when it finished (the user releases the mouse) the function drawArrow is called with two points marking the start and the end
of the input sequence (when the mouse was pressed and when the mouse was released).

In pdfeditrc add
 

which means that an item is created which can be referenced from other items. The item is described by a name, action to take when clicked, button icon, what is needed to
make the button enabled, the mode of the button.

And add the button to the toolbar by adding drawarrowe to
 

the result can look like this
 

this shows the button in the DrawToolbar menu.

Step 4, alternative 2: Creating the script as a plugin script


Take the code from step 1 and append this code to the end of the script.

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe''DrawToolbar','drawarrow',tr('Draw arrow'),'onSelectMode_drawArrow()','','draw_arrow.png',['need_page','mode_button''DrawToolbar','drawarrowe',tr('Draw arrow'),'onSelectMode_drawArrowe()','','draw_arrowe.png',['need_page','mode_button']);


Save it as "arrow.qs" and put the script in "scripts" dicrectory

Circular reference detected
  Attachment Size Date Added
      arrow.qs   1.73 KB   15.9.2006 00:00:00
 
 
add new attachment:

Categories
Scripting
Howto




Edited on 2007-02-08 11:45:33 by JozefMisutka

Additions:

How to add your script to PDFedit (step by step example)



Example 1 - drawing arrows


Step 1: Writing the script


Our aim is to be able to draw simple arrows. We use a stupid algorithm which takes 2 coordinates specifying the start and the end of a line and gives us 2
coordinates specifying left and right end point of an arrow. The end point is computed as the 1/10 of the main line width in 45 degree angle.
We use built-in script function operatorDrawLine which takes an array of lines to draw, line width and line colour.
We obtaing the line width and the line colour from default menu selectors using built-in functions.

Input coordinates and output coordinates may differ because page can use arbitrary transformation of coordinates. That is why every
coordinate needs to be converted using either convertPixmapPosToPdfPos_x or convertPixmapPosToPdfPos_y function.
An array consists of 3 lines. The main one connecting first two points, then one connecting left end point with
the end of the line, and likewise the right end point with the end of line. We use the input points as the start and end of the main line which is drawn first. Then
the line connecting left end and then the one connecting right end.

Finally reload the page to see the result.

/**
 * Draw an arrow.
  */
// Get the end points
// Convert main line points
// Convert arrow end points
"linewidth"), getColor("fg"));
    // Reload page
    go()
}


Step 2: Adding the script


Open dialogs.qs which should be in your install directory. Add the function drawArrow to the end (optionally write a comment describing the function in doxygen-like style to add the function in command line documentation which is automatically generated) and save the file.
Then after either restarting the application or reloading the script file calling
run ("dialogs.qs")
in command line
we can manually call the function from the command line.

Step 3: (optional) Finding new icon


Try e.g. kde look&feel; to get hicolor icons (32x32).
Add the icon to either icon or icon/something directory to match your actual icon set directory.

Step 4, alternative 1: Connecting button and mouse events with our function


In callback.qs add

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe');
}

These two functions are almost identical (only first is really needed the latter one is for functions that can be even more customized and require a dialog). They set a drawing mode (we use an existing one which draws lines) and when it finished (the user releases the mouse) the function drawArrow is called with two points marking the start and the end
of the input sequence (when the mouse was pressed and when the mouse was released).

In pdfeditrc add
 

which means that an item is created which can be referenced from other items. The item is described by a name, action to take when clicked, button icon, what is needed to
make the button enabled, the mode of the button.

And add the button to the toolbar by adding drawarrowe to
 

the result can look like this
 

this shows the button in the DrawToolbar menu.

Step 4, alternative 2: Creating the script as a plugin script


Take the code from step 1 and append this code to the end of the script.

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}

/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe''DrawToolbar','drawarrow',tr('Draw arrow'),'onSelectMode_drawArrow()','','draw_arrow.png',['need_page','mode_button''DrawToolbar','drawarrowe',tr('Draw arrow'),'onSelectMode_drawArrowe()','','draw_arrowe.png',['need_page','mode_button']);


Save it as "arrow.qs" and put the script in "scripts" dicrectory

Circular reference detected
  Attachment Size Date Added
      arrow.qs   1.73 KB   15.9.2006 00:00:00
 
 
add new attachment:

Categories
Scripting
Howto


Deletions:

How to add your script to PDFedit (step by step example)

Example 1 - drawing arrows

Step 1: Writing the script

Our aim is to be able to draw simple arrows. We use a stupid algorithm which takes 2 coordinates specifying the start and the end of a line and gives us 2
coordinates specifying left and right end point of an arrow. The end point is computed as the 1/10 of the main line width in 45 degree angle.
We use built-in script function operatorDrawLine which takes an array of lines to draw, line width and line colour.
We obtaing the line width and the line colour from default menu selectors using built-in functions.
Input coordinates and output coordinates may differ because page can use arbitrary transformation of coordinates. That is why every
coordinate needs to be converted using either convertPixmapPosToPdfPos_x or convertPixmapPosToPdfPos_y function.
An array consists of 3 lines. The main one connecting first two points, then one connecting left end point with
the end of the line, and likewise the right end point with the end of line. We use the input points as the start and end of the main line which is drawn first. Then
the line connecting left end and then the one connecting right end.
Finally reload the page to see the result.
/**
 * Draw an arrow.
  */
// Get the end points
// Convert main line points
// Convert arrow end points
"linewidth"), getColor("fg"));
    // Reload page
    go()
}

Step 2: Adding the script

Open dialogs.qs which should be in your install directory. Add the function drawArrow to the end (optionally write a comment describing the function in doxygen-like style to add the function in command line documentation which is automatically generated) and save the file.
Then after either restarting the application or reloading the script file calling
run ("dialogs.qs")
in command line
we can manually call the function from the command line.

Step 3: (optional) Finding new icon

Try e.g. kde look&feel; to get hicolor icons (32x32).
Add the icon to either icon or icon/something directory to match your actual icon set directory.

Step 4, alternative 1: Connecting button and mouse events with our function

In callback.qs add
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe');
}

These two functions are almost identical (only first is really needed the latter one is for functions that can be even more customized and require a dialog). They set a drawing mode (we use an existing one which draws lines) and when it finished (the user releases the mouse) the function drawArrow is called with two points marking the start and the end
of the input sequence (when the mouse was pressed and when the mouse was released).
In pdfeditrc add
 

which means that an item is created which can be referenced from other items. The item is described by a name, action to take when clicked, button icon, what is needed to
make the button enabled, the mode of the button.
And add the button to the toolbar by adding drawarrowe to
 

the result can look like this
 

this shows the button in the DrawToolbar menu.

Step 4, alternative 2: Creating the script as a plugin script

Take the code from step 1 and append this code to the end of the script.
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)");
 setModeButton('drawarrow');
}
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)");
 setModeButton('drawarrowe''DrawToolbar','drawarrow',tr('Draw arrow'),'onSelectMode_drawArrow()','','draw_arrow.png',['need_page','mode_button''DrawToolbar','drawarrowe',tr('Draw arrow'),'onSelectMode_drawArrowe()','','draw_arrowe.png',['need_page','mode_button']);

Save it as "arrow.qs" and put the script in "scripts" dicrectory
Circular reference detected
  Attachment Size Date Added
      arrow.qs   1.73 KB   15.9.2006 00:00:00
 
 
add new attachment:

Categories
Scripting




Edited on 2006-09-22 21:17:31 by MartinPetricek

Deletions:
%%(cpp)



Edited on 2006-09-15 07:01:00 by MartinPetricek

Additions:

Step 4, alternative 1: Connecting button and mouse events with our function

Step 4, alternative 2: Creating the script as a plugin script

Take the code from step 1 and append this code to the end of the script.
%%(javascript)/ Callback when selection mode is changed to draw new arrow */
createMenuItem('DrawToolbar','drawarrow',tr('Draw arrow'),'onSelectMode_drawArrow()',,'draw_arrow.png',['need_page','mode_button']);
createMenuItem('DrawToolbar','drawarrowe',tr('Draw arrow'),'onSelectMode_drawArrowe()',
,'draw_arrowe.png',['need_page','mode_button']);
Save it as "arrow.qs" and put the script in "scripts" dicrectory


Deletions:

Step 4: Connecting button and mouse events with our function





Edited on 2006-09-15 04:41:44 by MartinPetricek

Additions:
Circular reference detected



Edited on 2006-09-15 04:24:49 by MartinPetricek

Additions:
  Attachment Size Date Added
      arrow.qs   1.73 KB   15.9.2006 00:00:00
 
 
add new attachment:




Edited on 2006-09-14 01:39:27 by JozefMisutka

Additions:
These two functions are almost identical (only first is really needed the latter one is for functions that can be even more customized and require a dialog). They set a drawing mode (we use an existing one which draws lines) and when it finished (the user releases the mouse) the function drawArrow is called with two points marking the start and the end of the input sequence (when the mouse was pressed and when the mouse was released).

Deletions:
???????????????????????????????????????



Edited on 2006-09-14 01:37:24 by MartinPetricek

Additions:
Scripting

Deletions:
CategoryScripting



Edited on 2006-09-14 01:33:14 by JozefMisutka

Additions:
which means that an item is created which can be referenced from other items. The item is described by a name, action to take when clicked, button icon, what is needed to
make the button enabled, the mode of the button.
the result can look like this
this shows the button in the DrawToolbar menu.


Deletions:
?????????????????????????????????????????
e.g.
??????????????????????????????????????????




Edited on 2006-09-14 01:26:50 by JozefMisutka

Additions:

Example 1 - drawing arrows

Step 1: Writing the script

Our aim is to be able to draw simple arrows. We use a stupid algorithm which takes 2 coordinates specifying the start and the end of a line and gives us 2
coordinates specifying left and right end point of an arrow. The end point is computed as the 1/10 of the main line width in 45 degree angle.
We use built-in script function operatorDrawLine which takes an array of lines to draw, line width and line colour.
We obtaing the line width and the line colour from default menu selectors using built-in functions.
Input coordinates and output coordinates may differ because page can use arbitrary transformation of coordinates. That is why every
coordinate needs to be converted using either convertPixmapPosToPdfPos_x or convertPixmapPosToPdfPos_y function.
An array consists of 3 lines. The main one connecting first two points, then one connecting left end point with
the end of the line, and likewise the right end point with the end of line. We use the input points as the start and end of the main line which is drawn first. Then
the line connecting left end and then the one connecting right end.
Finally reload the page to see the result.
/**
 * Draw an arrow.
  */
// Get the end points
// Convert main line points
// Convert arrow end points
"linewidth"), getColor("fg"));
    // Reload page
    go()
}

Step 2: Adding the script

Open dialogs.qs which should be in your install directory. Add the function drawArrow to the end (optionally write a comment describing the function in doxygen-like style to add the function in command line documentation which is automatically generated) and save the file.
Then after either restarting the application or reloading the script file calling
run ("dialogs.qs")
in command line
we can manually call the function from the command line.

Step 3: (optional) Finding new icon

Try e.g. kde look&feel; to get hicolor icons (32x32).
Add the icon to either icon or icon/something directory to match your actual icon set directory.

Step 4: Connecting button and mouse events with our function

In callback.qs add
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,false)"'drawarrow');
}
/** Callback when selection mode is changed to draw new arrow */"new_object","line","drawArrow(%1,%2,%3,%4,true)"'drawarrowe');
}

???????????????????????????????????????
In pdfeditrc add
 

?????????????????????????????????????????
And add the button to the toolbar by adding drawarrowe to
 

e.g.
 

??????????????????????????????????????????




Oldest known version of this page was edited on 2006-09-13 23:33:30 by JozefMisutka [-- step by step script add example created]
Page view:

How to add your script to PDFedit (step by step example)






Categories
CategoryScripting