InDesign script export comes out non-deterministically low quality

New Here ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

TLDR; simple export script does not produce high quality, especially if run twice in a row.

Video demonstration: https://youtu.be/c0VsvCZskJY

 

 

 

Full Story:

Hi folks. Backstory is that I have been using InDesign to automatically create docs in my small business since 2010. We used Indesign up to 2018 with much success, but 2019 onward started giving us big quality issues. I left the company and was doing support on a consulting basis, and never really invested time to figure out what was up. They just stuck with 2018. Well, now they can't download 2018 on new machines, so we must fix it!

 

I have created a small reproduction with InDesign 2021 and a single page document with JPEGs and vector PDF images.

 

The export script is pretty simple:

 

defaultHQPreset = app.pdfExportPresets.itemByName('[High Quality Print]');
var scriptParentPath = (new File($.fileName)).parent.toString()
var docFile = File(scriptParentPath + "/" + "sample_chapter.indd");
var theDoc = app.open(docFile)
var outputPDFFile = File(docFile.toString()+".pdf");
theDoc.exportFile(ExportFormat.PDF_TYPE, outputPDFFile, false, defaultHQPreset);
theDoc.close(SaveOptions.NO);

 

 

If I do a manual export from InDesign, close the doc, then run the script, the PDF comes out nice. If I run the script a second time, all graphics are low quality.

 

Side note: I have manually turned off link updating/fixing in the preferences. This means no dialog boxes when our automation is running, and we do some manual rewriting of link sources when running our full workflow. None of that matters here, but the setting might.

 

One things I noticed, is that when I open the doc manually, all graphics are fuzzy for a sec then they snap into high quality.

 

If you watch the video I linked, you might notice that:

38 seconds: Graphics are fuzzy then crisp up. This is manually opening.

2:50: When script opens the file, all graphics are crisp immediately. Like maybe they are being cached some something.

3:21: Running the script a second time, you can briefly see the graphics are fuzzy. I added a $.sleep(5000) right after opening the file to get a better look - and it stays fuzzy for the whole 5 seconds.

 

I also notice a stopwatch icon on the image statuses, which clears in the video and when manually opening, but sticks when I sleep. Screenshot below.

status.png

 

So, something is happening here. I don't know what or how to trouble shoot, but I have this team of people at my old company that I'm trying to support and I can't figure out what to do next.

 

Any ideas out there?

 

I'm happy to provide sample files if its helpful.

 

 

When exporting the same .indd file in InDesign2021 using the following script, the file size and image quality varies depending on my last manual export.defa...
TOPICS
Import and export, Scripting

Views

142

Likes

translate

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
Adobe Community Professional ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

Can you share a sample of the bad file from the script? Does it happen with any preset—have you tried PDF/X-4?

 

app.pdfExportPresets.itemByName('[PDF/X4:2008]');

Likes

translate

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 ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

Sure thing.  Same effect with [PDF/X-4:2008].

 

I took out the "Close" line at the bottom of the script. After the script ends and InDesign takes over, those blurry images sharpen immediately. If I run the script again, it turns out right.

 

It's almost like there is a multi-threaded component that fetches the images. When I export manually, I wait for a progress bar and it says "Downloading file..." or something like that. It's not present in the video, but I think it is when you open InDesign fresh. It's almost like when running from script this other component doesn't get to do its job and the low-res thumbnails are used.

 

The example of running this experiment is here:

http://www.filedropper.com/samplechapterinddfirst

 

 

Likes

translate

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
Contributor ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

Sounds like the script may be exporting the PDF before the document is really ready. A simple test would be to disable the line where you open the document. Replace it with a line :

 

var theDoc = app.activeDocument;

 

 Then open a document and run the script. That may not be what you want for your workflow but at least you'll know if you have some kind of racing condition. 

Likes

translate

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 ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

After noting the issue with the fuzzy images, I tried adding the following to the script:

    for (var d = theDoc.links.length - 1; d >= 0; d--) {
		var link = theDoc.links[d];
		$.writeln("Checking link "+d+" Status is: "+link.status+" needed: "+link.needed);

    }

 

Annoyingly, this seems to resolve the issue in the single document case.

 

I did not fix the book case.

 

I was able to fix the book case by:

- opening the book

- opening every doc in the book and then doing the link loop above

- export the book

- close the docs

- close the book

 

This did not solve my overall issue in my main codebase though, and of course it feels more like an incantation than a solution.

Likes

translate

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 ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

Correction, stupid mistake, this ABSOLUTELY fixes my workflow....

 

Seems horrible, so I'll dig into things and see if I can make it more elegant. If anyone has any insights...

Likes

translate

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
Adobe Community Professional ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

Missing links certainly would cause the problem. Looks like the path to the test document is on a local volume, are the links on a server, or are they on the same volume? Sounds like the connection to the server is being interupted when the test document is opened via the script.

Likes

translate

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
Adobe Community Professional ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

This would try to update the document links and stop the script with an alert if there are any with Missing status:

 

try {
    var lks = app.documents[0].links.everyItem().update();
}catch(e) {
    alert("This Document Contains Missing Links")
    exit();
} 

 

Likes

translate

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 ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

Thanks for your thoughts on this Rob!

 

In our workflow, it's not that the docs are on a server, its that we use DropBox and not everyone's DropBox is in the same place, so our book-making scripts identify broken links and then go check the obvious locations on the current users computer to see if they can be found.

 

BUT! In this small reproduction, none of the links are broken. They are all valid, and printing the link status as I showed above shows this.

 

Interestingly, this means that the code you provided does not resolve the issue! Using that code instead of my old fashioned for-loop over the links does not seem to cause InDesign to fetch them.

 

I have discovered that if I embed the images instead of keeping them as links then no special code is required to ensure they come out nice. But, in our full workflow, a bunch of these images just have to be links so I seem to be a bit stuck with this clunky workflow.

Likes

translate

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
Adobe Community Professional ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

I don’t have a filedropper account so couldn’t look at the file, but if an .AI file with vectors is missing it would export as an image and not vector fills, which would show up in an AcrobatPro inspection or preflight and seems to be what you are seeing. If the preflight shows an image instead of a vector, obviously ID isn’t getting the link for the export. It is weird that it happens with a script, but not a manual export, which make me wonder if it has something to do with either a PDFExportPreset or PDFExportPreference property?

Likes

translate

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