Copy link to clipboard
Copied
Hi,
I'm using InDesign to create a memory book. Many people get one page each to fill with content. As past projects have shown, people are really keen about using Emojis, which I'd like to support. But I just can't get Emojis into InDesign via Data Merge, only when I copy&paste them manually.
My workflow so far:
This works. But as for the data merge part:
But the problem is: No matter how I format it and how I convert it, I won't get Emojis into the InDesign document. Only one of the two cases happens:
Does anyone know a solution? What am I overlooking? Is there any other character encoding than UTF16 that InDesign supports?
Ha, I have found a solution!
How to get line breaks and Emojis into InDesign via Data Merge
InDesign doesn't support line breaks or Emojis from data sources that you import via Data Merge. With this workaround, you can encode any special characters in your spreadsheet and decode them in InDesign again.
In your spreadsheet:
Copy link to clipboard
Copied
Ha, I have found a solution!
How to get line breaks and Emojis into InDesign via Data Merge
InDesign doesn't support line breaks or Emojis from data sources that you import via Data Merge. With this workaround, you can encode any special characters in your spreadsheet and decode them in InDesign again.
In your spreadsheet:
In InDesign:
Open a text editor, copy the below script into it, and save it as URL-decode.jsx
Move the script file to your scripts directory - on Windows this is: %AppData%\Adobe\InDesign\Version 14.0\en_GB\Scripts\Scripts Panel
(you can type %AppData% into the Windows search box, press enter and navigate to the folder from there)
URL-decode.jsx:
//DESCRIPTION:Decodes and replaces all URL-encoded strings in the active InDesign document.
//AUTHOR:Johannes Eichberger
//
//Example:
// This%20is%20URL-encoded%20text!
// This is URL-encoded text!
//
//How to use:
// Open an InDesign document with URL-encoded texts.
// Run the script.
// It replaces every (!) text in every text frame.
//
//Limitations:
// Works with text frames that contain text only. Any non-text
// content, such as tables and linked images, will get lost.
// If an encoded text exceeds its container (overset text),
// only the visible part will be replaced. You can run the script
// multiple times to solve this issue.
//
//When to use:
// InDesign's Data Merge has only poor support of character encodings.
// If you want to feed InDesign with Emojis, you can encode them in the
// spreadsheet via =ENCODEURL() and decode them using this script
// after running Data Merge.
//
#target indesign;
function main() {
try {
var myDocument = app.activeDocument;
var myTextFrames = myDocument.textFrames.everyItem();
var myContents = myTextFrames.contents;
for (var i=0; i<myContents.length; i++) {
var thisTextFrame = myDocument.textFrames.item(i);
var myDecoded = decodeURI(myContents[i]);
thisTextFrame.contents = myDecoded;
}
if (i==0) {
throw "No texts found!";
}
alert("Texts have been replaced.");
}
catch(err) {
alert(err);
}
}
main();
Copy link to clipboard
Copied
Hi joheiat ,
FWIW: be aware that your script could change the contents of text frames.
Before, text frame with one anchored object, the yellow rectangle:
After running URL-decode.jsx:
Also a problem. Tables. You'll remove tables.
Before:
After running URL-decode.jsx:
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe / Laubender,
Yes, you're right. The script is on a very basic level and only works for text frames which contain nothing else but text. I might think about extending it to keep additional content placed in text frames too. Thanks for pointing me to this!
If anyone has a demand for this, please leave a reply to nudge me.
Also, feel free to extend the script.
Regards,
Johannes
Copy link to clipboard
Copied
Hi Joheiat,
I'm actually in need of exactly this — a better process for data-merging with emojis. However, when I run your script to decode the url-encoded text, I get an error message. Is the script you posted here accurate and up-to-date? Thanks!
Steven
Copy link to clipboard
Copied
Hi Steven,
So sorry, I happened to see your reply only now. Are you still in the need of this? I tested my script again with the current version of InDesign with a minimalistic test file and it still works. Which error message do you / did you see?
Regards,
Johannes
Copy link to clipboard
Copied
Hi Joheiat,
For me, the script operated as intended. However, I occasionally have content that is emoji-heavy. It then displays the error URL-Error: Bad or Invalid URL.
Is there a way to solve this? Thanks!
Niven
Copy link to clipboard
Copied
Hi Niven,
I'm not sure what happened in your case, but as you state it happens only occasionally, it might be a cropped URL. Is there probably a percent sign in your encoded string which is NOT followed by two hex-numbers? Your error message ends with a % sign. Probably this is just cropped?
My script is very limited, it decodes only the visible text in a frame. Surely a script geek can find out how to decode the full text instead. What you could try as a work-around is: add another text frame outside the printing area, and connect the original frame to let overset text flow into that new frame. My assumption is that this would make overset text less likely to get cropped just after a % sign.
Regards,
Johannes
Copy link to clipboard
Copied
Hi Joheiat,
My text box was cropped. It showed the same error after extending the text-frame. The script used to work just fine but sometimes content loaded with emojis results in this error.
Are you aware of any resources I could use to upgrade the script?
Niven
Copy link to clipboard
Copied
Hi Niven,
Could you share a concrete example of a text that doesn't work, especially in its encoded form with the percent signs?
As for scripting resources, I would start with reading the documentation here, but depending on your scripting/programming experiences, this might be time-consuming. The issue in my script is probably that I'm accessing the text frame content via .contents which obviously only allows editing of the visible part. One would probably need to find methods or properties instead which allow access to the whole text.
Good Luck,
Johannes
Copy link to clipboard
Copied
Hello Joheiat,
I've attached two files to illustrate the error that occurred in my case because I was unable to express it in words.
The URL-Decoding Script is applied to one file, but not the other.
The script operated fine up until Page 19, at which point the previously mentioned issue occurred.
Since I am aware that this is asking for too much, I sincerely appreciate your time.
Regards,
Niven
Copy link to clipboard
Copied
Hi Niven,
I see in your first file (Script not applied) on page 19 that there is a break within an encoded sequence. One special character encodes to %A4, but is split into two text frames, the first one ending with % and the second one starting with A4. The script reads and writes textFrames.item(i).content which is obviously only the visible content, therefore this is a limitation (besides many others, such as ignoring mixed styles within a text frame). The first frame only contains a % sign, not followed by two hex-digits, therefore it throws an error.
To fix this, the script would need adaption to access the actual text of the frame instead. You're right, this is too much to demand here, however I'm leaving this here in case someone more experienced wants to update the script. For the time being, you can get into scripting yourself, or you can deal with work-arounds (such as disabling hyphenation), or you can go the tedious path and copy&paste all texts manually.
Let me also suggest to vote for these feature requests, which would make some of the datamerge issues easier to overcome:
Best regards,
Johannes
Copy link to clipboard
Copied
Hi Johannes,
the script code in your correct answer was damaged last year when this thread was moved to the new InDesign forum.
That could be one cause of an error message. Look into the for loop. At first glance I see that the iterator [i] was removed on myContents. Best correct your answer and post the original code again.
Thanks,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Uwe,
Thanks for the hint. I've updated my answer.
Best,
Johannes
Copy link to clipboard
Copied
Hello Joheiat,
Since you allready solved the problem how to convert image url to file names: could you share the method/script you used to do so?
Thanks!
Regards,
Pascal
Copy link to clipboard
Copied
Hello Pascal,
Do you mean the Google spreadsheet script that I used to get the file names of images that were uploaded via Google forms? Let me take a look, if I find it I will post it here.
Johannes
Copy link to clipboard
Copied
I'm sorry, I've lost access to the file where I solved this problem. I used a Google Apps script which I had to run manually. If I recall correctly, it did pretty much the same as the one in this StackOverflow answer (check all URLs in one column, and output the file names in another column):
https://stackoverflow.com/a/51398404
Hope this helps you.
Johannes
Copy link to clipboard
Copied
No problem. Thanks for the reply! I will look into it.
Cheers