Run ExportToImage Command Silently

The PDF-XChange Viewer for End Users
+++ FREE +++

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

nutter308
User
Posts: 1
Joined: Thu Apr 09, 2015 8:49 am

Run ExportToImage Command Silently

Post by nutter308 »

Hi,

I have really been finding it tricky to use the javascript console with the lack of documentation or examples that are PDF-XChange Viewer specific and hopefully your forum can help me.

I have to export a load of PDF's into .jpg images so when i found the js console I set out to automate this as best I can. The below code will set layer1 to visible then layer2 to hidden then calls the menu command ExportToImage for all open Documents. Once complete it closes all open documents.

Is there anyway to get the ExportToImage to run silently so I don't have to click the export button each time?

Code: Select all

function ExportAllToImage(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var ocgs = ad[i].getOCGs();
	for (var e = 0; e < ocgs.length; e++)
	{
		if (ocgs[e].name == "layer1") {
			ocgs[e].state = true;
		} else if (ocgs[e].name == "layer2") {
			ocgs[e].state = false;
		}
	}
	app.execMenuItem("ExportToImage", ad[i]);
  }
  app.execMenuItem("CloseAllWindows")
}
ExportAllToImage()
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19930
Joined: Mon Jan 12, 2009 8:07 am

Re: Run ExportToImage Command Silently

Post by Stefan - PDF-XChange »

Hello nutter308,

Welcome to our forums. This command opens a dialogue box and:
Modal dialog boxes must be closed by the user before the host application can be directly used again.
I've tried to find a way to "click" that OK button but have been unsuccessful, so I am afraid that you can not automate the export this way.

Also the Viewer is the older product - please consider using the Editor instead as the JS support in it is better:
https://www.pdf-xchange.com/produc ... nge-editor
There the command to open the Export To Images window is:
app.execMenuItem("cmd.document.export.toImages", this );

An alternative solution could be to e.g. merge multiple files (it's easy with the Editor -> File -> New Document -> Combine Files), and then export to images the new multi page merged file so you will only need to click that OK button once.

Regards,
Stefan