Skip to main content
Participating Frequently
July 14, 2009
Answered

How to generate transparent preview of the document?

  • July 14, 2009
  • 1 reply
  • 1178 views

Hi all,

I would like to generate trsansparent preview of an document in PNG file. Normal (not-transparent preview) I am doing by JavaScript like it is described below:

var myDocument = app.open(File(app.scriptArgs.getValue("documentPath")));
myDocument.exportFile(ExportFormat.jpg, File(app.scriptArgs.getValue("thumbnailPath")), PDFExportPreset.acrobatCompatibility);
myDocument.close(SaveOptions.no);

The result is normal JPG file. But I would like to get a transparent image. How can I do this?

Thank you for all information!

This topic has been closed for replies.
Correct answer Jongware

That's what you get for not mentioning your InDesign version ... PNG_FORMAT has been added in CS4.

Oh, and thanks by the way for reminding me of that site.

On official Adobe webpage...

Don't make me laugh. "That's funny -- it looks suspicously much like the HTML I bloody generated a while ago from the provided Help files" is what I said when I first saw it.

A full Javascript reference for both CS3 and CS4 scriptable objects can be found on http://www.jongware.com/idjshelp.html -- and those are the original results of my own hard work, not some pirated and unacknowledged and heavy-advertising piece of theft.

1 reply

Jongware
Community Expert
Community Expert
July 14, 2009

ExportFormat also has a PNG variant (ExportFormat.PNG_FORMAT), but if you want to know if it contains alpha transparency, you'll have to try it. There are no further parameters you can set.

(..several minutes later..)

And I just tried it myself. No: you cannot use it on "myDocument" (an entire document) -- only on "single" objects (a group is a single object).

But, Yes: the background is transparent.

Participating Frequently
July 16, 2009

Hmm could you give any example of code? According to the scripting reference there is nothing like "ExportFormat.PNG_FORMAT" - I cannot even find this in Google. On official Adobe webpage in the scripting reference I can find:

Name Description Value
TAGGED_TEXTExports to a tagged text file with a TXT extension.1416066168  =                 'Tgtx'
PDF_TYPEExports to PDF format.1952403524  =                 't_PD'
EPS_TYPEExports to EPS format.1952400720  =                 't_EP'
RTFExports to rich text format (RTF).1381254688  =                 'RTF '
SVGExports to SVG format.1398163232  =                 'SVG '
SVG_COMPRESSEDExports to SVGZ format.1398163267  =                 'SVGC'
TEXT_TYPEExports to text (TXT) format.1952412773  =                 't_te'
XMLExports the document's tagged content to XML.1481460768  =                 'XML '
JPGExports to JPEG format.1246775072  =                 'JPG '
INDESIGN_INTERCHANGEExports to InDesign Interchange (INX) format.1229871136  =                 'INX '
INDESIGN_SNIPPETExports to InDesign Snippet (INDS) format.1936617588  =                 'snpt'
INCOPY_CS_DOCUMENTExports to InCopy CS document (INCD) format.1702126436  =                 'etcd'
INCOPY_DOCUMENTExports to InCopy document (INCX) format.1702126456  =                 'etcx'

and this is all (http://www.indesignscriptingreference.com/CS3/JavaScript/ExportFormat-enum.htm). When I am trying to use the code on a group of objects, it is failing. The code:

var myDocument = app.documents.add();
myDocument.pages.item(0).place(File(app.scriptArgs.getValue("snippetPath")));

g = myDocument.pages.item(0).groups.add (myDocument.pages.item(0).allPageItems);
g.exportFile(ExportFormat.PNG_FORMAT, File(app.scriptArgs.getValue("pngThumbnailPath")), PDFExportPreset.acrobatCompatibility);

myDocument.close(SaveOptions.no);

And the error:

Error Number: 55
Error String: Object does not support the property or method 'PNG_FORMAT'
Line: 6
Source: g.exportFile(ExportFormat.PNG_FORMAT, File(app.scriptArgs.getValue("pngThumbnailPath")), PDFExportPreset.acrobatCompatibility);

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
July 16, 2009

That's what you get for not mentioning your InDesign version ... PNG_FORMAT has been added in CS4.

Oh, and thanks by the way for reminding me of that site.

On official Adobe webpage...

Don't make me laugh. "That's funny -- it looks suspicously much like the HTML I bloody generated a while ago from the provided Help files" is what I said when I first saw it.

A full Javascript reference for both CS3 and CS4 scriptable objects can be found on http://www.jongware.com/idjshelp.html -- and those are the original results of my own hard work, not some pirated and unacknowledged and heavy-advertising piece of theft.