I use a JavaScript blob to create an FDF file which opens & fills in a locally stored PDF.
However, the file path to the locally stored PDF contains an accented character (and I am unable to edit the folder name).
This code works when the folder path doesn’t contain an accent and if I open the fdf in Notepad, the default encoding is ANSI. But when the folder path contains an accent, the FDF opens to a message stating the PDF cannot be found. Furthermore, the default encoding in Notepad has changed to UTF-8.
FDF_Text = ''
+ '%FDF-1.2' + "\n"
+ '1 0 obj<</FDF<</F(T:/Échange/MY_PDF.pdf)/Fields 2 0 R>>>>' + "\n"
+ 'endobj' + "\n"
+ '2 0 obj[' + "\n"
+ '<</T(FIELD_NAME)/V(SOME_TEXT)>>' + "\n"
+ ']' + "\n"
+ 'endobj' + "\n"
+ 'trailer' + "\n"
+ '<</Root 1 0 R>>' + "\n"
+ '%%EO'
var blobObject = new Blob([FDF_Text], {type: 'text/css;charset=ANSI'});
window.navigator.msSaveOrOpenBlob(blobObject, 'MY_FDF.fdf');
I have tried
replacing É with E
using String.fromCharCode(201) (the chr value for É)
changing & removing the "type" of the blob itself to several different examples I've found (sorry I didn't keep track of all the different combinations).
Can anyone suggest a different solution?
You can represent the data as binary, just run through the string and fill a binary array
FDF_Text = ''
+ '%FDF-1.2' + "\n"
+ '1 0 obj<</FDF<</F(T:/Échange/MY_PDF.pdf)/Fields 2 0 R>>>>' + "\n"
+ 'endobj' + "\n"
+ '2 0 obj[' + "\n"
+ '<</T(FIELD_NAME)/V(SOME_TEXT)>>' + "\n"
+ ']' + "\n"
+ 'endobj' + "\n"
+ 'trailer' + "\n"
+ '<</Root 1 0 R>>' + "\n"
+ '%%EO'
var uint8 = new Uint8Array(FDF_Text.length);
for (var i = 0; i < uint8.length; i++){
uint8[i] = FDF_Text.charCodeAt(i);
}
var blobObject = new Blob([uint8], {type: 'text/fdf'});
window.navigator.msSaveOrOpenBlob(blobObject, 'MY_FDF.fdf');
Related
I have this meeting appointment i'm trying to send from an .ics file.
This is the data
"BEGIN:VCALENDAR\n" +
"CALSCALE:GREGORIAN\n" +
"METHOD:PUBLISH\n" +
"PRODID:-//Send project Invite//EN\n" +
"VERSION:2.0\n" +
"BEGIN:VEVENT\n" +
"UID:gestionprojetsCalendarInvite\n" +
"DTSTART;VALUE=DATE-TIME:" +
convertDate(startDate) +
"\n" +
"DTEND;VALUE=DATE-TIME:" +
convertDate(endDate) +
"\n" +
"SUMMARY:" +
subject +
"\n" +
"DESCRIPTION:" +
description +
"\n" +
"LOCATION:" +
location +
"\n" +
to.filter(o => o != '').map(o => "ATTENDEE;MAILTO:" + o.email).join("\n") +
"\n" +
"BEGIN:VALARM" +
"\n" +
"TRIGGER:-PT15M" +
"\n" +
"ACTION:DISPLAY" +
"\n" +
"DESCRIPTION:Reminder" +
"\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR";
I want to know why, when I open the .ics file, it's saying "send update" instead of "send".
What I get :
What I want :
I believe it’s because you have static UID for all .ics you generated. "UID:gestionprojetsCalendarInvite\n"
UID aka unique ID, is supposed to uniquely represent a calendar event. When you open an ics file containing duplicated UID, your app (Outlook I guess?) thinks you want to update an existing event, not creating a new one.
Try give it a different UID to see if that solves your problem.
Ref: https://icalendar.org/New-Properties-for-iCalendar-RFC-7986/5-3-uid-property.html
I have a Google Apps Script I am writing that combines a number of reports into a consolidated tab-delimited (TSV) format. However, I am noticing that whenever I write to file, the tabs in my strings are being converted into spaces. Is there some other string literal that I should use?
var content =
data.parameters.time[0] + "\t" +
data.parameters.url[0] + "\t" +
data.parameters.code_name[0] + "\t" +
data.parameters.app_name[0] + "\t" +
data.parameters.version[0] + "\t" +
data.parameters.cookies[0] + "\t" +
data.parameters.lang[0] + "\t" +
data.parameters.platform[0] + "\t" +
data.parameters.user_agent[0] + "\t" +
data.parameters.ex[0];
fld.createFile(makeid() + ".tab", content, ContentService.MimeType.CSV);
Nothing is wrong with using the \t string literal - rather you're using the wrong MimeType enum, from the ContentService. DriveApp methods expect MimeType as a string. Try:
fld.createFile(makeid() + ".tab", content, MimeType.CSV);
Here's a snippet that shows the tab characters survive the file write when the MimeType is properly set:
function myFunction() {
var content =
'time' + "\t" +
'url' + "\t" +
'code_name' + "\t" +
'etcetera';
Logger.log("Initial TSV: " + JSON.stringify(content.split("\t")));
var newFile = DriveApp.createFile("Delete-me" + ".tab", content, MimeType.CSV);
// Check our result, by reading back the file
var blob = newFile.getBlob();
var docContent = blob.getDataAsString()
Logger.log("Result TSV: " + JSON.stringify(docContent.split("\t")));
}
Logs:
[15-04-07 14:53:08:767 EDT] Initial TSV: ["time","url","code_name","etcetera"]
[15-04-07 14:53:09:542 EDT] Result TSV: ["time","url","code_name","etcetera"]
Is there a way to concatenate strings and variable values and new lines, in javascript?
My code:
var variab = "Make:"+ make \n
"Model:" + model \n
"Date taken: " + dateTime \n
"File name:" + fileName ;
variab = variab.replace(/\n/g, '<br>');
document.getElementById('exifid').innerHTML = variab;});
make, model, dateTime and fileName are all variables that return specific values, and I want them to be displayed into a list-like form in my div.
You almost got it:
var variab = "Make:" + make + "\n" +
"Model:" + model + "\n" +
"Date taken: " + dateTime + "\n" +
"File name:" + fileName ;
variab = variab.replace(/\n/g, '<br>');
document.getElementById('exifid').innerHTML = variab;
You can also put each line in an Array and use .join("<br>") to save yourself some typing.
Why use the replace?
var variab = "Make:"+ make + "<br>" +
"Model:" + model + "<br>" +
"Date taken: " + dateTime + "<br>" +
"File name:" + fileName ;
document.getElementById('exifid').innerHTML = variab;
You could stuff each element into an array and then join them.
var array = [
"Make:"+ make,
"Model:" + model,
"Date taken: " + dateTime,
"File name:" + fileName
];
document.getElementById('exifid').innerHTML = array.join('<br/>');
For greater readability, I'd do this:
var variab = [
"Make:" + make,
"Model:" + model,
"Date taken: " + dateTime,
"File name:" + fileName
].join("<br />");
You're also free to include newlines within your fields this way.
Unless your needs grow more complex. In that case, I'd use a templating framework.
It is much, much better to abstract the data into a readable form using a JavaScript object, like below, if possible.
var variab = {
"Make": "Audi",
"Model": "A3",
"Date Taken": 2006,
"File Name": "audia3.doc"
}
var string = "";
for (var detail_type in variab){
var detail_data = variab[detail_type];
string += detail_type + ": " + detail_data + "<br/>"
}
document.getElementById('exifid').innerHTML = variab;
Can anybody help to assign this xml as constant string in javascript. How to assign this xml as constant without any changes?
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">
" +
"<wp:Tile>
" +
"<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
"<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
"<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
"<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
"<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
"<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
"
</wp:Tile> " +
"
</wp:Notification>";
Thanks in advance
JavaScript doesn't have a constant modifier.
Closest you could do is define it with defineProperty() and set writable to false.
Also, your string...
"<wp:Tile>
" +
...won't work as the parser currently doesn't support multiline strings. You'll need to break it up with " + " or use the escape character as the last character.
I'm sending variables to a text box as a concatenated string so I can include multiple variables in on getElementById call.
I need to specify a line break so the address is formatted properly.
document.getElementById("address_box").value =
(title + address + address2 + address3 + address4);
I've already tried \n after the line break and after the variable. and tried changing the concatenation operator to +=.
Fixed: This problem was resolved using;
document.getElementById("address_box").value =
(title + "\n" + address + "\n" + address2 + "\n" + address3 + "\n" + address4);
and changing the textbox from 'input type' to 'textarea'
You can't have multiple lines in a text box, you need a textarea. Then it works with \n between the values.
document.getElementById("address_box").value =
(title + "\n" + address + "\n" + address2 + "\n" + address3 + "\n" + address4);
You need to use \n inside quotes.
document.getElementById("address_box").value = (title + "\n" + address + "\n" + address2 + "\n" + address3 + "\n" + address4)
\n is called a EOL or line-break, \n is a common EOL marker and is commonly refereed to as LF or line-feed, it is a special ASCII character
Using Backtick
Backticks are commonly used for multi-line strings or when you want to interpolate an expression within your string
let title = 'John';
let address = 'address';
let address2 = 'address2222';
let address3 = 'address33333';
let address4 = 'address44444';
document.getElementById("address_box").innerText = `${title}
${address}
${address2}
${address3}
${address4}`;
<div id="address_box">
</div>