predefined stamps

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

predefined stamps

Post by TatianaS » Wed Mar 27, 2013 6:54 pm

Hello,
I have my own set of predefined text and bitmap stamps in my UI. I do not want to display your Stamp Tool in the viewer.
When user selects one of my stamps and click on the document, I want that text/bitmap to be pasted into the document.
Could you please advise me what will be the best way to accomplish that programmatically. Do I need to use java script to be able to paste bitmap stamps? If I need to use events for that, could you please provide some example. At this point I am not sure what events I should monitor.

Thanks.

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: predefined stamps

Post by Nico - Tracker Supp » Wed Mar 27, 2013 9:28 pm

Hi TatianaS,

Thank you for your post.
Regarding your questions, if you want to do create and place a stamp programmatically, you need to use JavaScript.
For example:
var annot = this.addAnnot
({
page: 0,
type: "Text",
author: "A. C. Robat",
point: [300,400],
strokeColor: color.yellow,
contents: "Need a little help with this paragraph.",
noteIcon: "Help"
});

For more examples please consult Adobe JS Reference manual: http://www.adobe.com/content/dam/Adobe/ ... erence.pdf
Supported JavaScript functionality is available on section 2.3 from the Viewer ActiveX manual.

You can run JavaScript from your application by using RunJavaScript method (section 2.1.1.1.7 from the Viewer ActiveX manual).
An example of this method can be found in the FullDemo application that comes with the Viewer ActiveX SDK.
Thanks.

Sincerely,

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Mon Apr 08, 2013 11:56 pm

Hi, could you please help me to figure out how can I add an image stamp (.bmp) to my page without using stamp tool.
My stamps are stored in the specific location I cannot change that. I tried to use js, but without any luck. I also found command #36304 Create Stamp from Image File..., but not sure how to use it. I would appreciate any help.
Thanks.

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: predefined stamps

Post by Nico - Tracker Supp » Tue Apr 09, 2013 10:28 pm

Hi TatianaS,

Thank you for your post.
Regarding your questions:
could you please help me to figure out how can I add an image stamp (.bmp) to my page without using stamp tool.
Using the stamp tool (Stamp Palette) is the simplest way, however there is another alternative which consists in utilizing the Windows clipboard as a means to pass the contents of your .bmp file. This approach would include the following steps:

1. place the any picture into Windows clipboard:

2. call the pdfViewer.DoVerb(NULL, "ExecuteCommand", DataIn("Paste"), NULL, 0);

3. intercept the event about adding new annot by:

OnEvent(type, name...)
{
if (type == PXCVA_OnNamedNotify)
{
if (name == "Notifications.NewAnnotAdded")
{
int pageIndex = -1;
string newAnnotName;
pdfViewer.GetProperty("Notifications.NewAnnotAdded.PageIndex", out pageIndex, 0);
pdfViewer.GetProperty("Notifications.NewAnnotAdded.Name", out newAnnotName, 0);
if (pageIndex >= 0)
{
// move the new stamp to another position, if needed
string jsNewRect = "[200, 200, 300, 300]";
string js = "var ann = this.getAnnot(" + pageIndex ", "" + annotName + ""); if (ann != null) ann.rect=" + jsNewRect;
pdfViewer.RunJavaScript(js...);
}
}
}
}
I also found command #36304 Create Stamp from Image File..., but not sure how to use it
The command 36304 does the same as clicking with the mouse on ShowStampsPalette->From Image button, which opens a dialog to look for the source image file for the new stamp.
Thanks.
Sincerely,

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Thu Apr 11, 2013 5:54 pm

Thank you so much for your response. I tried the to make it work, but I need the stamp to be added on left mouse click event.
So, what I do is to monitor the mouse, get coordinates on left click, load bitmap into clipboard and paste it. Then on NewAnnotAdded notification, I am moving it to the coordinates of the mouse I previously saved. However, the Paste doesn't work inside onEvent() and I get "Command is disabled currently" error message. It does work however if image loading, clipboard copying and paste code are called outside the onEvent (when user clicks my button). It seams strange that I can't call event within event.

1. Select predefined bitmap image from my app
2. OnEvent(Type_, name...) {

if (Type_ = PXCVA_OnNamedNotify) and (Name = 'Notifications.Mouse') then begin
fPDFViewer.GetProperty('Notifications.Mouse.Msg', vDataOut, 0);//get mouse position
if (vDataOut = 514) then begin //WM_LBUTTONUP
fPDFViewer.GetProperty('Notifications.Mouse.X', vDataOutX, 0);
fPDFViewer.GetProperty('Notifications.Mouse.Y', vDataOutY, 0);
fsx := vDataOutX;
fsy := vDataOutY;

//load bitmap to the clipboard
fBitmapStamp := TBitmap.Create;
fBitmapStamp.LoadFromFile('..\usertile11.bmp');
Clipboard.Clear;
Clipboard.Assign(fBitmapStamp);
//paste from clipboard
fPDFViewer.DoVerb('', 'ExecuteCommand', 'Paste', DataOut, 0);
end;
end
else if (Type_ = PXCVA_OnNamedNotify) and (name = 'Notifications.NewAnnotAdded') then begin
fPDFViewer.GetProperty('Notifications.NewAnnotAdded.Name', DataOut, 0);
MoveStamp(aAnnName);//run js to move annotation to the mouse coordinates: fsx,fsy
end;
end;

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Thu Apr 11, 2013 6:07 pm

I also tried to use stamp tool, but without success. I have a couple stamps saved in C:\Users\{user}\AppData\Roaming\Tracker Software\PDF-XChange Viewer\2.0\Stamps as pdfs and can see and use them in the viewer. When I run code

GetProperty("Commenting.StickyNote.Styles.Count", DataOut, 0);
Count = DataOut;
...
for i = 0 to Count-1
{
GetProperty("Commenting.Stamp.Styles[" + i + "].ID", DataOut1, 0);
GetProperty("Commenting.Stamp.Styles[" + i + "].Name", DataOut2, 0);
GetProperty("Commenting.Stamp.Styles[" + i + "].Type", DataOut3, 0);
...
}
...
I only get one stamp:
[61952, Default Style, Draft]

Do I need to have my stamps in different directory for the development too?

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: predefined stamps

Post by Nico - Tracker Supp » Thu Apr 11, 2013 8:26 pm

Hi TatianaS,

Thank you for your post.
Regarding your questions:
1.
However, the Paste doesn't work inside onEvent() and I get "Command is disabled currently" error message
You can try to post a custom message to remind your application to execute the paste command once OnEvent has finished (Ref: http://msdn.microsoft.com/en-ca/library ... 85%29.aspx)
2. About the stamps tool, you need to:
1. Show the stamp palette
2. Select a palette collection other than the Standard
3. Call Create stamp from PDF Document command to show the Open File dialog
Step 2 cannot be done programmatically, you may find ways around this but we don't recommend it because the stamp palette dialog was designed to be accessed by the GUI, therefore there is not a direct way to select a palette collection programmatically.
Thanks.

Sincerely,

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Mon Apr 15, 2013 8:01 pm

Thank you, I created custom post message and succeeded to paste my stamp from the clipboard, but event Notifications.NewAnnotAdded never triggered (I print all of them to the console). Do I need to have some kind of filter defined for it? This notification is not in the documentation, so I do not have any references.

OnEvent(type, name...)
{
if (type == PXCVA_OnNamedNotify)
{
if (name == "Notifications.NewAnnotAdded")

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: predefined stamps

Post by Nico - Tracker Supp » Mon Apr 15, 2013 9:02 pm

Hi TatianaS,

Thank you for your post.
To activate the NewAnnotAdded notification, please register the text editor notifications first:

Code: Select all

// C++
CComBSTR bsPropName(L"Notifications.TextEditor.Filter");
CComVariant vDataIn(L"All");
m_spView->SetProperty(bsPropName, vDataIn, 0);
Thanks.
Sincerely,

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Mon Apr 15, 2013 11:45 pm

That didn't help unfortunately. I am not pasting text though, it is a bitmap stamp.

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1983
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: predefined stamps

Post by Vasyl-Tracker Dev Team » Tue Apr 16, 2013 1:18 am

Hi, TatianaS.

Code: Select all

OnEvent(type, name...)
{
if (type == PXCVA_OnNamedNotify)
{
if (name == "Notifications.NewAnnotAdded")
- I checked it again and it working as expected.. Which build you have using? Because it is new event, added recently..

and the:

Code: Select all

CComBSTR bsPropName(L"Notifications.TextEditor.Filter");
CComVariant vDataIn(L"All");
m_spView->SetProperty(bsPropName, vDataIn, 0);
- isn't nessesary to enabling this event.. my colleague has been mistaken a little, sorry..

HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Tue Apr 16, 2013 7:38 pm

Thank you for your response. I actually do not need to catch Notifications.NewAnnotAdded. What I do is to call paste, with makes the annotation selected, and then I use js

fPDFViewer.DoVerb('', 'ExecuteCommand', 'Paste', DataOut, 0);
jsMsg := TStringBuilder.Create;
jsMsg.Append('var annots = this.selectedAnnots;');
jsMsg.Append('for (var i = 0; i < annots.length; i++){');
jsMsg.Append('annots.setProps({ rect: [...........................]});');
.....
jsMsg.Append('}');

fPDFViewer.RunJavaScript(jsMsg.ToString, out_, 0, 0);

and it woks :D

User avatar
Paul - Tracker Supp
Site Admin
Posts: 4999
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: predefined stamps

Post by Paul - Tracker Supp » Wed Apr 17, 2013 12:13 am

That's great to hear Tatiana,

:-)
_________________
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com

TatianaS
User
Posts: 103
Joined: Mon Mar 18, 2013 4:26 pm

Re: predefined stamps

Post by TatianaS » Wed Apr 17, 2013 6:08 pm

Hello, is there a way in javascript to set background color of a stamp to be transparent? I couldn't find it in the JavaScript API doc.

John - Tracker Supp
Site Admin
Posts: 8204
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: predefined stamps

Post by John - Tracker Supp » Thu Apr 18, 2013 2:00 am

Hi,

if I understand you correctly you are using an image as a stamp and therefore it would be the image background that would need to be transparent - not the stamp itself.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Post Reply