InDesign Server Scripting - Exporting Link Graphics

New Here ,
Jan 30, 2022 Jan 30, 2022

Copy link to clipboard

Copied

Hello,

 

A portion of my script is reponsible for iteratring allGraphics, and and doing some inspection of their constituent image data. If certain conditions match, the graphic is exported as a JPEG image.

 

I've encountered an interesting problem whereby an artist has set a 2-page InDesign document using a 2-page PDF. On page 1 of the indd document, a rectangle is set, and they have placed PDF page 1 as its graphic.

 

The same is true for page two. The artist has placed, again, this same 2-page pdf, but on page two of the indd, its rectangle uses page 2 of the pdf. Neat lazy trick, I think. Rather than have two links in their document, they have simply used the same asset, twice, and simply arranged the pdf in such a way that it can be used twice. Cute trick.

 

But that cute trick is giving my graphic exporter fits. When it reaches that link, and its graphic, it is only exporting page one of it.

 

I am seeking help here in this forum to determine how to address the graphic, and get it to export both pages.

 

When I export a multi-page indd as JPEG, I have access to jpegExportRange. I use ExportRangeOrAllPages.EXPORT_RANGE, and I specify app.jpegExportPreferences.pageString = [1,2,3,4,5], etc, and indesign dutifully exports that page to a jpeg. The exported JPEG filename, of course, includes that page number; eg: indd-document-page-1.jpg, indd-document-page-2.jpg, and so on.

 

Well, this strategy is not working for the Link graphic. I can see that the graphic PDF has two pages when I inspect graphic.pdfAttributes.pageNumber. But when I export that Link Graphic to the filesystem, as a JPEG (or other format), I only receive page 1.

 

Thanks for any insights you might have.

TOPICS
Scripting

Views

61

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2022 Jan 30, 2022

Copy link to clipboard

Copied

<facepalm>

 

Filename is important. And, reading comments I wrote into this script 8 years ago...

 

Apparently, a client I had during the Obama administration had an interesting edge case. To resolve this, just prior to export, I actually removed the link, and re-placed it. Likely to clear out fitting options. I wanted the whole graphic, but this client had done some interesting fitting options that was obsucring parts of the image. So, I blew away the link graphic, and re-placed it.

 

That action screwed up the 2nd phase, the actual graphic export.

 

tl;dr: Comment your code well. Read your old comments. Heed your own warnings from your younger self.

 

{sigh}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 30, 2022 Jan 30, 2022

Copy link to clipboard

Copied

LATEST

Hi @jeffmlevy ,

I have setup 2 pages document as below.

SumitKumar_0-1643606391247.png

 

export2jpg();

function export2jpg() {
    if (!(app.documents.length)) return;
    app.jpegExportPreferences.properties = {
        jpegColorSpace: JpegColorSpaceEnum.RGB,
        jpegExportRange: ExportRangeOrAllPages.EXPORT_ALL,
        jpegQuality: JPEGOptionsQuality.MAXIMUM,
    }
    var __ = $.global.localize,
        doc = app.documents[0],
        docFile = new File(doc.fullName),
        docPath = docFile.parent,
        jpgPathPattern = docPath + "/indd-document-page-%1.jpg";
    var re = /\.pdf$/i, link, rectangle, page, pageName;
    for (var i = 0, links = doc.links, n = links.length; i < n; i++) {
        link = links[i];
        if (re.test(link.name)) {
            rectangle = link.parent.parent;
            if ((page = rectangle.parentPage)) {
                pageName = page.name;
                rectangle.exportFile(ExportFormat.JPG, new File(__(jpgPathPattern, pageName)));
            }
        }
    }
}

 

Generated 2 separate jpg file

SumitKumar_1-1643608988303.png

 

 

-Sumit

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines