Copy link to clipboard
Copied
I get a lot of files with tables in them, that are constructed with strokes that are less than 0.25mm thick, is there a way, to select all these thin lines, and then bump them up to 0.25mm?
Try the following
function changeTableBorder(t)
{
for(var i = 0 ; i < t.length; i++)
{
var tt = t[i].cells.everyItem().tables.everyItem().getElements()
if(tt.length)
changeTableBorder(tt)
t[i].bottomBorderStrokeWeight = t[i].leftBorderStrokeWeight = t[i].rightBorderStrokeWeight = t[i].topBorderStrokeWeight = ".25 mm"
}
}
var t = app.documents[0].stories.everyItem().tables.everyItem().getElements()
changeTableBorder(t)
-Manan
In AppleScript it would be something like this. The stroke weight by default is set in points, so .25mm = .709pts and here I’m getting every stroke weight that is less than .8pt and setting it to 1pt. If you are not using OSX it should be easy to translate to JS
tell application id "com.adobe.indesign"
set api to all page items of active document
repeat with x in api
if stroke weight of x is greater than 0 and stroke weight of x is less than .8 then
set stroke weight of x to 1
end...
Hi together,
I'd still prefer a fix on the PDF output.
Reasons:
1. An ExtendScript cannot inspect and change the contents of placed vector graphics.
2. It's next to impossible to catch cases where strokes are showing only partly because they are pasted inside other objects and therefore are clipped.
3. How about strokes on text like Underline, Rule Above, Rule Below etc.pp.?
All this can be treated by PDF preflight.
With Acrobat Pro, with PitStop or pdfToolbox etc.pp.
Below just a special
...Copy link to clipboard
Copied
Try the following
function changeTableBorder(t)
{
for(var i = 0 ; i < t.length; i++)
{
var tt = t[i].cells.everyItem().tables.everyItem().getElements()
if(tt.length)
changeTableBorder(tt)
t[i].bottomBorderStrokeWeight = t[i].leftBorderStrokeWeight = t[i].rightBorderStrokeWeight = t[i].topBorderStrokeWeight = ".25 mm"
}
}
var t = app.documents[0].stories.everyItem().tables.everyItem().getElements()
changeTableBorder(t)
-Manan
Copy link to clipboard
Copied
Sorry my explanation wasn't good.
There are other elements in the designs that are also made up of very thin strokes, that would need to be thickened up.
I'm looking for something that can run through the entire active document, and select all strokes below 0.25mm, and then make them 0.25mm.
Copy link to clipboard
Copied
Rather than doing this, how about making changes to the styles applied on these objects. This would be a quick way to edit everything, make changes in object styles, table styles, cell styles etc and you should be good.
-Manan
Copy link to clipboard
Copied
The problem is that I won't be the author of the files, so I can't be sure how they'll be setup. that's why I'm looking for a broad spectrum solution.
Copy link to clipboard
Copied
In AppleScript it would be something like this. The stroke weight by default is set in points, so .25mm = .709pts and here I’m getting every stroke weight that is less than .8pt and setting it to 1pt. If you are not using OSX it should be easy to translate to JS
tell application id "com.adobe.indesign"
set api to all page items of active document
repeat with x in api
if stroke weight of x is greater than 0 and stroke weight of x is less than .8 then
set stroke weight of x to 1
end if
end repeat
end tell
Copy link to clipboard
Copied
unfortunately, I need it to be platform-independent because we'll be running the script on macOS and Windows-based machines.
Copy link to clipboard
Copied
I think this JS will work for page items. You could combine it with Manan’s JS to get tables.
var minstroke = .8
var newstroke = 1
var api = app.activeDocument.allPageItems;
for(var i=0; i < api.length; i++){
if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke){
api[i].strokeWeight=newstroke;
}
}
Copy link to clipboard
Copied
hmmm, for some reason that's not working for me. No error message, but also no results.
Copy link to clipboard
Copied
Are you sure there is a page item with a stroke that is less than .8 pts? I’m setting the minimum and desired stroke in the two variables at the top. The weight is in points not mm.
Copy link to clipboard
Copied
Hm, hm, hm…
Working with allPageItems is ok unless you are encounting groups where the individual items have different stroke weights.
Or until you encounter graphic objects that do know nothing about stroke weights.
And then it could be that page items are scaled and the effective stroke weight is different from the nominal one.
All in all I think it would be better to do corrections like that after exporting the pages to PDF.
There is the function Fix Hairlines under Print Production of Acrobat Pro. Also a couple of preflight single fix actions you could duplicate and edit to your needs:
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Uwe,
In 99% of cases, you're right. But these are products being uploaded to a custom W2P solution and handling the correction of the files that was doesn't fit the workflow too well. In an ideal world, we'd want to fix all the issues with a file inside of InDesign when our designers are sorting out other issues such as bleed, margins, etc... We want to automate as much as is possible in terms of file preparation as we can. Using InDesign to do this instead of another piece of software like Acrobat or PitStop suits us better.
Copy link to clipboard
Copied
Hi Uwe, I think you are right that a simple script would not catch everything.
With .allPageItems if I add a try statement the script works with groups—it gets all of the items inside of multiple groups, but skips the group. If I group 5 page items and get the length of .allpageitems, it returns 6 not 1. So this works with multiple groups and page items (but not tables).
var minstroke = .8
var newstroke = 1
var api = app.activeDocument.allPageItems;
for(var i=0; i < api.length; i++){
try{
if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke){
api[i].strokeWeight=newstroke;
}
}catch(e){}
}
A mix of items with strokes, some less than .7pt
The result
The result
Copy link to clipboard
Copied
Hi together,
I'd still prefer a fix on the PDF output.
Reasons:
1. An ExtendScript cannot inspect and change the contents of placed vector graphics.
2. It's next to impossible to catch cases where strokes are showing only partly because they are pasted inside other objects and therefore are clipped.
3. How about strokes on text like Underline, Rule Above, Rule Below etc.pp.?
All this can be treated by PDF preflight.
With Acrobat Pro, with PitStop or pdfToolbox etc.pp.
Below just a special case not mentioned above where one item is scaled and another one is not. Effective stroke weight vs nominal stroke weight. Both objects appear to have the same nominal stroke weight of 20 Pt. Effectively both stroke weights are very different.
Why? Because one of the objects was scaled:
How should we handle issues like that by scripting?
Solution: We could "Redefine Scaling as 100%" first and then hunt for nominal stroke weights.
// Added one line to Rob's code to redefine scaling:
var minstroke = .8;
var newstroke = 1;
var api = app.activeDocument.allPageItems;
for(var i=0; i < api.length; i++){
try
{
// First redefine scaling as 100%:
api[i].redefineScaling();
// Then go for the stroke weights:
if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke)
{
api[i].strokeWeight=newstroke;
}
}catch(e){};
};
// Now do tables as well using Manan's code:
// …
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Uwe,
This works well, when i run it as a script by itself, but ,when I add it to my script and run it as a function it keeps giving me an "undefined" error.
//FIX STROKES// INCREASES STROKE WEIGHT OF STROKES BELOW 0.25MM
var button8 = group3.add("button", undefined, undefined, {name: "button9"});
button8.enabled = true;
button8.helpTip = "Finds strokes thinner than 0.25mm, and makes them 0.25mm.";
button8.text = "Fix Strokes";
win.group1.group3.button8.addEventListener("click", function(){
var minstroke = .24;
var newstroke = .25;
var api = app.activeDocument.allPageItems;
for(var i=0; i < api.length; i++){try{api[i].redefineScaling();
if(api[i].strokeWeight>0 && api[i].strokeWeight<minstroke) {api[i].strokeWeight=newstroke;}}catch(e){};};});What am I doing wrong?
Copy link to clipboard
Copied
i figured it out, the name of the button was wrong
Copy link to clipboard
Copied
Hi,
I would be very cautious using redefineScaling() in every situation. The appearance of an object could change if the scaling factor for width and height is different! See my sample below where the top object is the scaled one and the one below is the version where I did redefineScaling():
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
thanks, Uwe, I've got lots of warnings when the before the script is run, that it could be dangerous.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more