Javascript API: buttonImportIcon() crashing PDFXEdit  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

SB-GFP
User
Posts: 21
Joined: Thu Sep 12, 2024 11:01 am

Javascript API: buttonImportIcon() crashing PDFXEdit

Post by SB-GFP »

Hello Community

Just for clarification:
this concerns JS contained in a PDF, not the SDK.

I have been using the Field method buttonImportIcon for a long time to have PDFXEdit prompt the user for an icon for a field. Note the empty string for cPath.

The following code snipped worked in version 8 and 9:

Code: Select all

let foo = this.getField('foo');
foo.buttonImportIcon({cPath: ''})

This functionality appears to be broken in Version 10.
Was this ever officially supported and what would be my alternative?

The above code works if I do specify a valid path for cPath.
Also, the error is not beeing caught within a try/catch block.

The code is beeing execute in a (dynamic) stamps file

Thanks to all
Sebastian
Sebastian Bartel
IT-Everything
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13189
Joined: Wed Jan 03, 2018 6:52 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Daniel - PDF-XChange »

Hello, SB-GFP

Sorry for the delay, I have escalated this to our Dev team for review and resolution.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13189
Joined: Wed Jan 03, 2018 6:52 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Daniel - PDF-XChange »

Hello,

Just a quick followup, you noted this started after V10, can you confirm which specific build you are running at the moment? The latest release is 10.8.4, so if you are not updated, please do so now.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
SB-GFP
User
Posts: 21
Joined: Thu Sep 12, 2024 11:01 am

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by SB-GFP »

Hello,

Yes, the functionality broke after updating from v.8 to v.10.7.2
I'm currently updating tp 10.8.4. Shall I let you know if the issus persists?
Sebastian Bartel
IT-Everything
SB-GFP
User
Posts: 21
Joined: Thu Sep 12, 2024 11:01 am

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by SB-GFP »

Bseides the question whether version 10 supports an empty path, i.e.

Code: Select all

MyForm.buttonImportIcon({cPath:''})
Let me dscribe, how I resolved the issue. Maybe that will give you additional information as to why buttonImportIcon() wouldn't accept an empty path anymore.

I delegated the functionality 'prompt user for a file path' from the code inside stamps.pdf to folder level javascript in
%appdata%/.../Javascript/stamps.js
Like so:

stamps.js:

Code: Select all

Stamps.getFilePath = function(cInit='*.*') {
	try {
		var r = app.browseForDoc({cFilenameInit:cInit});
		return (typeof r != "undefined" ? r.cPath : null);
	}
	catch (e) {
		console.println("Stamps:getFilePath() EXC: " + e);
		return null;
	}
};
This throws a security exception.
Then I wrapped Stamps.getFilePath() in an app.trustedFunction which solved the issue.

In summary, I replaced my file level script: MyForm.buttonImportIcon({cPath:''})
With folder level script:

Code: Select all

Stamps.getFilePath = app.trustedFunction(function(cInit='*.*') {
app.beginPriv();
	try {
		var r = app.browseForDoc({cFilenameInit:cInit});
        }
     // ... 
}
Sebastian Bartel
IT-Everything
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13189
Joined: Wed Jan 03, 2018 6:52 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Daniel - PDF-XChange »

Hello, SB-GFP

Terribly sorry for the delay, somehow I missed this until just now, for which I apologize. I have just sent this new information up the chain for further review (and they informed me that I misread your reply anyway, it seems that you found the correct solution here)

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
SB-GFP
User
Posts: 21
Joined: Thu Sep 12, 2024 11:01 am

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by SB-GFP »

Hello Daniel

Yes, I have found a workaround for my problem.
It would still be informative for the community to understand the root of the problem. Candidates are:

a) improper exception handling in file level script (in stamp files)
b) improper usage (me) or implementation (you) of buttonImportIcon()

Cheers, Sebastian
Sebastian Bartel
IT-Everything
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13189
Joined: Wed Jan 03, 2018 6:52 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Daniel - PDF-XChange »

Hello, SB-GFP

It looks to be a case opf B, this is what i got from the Dev team:
In V10, we are following the JS spec, respecting security.
He found the proper solution - use of app.trustedFunction
Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
User avatar
Mathew
User
Posts: 907
Joined: Thu Jun 19, 2014 7:30 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Mathew »

Daniel - PDF-XChange wrote: Thu Apr 23, 2026 6:15 pm Hello, SB-GFP

It looks to be a case opf B, this is what i got from the Dev team:
In V10, we are following the JS spec, respecting security.
He found the proper solution - use of app.trustedFunction
Kind regards,
Hi Daniel,
Do the dev team understand that this is crashing PXCE? Shouldn't it just throw an error? The attached stamp file crashes build 410 with the following javascript:

Code: Select all

{
  const f = this.getField("Button2");
  let res;
  try{
    // this crashes after the stamp is placed - it appears to set the icon OK, but then crashes
    res = f.buttonImportIcon();
    } catch(e) {
    console.println(e)
  }
  console.println("Result: "+res);
}
I'm not good at making these animated gifs, but this tries to show:
buttonImportCrash.gif
Mathew.
test_crashes_buttonImportIcon.pdf
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 13189
Joined: Wed Jan 03, 2018 6:52 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Daniel - PDF-XChange »

Hello, Mathew

Yes, the note about crashing was conveyed, however we could not reproduce any such crash on this end. Are you also updated to 10.8.5? If you are and there is still a crash, I would need to ask for a crashdump to provide the dev team.
As usual, these should appear here automatically:
%localappdata%\CrashDumps

You can upload them here: https://files.pdf-xchange.com/s/ke74kiTHjCSAHaj

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
[email protected]
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3611
Joined: Thu Jul 08, 2004 10:36 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit  SOLVED

Post by Ivan - Tracker Software »

No crash dump required - the issue is found and fixed.
The fix will be included in the next build of V10 and V11.
Sorry for the inconvenience.
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
SB-GFP
User
Posts: 21
Joined: Thu Sep 12, 2024 11:01 am

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by SB-GFP »

Hello Everybody
Thanks to all for contributing and resolving the issue.

Cheers, Sebastian
Sebastian Bartel
IT-Everything
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1175
Joined: Wed Sep 14, 2016 5:42 pm

Re: Javascript API: buttonImportIcon() crashing PDFXEdit

Post by Sean - PDF-XChange »

:)
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623