How write text to File by Encode UTF-8? - extendscript

My code write Text to file in Adobe Script (.jsx):
var xml= " 小塚ゴシック Pro"
var file = new File(output);
file.open("w");
file.write(xml);
file.close();
But result encode UTF-8 can't display: ϬӋēĖĢĎ Pro
It only can display text " 小塚ゴシック Pro" , if set encode of file is Shift-JIS.
How write text to File by Encode UTF-8?

Try this:
file.encoding = "UTF-8";
And here is a sample, for reference.

Related

How to Convert drawn shapes of HWPFDocument to XSL FO?

I am trying to convert .doc file to PDF,
For this I am initially trying to convert .doc > XSL-FO > PDF.
On Converting the .doc to XSL-FO I am unable to convert the drawn objects such as checkbox,rectangle,square to XSL-FO.
It gets converted as below , which should actually be a box
The conversion code I am using is
HWPFDocumentCore wordDocument = WordToFoUtils.loadDoc(is);
WordToFoConverter wordToFoConverter = new WordToFoConverter(
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
wordToFoConverter.processDocument(wordDocument);
File foFile = new File("D:\\Testing\\testing\\" + "test.fo");
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(out);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new
DOMSource(wordToFoConverter.getDocument()), streamResult);
String result =
org.apache.commons.lang3.StringUtils.normalizeSpace(java.text.Normalizer.normalize(new
String(out.toByteArray(), "UTF-8"), java.text.Normalizer.Form.NFD));
result = URLEncoder.encode(result, "UTF-8");
Further Apache FOP is used to convert the .fo to pdf
The .doc file is as below
and the WordToFoConverter converted the boxes as below
In Plain Text like XML, check boxes usually come from basic symbol fonts.
They are seen / shown as ☐ when unchecked, or ☑ or ☒ when checked.
In any basic text stream it should be relatively easy to use or find and replace them. However beware the encoding especially UTF , thus best copied from a clean set of Zapf Dingbats or Adobe TTF Symbol font.
many have a Unicode description but do test visually that they work after copy and paste from the PDF since the font mapping may not always tally.
8999 ⌧ ⌧ \002327 0x2327 X in a rectangle box
By far the simplest way to use UniCode text is as Rich Text which you can on Windows Command Line (you don't need the lower left dialogue, its just to illustrate export settings) outPort as Port-AbleDocFile using Write.exe which can read TXT and /PrintTo PDF.
Its much simpler than XML where just one character requires:-
<w:rPr>
<w:rFonts w:ascii="Segoe UI Symbol" w:hAnsi="Segoe UI Symbol" w:cs="Segoe UI Symbol" w:eastAsia="Segoe UI Symbol"/>
<w:color w:val="auto"/>
<w:spacing w:val="0"/>
<w:position w:val="0"/>
<w:sz w:val="48"/>
<w:shd w:fill="auto" w:val="clear"/>
<w:vertAlign w:val="subscript"/>
</w:rPr>
<w:t xml:space="preserve">☑</w:t>

How Do I Remove a String that I Added Using svg.appendChild?

I am trying to build a program that will take a user input in a text box and display it. My problem is that when I enter a new input into the text box hat input overlaps the first text. What I want is that original text to be removed and replaced by the new input. The code I am using is below.
function eccentricityChanged() {
let svg = document.getElementById('diagram');
let text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
text.setAttribute('x', 585);
text.setAttribute('y', 275);
text.setAttribute('fill', 'red');
svg.appendChild(text);
svg.selectAll('*').remove();
let txt = document.getElementById("eccentricity").value;
parseFloat('text', txt);
text.innerHTML = txt;

Base64 encoded OpenType font-face using data URI,that dynamicaly input user from computer

The user must upload ttf file,and I want to apply that font file for text,that's why I use base64 format in font-face,but something went wrong,and don't changed text font
https://jsfiddle.net/Meline222/xmeuqwp4/1/
var output = document.getElementById('output');
var f = new FontFace("fingerpaint", `url(data:font/truetype;charset=utf-8;base64,${ret})`);
console.log(dataURL)
f.load().then(function(loaded_face) {
output.style.fontFamily = "fingerpaint";

Generate Arabic content with PDFKit & nodeJS

i'm using pdfkit with nodejs to generate dynamically PDF files. the generation works fine but i have a problem displaying arabic characters even if i setup a font that support arabic.
The letters are rendered correctly, but the words are displayed character by character :(
here's my code
doc = new PDFDocument;
doc.pipe(fs.createWriteStream('output.pdf'));
var str = "فصل الربيع الزهور \n#nature #payesage #fleurs #plantes #vert #espace #temara #rabat #maroc #WeekEnd #balade #instamoment #instalife #instamaroc #photographie #macro #peace";
doc.font('resources/HelveticaNeueLTArabic-Roman.ttf').text(str);
Any thoughts or suggestions will be great.
Use Amiri font , it supports arabic font
const customFontRegular = fs.readFileSync(`./amiri/Amiri-Regular.ttf`);
const customFontBold = fs.readFileSync(`./amiri/Amiri-Bold.ttf`);
pdfDoc.registerFont(`Amiri-Regular`, customFontRegular);
pdfDoc.registerFont(`Amiri-Bold`, customFontBold);
And it can be used as
pdfDoc.font('Amiri-Regular').text("Hello world");

How to: nodejs pdfkit output japanese or chinese

I'm doing my nodejs + expressjs + mongodb project, I need fetch data from mongodb and then write it to pdf file, then send out by expressjs. everything seems fine except that the data is Japanese letter, and the encoding messed-up. I'm using pdfkit for creating pdf file, like this:
var doc = new PDFDocument();
doc.info['Title'] = profile.firstName + " " + profile.lastName;
doc.fillColor('black')
.text(profile.firstName + " " + profile.lastName, {
paragraphGap: 10,
indent: 20,
align: 'justify',
columns: 2
});
then the meta-info of the file and the only line of the content shows: "kf Y’˛" which is should be : "武 大郎"
so, is there any way to set the encoding in pdfkit? or some work around?
PDFKit supports embedding font files in the TrueType (.ttf), TrueType Collection (.ttc), and Datafork TrueType (.dfont) formats. (source: http://pdfkit.org/docs/text.html#fonts)
Download a Japanese Font in TrueType (.ttf) format here http://www.freejapanesefont.com/ipaex-gothic/
# Using a TrueType font (.ttf)
doc.font('fonts/ipaexg.ttf').text('武大郎')

Resources