Forum Replies Created
-
AuthorPosts
-
Theunis De Jong
MemberWhat a cool idea for a programmer’s book! Can’t resist — here is a ready-made script! (Enjoy disassembling it. Javascript itself is not very hard, but you got to make it interact just right with InDesign.)
For this to work, you have to assign a label to the text frame(s) that contain the Auto Page Number code on your Master Pages; select the FRAME, then use the Script Label panel (or the Layers panel in newer versions of InDesign) and assign the label “pn” — for ‘page number’. Then run the following script!
It will try to locate the labelled text frames for each page, override them when found, and change all Current Page Number markers into the correct, uppercased, hexadecimal form.
//DESCRIPTION:Change page numbers to Hex! // A Jongware script 13-Oct-2014 app.findTextPreferences = null; app.findTextPreferences.findWhat = "^N"; // Current Page Number doc = app.activeDocument; for (p=0; p<doc.pages.length; p++) { a_page = doc.pages[p]; pagenum = a_page.documentOffset - a_page.appliedSection.pageStart.documentOffset + a_page.appliedSection.pageNumberStart; // who is your master then? m = a_page.appliedMaster; if (m && m.isValid) { for (f=a_page.masterPageItems.length-1; f>=0; f--) { if (a_page.masterPageItems[f].label == 'pn') { // we got one. Override it.. tf = a_page.masterPageItems[f].override (a_page); // .. and change page number code .. pgcode = tf.findText(true); for (i=0; i<pgcode.length; i++) { pgcode[i].contents = (pagenum).toString(16).toUpperCase(); } } } } }Theunis De Jong
MemberScripts cannot *select* pages (that is, make them appear ‘selected’ in the Pages panel).
But “selecting pages” is, on itself, not a useful task. Can you explain WHY you want to have them selected? Do you want to print them, or export, delete, find text, apply a master, or anything else?
Theunis De Jong
MemberBill,
An unfortunate mistake in copying the script into the forum. The backslashes in the line #20
pagerange_nrs = pagerange.match(/^(d+)-(d+)$/);
somehow disappeared; it should have been
pagerange_nrs = pagerange.match(/^(\d+)-(\d+)$/);
I’ve added these, and also did a slightly better check on the page rage. An improved! better! faster! (well, not faster) version can be downloaded from my site:
https://www.jongware.com/binaries/multipagepaste.zipTheunis De Jong
MemberOkay, here is something I made up right now. Try to run it only once per document :P as it attempts to ‘clean up’, but hyperlinks may use so many different objects, it’s hard to get that right.
All it requires are objects marked with one of two object styles: ‘prev’ and ‘next’. The objects may appear on any single page, or reside on a Master Page. Only one level deep! That is, not on a master page based on a master page, which in turn is based on a master page … (and so on) … Keep it simple!
After running the script, master page items are overridden, and all ‘prev’ objects will link to the previous page and ‘next’ to the next one. A ‘prev’ link on the first page will not get linked, and neither will a ‘next’ link on the *last* page of a document.
Here is the code; also downloadable from my site as https://www.jongware.com/binaries/linkprevnextpages.zip
//DESCRIPTION:Make Page To Page Links
// A Jongware script 13-Jun-2014
// Do not modify or distribute without permission.for (p=0; p < app.activeDocument.pages.length; p++)
processPage(app.activeDocument.pages[p]);function processPage (a_page)
{
var obj, link, e;/* search the applied master */
if (a_page.appliedMaster != null)
{
for (obj=0; obj<a_page.appliedMaster.pageItems.length; obj++)
{
if (a_page.appliedMaster.pageItems[obj].appliedObjectStyle)
{
if (a_page.appliedMaster.pageItems[obj].appliedObjectStyle.name == ‘prev’ &&
a_page.documentOffset > 0)
{
try {
a_page.appliedMaster.pageItems[obj].override (a_page);
} catch (e)
{
/* no problem */
}
}
if (a_page.appliedMaster.pageItems[obj].appliedObjectStyle.name == ‘next’ &&
a_page.documentOffset < app.activeDocument.pages.length-1)
{
try {
a_page.appliedMaster.pageItems[obj].override (a_page);
} catch (e)
{
/* no problem */
}
}
}
}
}/* check current objects */
for (obj=0; obj<a_page.pageItems.length; obj++)
{
if (a_page.pageItems[obj].appliedObjectStyle)
{
if (a_page.pageItems[obj].appliedObjectStyle.name == ‘prev’ &&
a_page.documentOffset > 0)
{
removeOldLink (a_page.pageItems[obj]);
link = app.activeDocument.hyperlinks.add (app.activeDocument.hyperlinkPageItemSources.add(a_page.pageItems[obj]),
app.activeDocument.hyperlinkPageDestinations.add(app.activeDocument.pages[a_page.documentOffset-1]) );
link.visible = false;
}
if (a_page.pageItems[obj].appliedObjectStyle.name == ‘next’ &&
a_page.documentOffset < app.activeDocument.pages.length-1)
{
removeOldLink (a_page.pageItems[obj]);
link = app.activeDocument.hyperlinks.add (app.activeDocument.hyperlinkPageItemSources.add(a_page.pageItems[obj]),
app.activeDocument.hyperlinkPageDestinations.add(app.activeDocument.pages[a_page.documentOffset+1]) );
link.visible = false;
}
}
}
}function removeOldLink (pageitem)
{
var i, hpis = app.activeDocument.hyperlinkPageItemSources, l = hpis.length;
for (i=0; i<l; i++)
{
if (hpis[i].sourcePageItem == pageitem)
{
hpis[i].remove();
return;
}
}
}Theunis De Jong
MemberCan you expand a bit on what you need? I don’t know if it already exists in the form and shape you want, but it reminds me of the “Continued on page xx” script I wrote a while ago: https://creativepro.com/how-to-add-automatic-jump-lines.php
Theunis De Jong
MemberAndy, hopefully I am wrong, but will all of your tinkering with word and letterspacing not be rendered completely moot with “justified text, with no hyphenation”?
In my professional opinion, there is NO WAY you can use the phrases ‘nice spacing’, ‘justification’, and ‘no hyphenation’ together in a single sentence. I.e., pick 2 — any 2 — but then forget about the 3rd one.
Theunis De Jong
MemberYeah, we need a new term for either the machine or the person/firm :) “Pressman” could do: “a person who operates or has charge of a printing press” (that is, if the ladies don’t mind — “pressperson” is rather stretching p.c. usage (that is, “Politically Correct” — not the piece of hardware under my desk)).
Funny how they say it’s *your* fault that *they* don’t know what the problem is! I guess their stance is, “we supply this preset to everyone and so you must be causing the error somehow”. Unfortunately, my office has found itself in that position as well: a client delivers a ready-for-press PDF, except that it contains stuff known to cause errors — e.g., ‘grayscale’ images that are included as RGB or CMYK. When asked to change it in their PDF, they don’t know how to change it or flat out claim the file is okay (“because I am seeing grayscale”).
Some gentle to-and-fro communication may do wonders. If your printer is paying attention to your problem, it not only helps *you* but *them* as well. Let them try a sample page with the other settings.
One more thing I’d like to ask. Is the resolution of this one image pretty nigh on correct? Is it not way too large (or small :P), with some ridiculous scaling applied in InDesign? Are there *reasonable* Downscale At values in the printer profile? (I suspect there are.) Is the box “Crop Image Data To Frame” checked or unchecked? (Grasping at straws here, but you never know. I *have* seen a printer error creep in because of that, and toggling it magically fixed it.)
Theunis De Jong
MemberIt is a local printer problem; your being able to print it out correctly shows so.
It is not related to overprinting. Something went wrong in the printers’ RIP software (the program that creates a super-high resolution bitmap of your PDF) while decompressing that particular CMYK image. The usual sequence of “Cyan,Magenta,Yellow,Black” pixels got messed up, and then all went out of sync: the values ended up showing the wrong colors, and parts of your image moved around.
With the right software, your printer can try to apply another kind of compression on this one image, straight inside your PDF. You can also help (a bit): check what image conversion settings the PDF export uses under “Compression”. If it’s “JPEG”, change to “ZIP”; if it says “ZIP” then change it to JPEG and set the quality to “Maximum”.
You don’t have to do anything to your original image! When exporting to PDF, InDesign is going to convert and store your image as it says in the Export dialog, regardless of how you saved it from Photoshop.
Export just this one page — if your printers’ software is not up to specs, flaky, or otherwise contains Bugs of the Unexpected Kind, you might ‘destroy’ other images that were printed correctly before.
Theunis De Jong
MemberIt seems PNG exporting is some kind of left-over or not-(yet?)-fully implemented. The other export formats *do* have various options, but PNG does not. It can’t be coincidental that “PNG” is also missing from the list of exportable formats (at least, it is in my CS4).
Here is a small function I wrote a while ago that implements a PNG export. Since you cannot export an entire *page*, you have to target a *group* instead. So first thing the script does is over-riding all master page items on each page, so they can be included; then it adds all items on the page to a new group, and finally exports *that*.
So it changes your document — Save before running and Do Not “Save” it afterwards!
This script exports all pages in your document but can easily be rewritten to export a certain page range only.
for (pg=0; pg<app.activeDocument.pages.length; pg++)
{
page = app.activeDocument.pages[pg];
for (mas=0; mas < page.appliedMaster.pageItems.length; mas++)
try {
page.appliedMaster.pageItems[mas].override(app.activeDocument.pages[pg]);
} catch (a_bah) { }g = page.groups.add(page.pageItems);
g.exportFile(ExportFormat.PNG_FORMAT, File(Folder.myDocuments.fsName+”/”+(page.name)+”.png”));
}Theunis De Jong
MemberYou can always try my little script IDentify.jsx before attempting to open a file:
https://forums.adobe.com/thread/934429
Up until now it correctly identifies the creator of files, right until CC. I have not checked if it works for sub-versions beyond “9.0”, the point where Adobe introduced single digit updates on a regular base.
Theunis De Jong
MemberActually you don’t need a lookahead for the ‘position markers’ $ and \Z. Stuart mentions he tried some variations, but maybe he overlooked the simplest possible case:
rZ
— that is, the return occurs *before* the end of story.
Theunis De Jong
Member> I noticed Corbel has five choices for the each number in the glyphs palette and one works great.
Well, two of those are superior and inferior numbers — I sure hope it’s not one of these that “work great” :)
The other three are identified (just hold the mouse still on one of the numbers) as “Tabular Figures (tnum) + Lining Figures (lnum)”, “Tabular Figures (tnum)”, and “Lining Figures (lnum)”. That means you can access the different styles as OpenType Features.
In your Paragraph Style Options, go to the OpenType Features tab. The bottom of that dialog contains “Figure Style” — use the drop down list to select the particular style you want.
Theunis De Jong
MemberWell, it should work right out of the box (providing you have some hyperlinks in your document).
What sort of database are your Abbreviations/Hyperlinks in? If you can export them to a simple text list, you can have the script look them up automatically. That would be something like (warning: making this up as I type):
// add this list at the very top of the script;
// take note to close all the [ that you open ], nested as shown
var abbrList = [ [“AAA”, “https://creativepro.com”%5D,
[“AAB”, “https://www.adobe.com”%5D,
[“XYZ”, “https://forums.adobe.com/community/indesign?view=discussions”%5D,
[“MIT”, “https://jongware.mit.edu/idcs6js/index.html” ] ]; // etc. — full hyperlinks!and then instead of inserting a plain fixed text
r.texts[0].contents = “AAA”;
replace it with a loop over the abbrList array, checking if the link is in there and inserting the proper abbreviation if found:
r.parentStory.contents = “???”;
for (j=0; j<abbrList.length; j++)
if (abbrList[j][1] == links[i].destination.destinationURL)
{
r.parentStory.contents = abbrList[j][0];
break;
}Also, add this line under the comment line:
// set some Anchored Object propertiesr.anchoredObjectSettings.anchorPoint = AnchorPoint.BOTTOM_RIGHT_ANCHOR;
— I found the position from the left margin and baseline depends on your current *default* settings, and they happened to be correct for my initial test.
Theunis De Jong
MemberThis sure needed a round trip through InDesign’s Document Object Model — hyperlinks, anchored objects, text frames .. the lot! But I think the following will get you started. The following script scans your document for hyperlinks, and creates a new anchored frame to its left on a fixed position. It fills the frame with a placeholder text — how and where would your abbreviations come from? That part wasn’t entirely clear, but perhaps you can fiddle with my script and add it where you wish.
The script assumes the following:
1. An Object Style called “RedBorder”. Please note: make sure this object style does *NOT* define any Anchored Object settings! These will override the ones that I put in my script (as I only found out after some serious head scratching).
2. A Paragraph Style called “RedCaps”.
3. Some texts marked with a hyperlink to an external URL.
4. The baseline of the new box will be aligned to the baseline of your text. I moved it down 1mm, but how much it needs to have the *text* inside it aligned depends (I think) on the font and size of the paragraph style RedCaps. I suppose it’s easiest to run the script once, move one of the anchored objects up or down until it aligns correctly, note down the vertical offset, and then discard your new document and run the script again, with the correct value inserted. I don’t think this step can be automated.First off, let me show a *short* sample script to illustrate how Hyperlinks work in InDesign. A Hyperlink is an abstract item, only visible in the Hyperlinks palette, which has two important properties: where it *points to* (which can be anything: to another page, to a text location, or — the one you want — to an external URL), and what the *link* item is in your document (this can be a Cross Reference, any clickable Page Item such as a button, or some plain text). The following script changes the font of all of your *text* links that point to *URLs* to something else:
links = app.activeDocument.hyperlinks;
for (i=0; i<links.length; i++)
{
if (links[i].source instanceof HyperlinkTextSource &&
links[i].destination instanceof HyperlinkURLDestination)
links[i].source.sourceText.appliedFont = “Comic Sans”;
}You see it needs to check the *type* of both source and destination, because not every ‘clickable’ item may have a font, and not every link may point to an URL.
The *sourceText* is where I am going to insert a new anchored object; then I set some properties, so your text can be inserted and the anchor is moved into position, and finally, the same *destination* is applied to this new object — not to its text as you requested, but — hey! — to the entire rectangle. Instant Hyperlink Buttons ahoy!
Here is the full script; after copying, take care to check it for unexpected modifications, such as curly quotes (they should all be straight) and en-dashes (these probably should be two hyphens). Also, make sure the object and paragraph styles exist before running (it won’t work otherwise). Hope it’s enough to get you started!
// Get list of links — the following forces a COPY of ID’s internal list
// That is important, because we’re going to ADD a lot of them :-/
links = app.activeDocument.hyperlinks.everyItem().getElements();for (i=0; i<links.length; i++)
{
if (links[i].source instanceof HyperlinkTextSource &&
links[i].destination instanceof HyperlinkURLDestination)
{
r = links[i].source.sourceText.insertionPoints[0].textFrames.add();
// initially inline; convert to Anchored Object
r.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;// set some Anchored Object properties
r.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;
r.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE;
r.anchoredObjectSettings.pinPosition = false;
r.anchoredObjectSettings.anchorXoffset = “5mm”;
r.anchoredObjectSettings.anchorYoffset = “1mm”; // <- Find proper value!// apply object style. Make sure it *sets* no Anchored Style!
r.appliedObjectStyle = app.activeDocument.objectStyles.item(“RedBorder”);// write some text into it
r.texts[0].contents = “AAA”;
r.texts[0].appliedParagraphStyle = “RedCaps”;
// make sure it has some space left and right
r.textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;
r.textFramePreferences.insetSpacing = [“1mm”, “3mm”,”1mm”,”3mm”];
// ..first make it *way* too large (hopefully)
r.geometricBounds = [0,0, “10mm”,”100mm”];
// .. then resize to fit
r.fit (FitOptions.FRAME_TO_CONTENT);// make the entire rectangle a hyperlink, pointing to the same
// URL as the original one
newlink = app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkPageItemSources.add(r), links[i].destination);
newlink.visible = false;
}
} -
AuthorPosts
