Write to a PDF using JS (pdfform.js) - javascript

I need to make an update to a script that is using pdfform.js in order to take data from html inputs and pass them into a fillable pdf file.
Basically all I need to do is to update the PDF file for the year 2022.
The problem is that my new PDF doesn't have fields where I can write like the old one:
PDF that has fillable inputs:
old pdf
My new PDF:
new pdf
I tried to add fields to my new pdf using Adobe Acrobat but the script is not able to write to them. I don't know exactly how to add the fields in order to have the same reference as the old ones.
<script type = "text/javascript"
src = "pdfform.pdf_js.dist.js" > < /script>
< script > $(document).ready(function() {
$("#descarca-pdf").on("click", function() {
event.preventDefault();
var a = new XMLHttpRequest;
a.open("GET", "Formular-230_Habitat-for-Humanity-Romania-2.pdf", !0), a.responseType = "arraybuffer", a.onload = function() {
if (200 == this.status) {
var a = this.response,
e = {
cnp: [$("#form-cnp").val()],
initiala: [$("#form-initiala").val()],
prenume: [$("#form-prenume").val()],
numar: [$("#form-numar").val()],
nume: [$("#form-nume").val()],
scara: [$("#form-scara").val()],
etaj: [$("#form-etaj").val()],
apartament: [$("#form-apartament").val()],
bloc: [$("#form-bloc").val()],
judet: [$("#form-judet").val()],
localitate: [$("#form-localitate").val()],
codpostal: [$("#form-codpostal").val()],
email: [$("#form-email").val()],
telefon: [$("#form-telefon").val()],
strada: [$("#form-strada").val()],
fax: [$("#form-fax").val()]
},
o = pdfform().transform(a, e),
t = new Blob([o], {
type: "application/pdf"
}),
r = document.createElement("a");
r.href = window.URL.createObjectURL(t), r.download = "Formular_230_Habitat_for_Humanity_Romania.pdf", r.click()
} else on_error("failed to load URL (code: " + this.status + ")")
}, a.send()
})
}); < /script>
Does anyone know any tool that I can use for this?

As far as I can tell you are trying to update a Government Form 230 which used to look like this
And you say you need to update those field for this year HOWEVER the Current Form uses a totally different structure, like this
Here we can see the difference in the two sets of field tags
The XFDF data fields structure as published can be found at
https://static.anaf.ro/static/10/Anaf/Declaratii_R/AplicatiiDec/structura_B230_D230_2020_27032020.pdf
and https://static.anaf.ro/static/10/Anaf/Declaratii_R/AplicatiiDec/structura_B230_D230_2022_12012022.pdf
The forms structure may be used for customised versions with a java library and both years forms have their own personalized .jars for each structure, so it is best to use the official ANAF J Soft available online.
You provide a sample of a modified custom version which has been dumbed down to be part flattened and part not ! thus to my view would not be compatible with your declaration it must match the government XFA format, however it was initially generated or modified using Adobe Forms Library Code, so has working fields in one part area, but they are not XFA structure like the official ANAF version they are declared as "You cannot save data...Please print..." to be simply printed and scanned as if it was a basic paper copy without intelligent fields, which defeats the whole reason for it being a fillable form in the first place. You may just as well use a word doc or any other editor form.
OK on looking through many different modified D230's including yours they seem to be from the same source "Codruţ Popa" who I assume is an ANAF designer so best to get a newer copy from them.

Related

HTML export from Google Doc not maintaining format when pasted into GMail

tl;dr - After exporting a Google Doc as an HTML file and pasting the HTML into a GMail draft it does not contain the formatting from the original Google Doc (other than hyperlinks).
Code snippet:
//copies the doc to HTML format
var htmlExport = "https://docs.google.com/feeds/download/documents/export/Export?id=" + docID + "&exportFormat=html";
var param = {
method: "get",
headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions: true,
};
var htmlExportText = UrlFetchApp.fetch(htmlExport,param).getContentText();
//the variables below (contactEmail & emailSubject) are both taken from a spreadsheet
//copies recent draft body to new email, then updates body of new email to include HTML export
var draftEmailBody = GmailApp.getMessageById(draftEmailID).getBody();
var draftToSend = GmailApp.createDraft(contactEmail,emailSubject,'',{htmlBody: htmlExportText + draftEmailBody}).getMessageId();
Long version:
I am building a mail merge that pulls contact info from a GSheet and uses GDoc as the template for the body. The GDoc has several bits of formatting in it (bold, italics, superscript) that, when exported as an HTML using the script above, appear in the GMail draft devoid of formatting (for some reason it leaves the hyperlinks). For some odd reason it even leaves the images from the doc!
The GMail draft pulled into the body (draftEmailBody) does, however, keep all it's formatting. I can only assume this means I'm doing something wrong by using getContentText but I don't know how else to go about it.
(This is completely separate and I should probably just make another question for this, but I'm here so...)
Separately, I wanted to have the script edit specific fields within the GDoc template, but I have run into 2 issues.
Problem 1 - I have found no way to replace specific text within a GMail draft.
Workaround 1 - I have the script edit the text in a GDoc instead, using repalceText. This, however, leads to:
Problem 2 - Using replaceText in a GDoc requires you to saveAndClose before the script can recognize the change. For some reason I can never get my script to open the GDoc again, despite including openByID in various places of the script!
Workaround 2 - I create a copy of the doc for each contact, replacing the text within that doc, then trash all of the copies on completion so there's no clutter. Quite clunky and slow but it gets the job done.
While it's not the prettiest solution, I found something that helps:
Google Scripts: Generating Email from Docs Loses Formatting

Web application - Write To .txt file with Javascript FileObject.Write

I'm trying to re-purpose some older java script code that I use in order to create a text file via an intranet web app. The following code creates text files that are picked up and processed by a third party application running on the same device...
<script>
function WriteTransferFile(location) {
var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var fileObject = fileSystemObject.CreateTextFile("C:\\transfer\\transfer.txt", true);
fileObject.Write(location);
fileObject.Close();
return location;
}
</script>
<script id="writetransfer">
function writetransfer() {
var Location = document.getElementById('lblCommand');
var Command = Location.innerHTML;
WriteTransferFile(Command);
}
</script>
This works fine for a single text string to be pasted into a text file, but I now need to create a file which takes 4 different fields from the web page and writes them on to consecutive lines. I've played around with the above but any attempt to add a second line of text overwrites the first line instead creating a new one below it. Desired output...
Field 1
Field 2
Field 3
Field 4
Any ideas how I might accomplish this?
I'm aware this probably isn't the sleekest solution, but there are no concerns regarding the suppression of active X security settings as this is for a closed system with access to local intranet only.
Thanks
Steve

Generic link to open latest version of document wiki pages

Hi I am completely new to Sharepoint and wiki pages. I manage to do few changes to wiki pages to have a feel of it. I noticed that every time i create a link to a document if the version changes i need to update the link manually by editing it. Is there any way to automate this process?
Eg: Docv1.0.doc is updated to Docv2.0
Thanks
When you change a document, you don't need to change the file name. SharePoint has versioning built in, so you can keep the file name the same.
That's the only solution actually, don't change the filename. Enable versioning on the library to be able to see previous versions.
Sharepoint site has several links to templates and documents that points to a shared server and these documents can be updated as new versions, so the links to this files needs to be updated automatically, in fact these links need to call some script for dynamically linking them to the latest files. (not sure if a better way of doing this without a script). Here is what I could manage to do, a better and other options to achieve will be appreciated.
I manage to get something working using webparts Content Editor and linking it to a file. Not sure if this the only/best approached for Sharepoint 2007
<script type="text/javascript">
function getLatestFile(){
var myObject;
var recent = "";
myObject = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = myObject.GetFolder("C:\Test");
var fc = new Enumerator(folderObj.files);
for(var objEnum = new Enumerator(FileCollection); !objEnum.atEnd(); objEnum.moveNext()) {
If (recentFile = ""){
recentFile = file;
else if (file.DateLastModified > recentFile.DateLastModified){
recentFile = file;
}
}
}//for loop
alert("recentFile : " + recentFile);
var mylink = document.getElementById("myLink");
mylink.setAttribute("href", urlToFile);
mylink.click();
}
</script>
<P> </P><A id="myLink" onclick="getUrl();"> TestFile1 </A>
Content Type Editor
check above link for more on using content links to use JavaScript and HTML.

Set PDF page layout to "TwoPageLeft" using JavaScript (Acrobat Pro)

I would like to change (or add if it doesn't exist) to a PDF file with multiple pages the setting that will force the PDF to be opened in two page mode (PageLayout : TwoPageLeft for example).
I tried with that kind of JavaScript (given with Enfocus FullSwitch as example) :
if(($error == null) && ($doc != null))
{
try
{
$outfile = $outfolder + '/' + $filename + ".pdf";
$doc.layout = "TwoPageLeft";
$doc.saveAs( {cPath : $outfile, bCopy : true});
$outfiles.push($outfile);
}
catch(theError)
{
$error = theError;
$doc.closeDoc( {bNoSave : true} );
}
}
But it doesn't work as I would like (it will be opened with Acrobat Pro and saved as a new file without including the setting about the layout).
Does anyone can help me to correct that code to let JS open the PDF file, set the layout inside the PDF datas and save it out?
The readable information inside the PDF file should looks like this:
PageLayout/TwoPageLeft/Type/Catalog/ViewerPreferences
For information, I'm using FullSwitch (Enfocus) to handle files in a workflow, with Acrobat Pro, and at this time, it's only saving the file without adding the setting.
I can't find myself the answer over all the Web I searched recently, so I ask…
Thanks in advance!
I think you copied the "this.layout = ..." line out of the Acrobat JavaScript reference documentation, correct?
When you write a JavaScript for Switch to execute (or rather for Switch to instruct Acrobat to execute for you), you should use the "$doc" variable to refer to the document Switch is processing.
So try changing the line:
$this.layout = "TwoColumnLeft";
to
$doc.layout = "TwoColumnLeft";
As you say the rest of the code works and the document is saved without errors I assume the rest of your code is correct. The change proposed here will make the adjustment in the document you're looking for.

Copy a HTML snippet of the page to a clipboard

I am developing web development tools and I'd like to copy of a part of current web page's HTML code to the clipboard using Javascript.
This probably would involve
Getting the piece of HTML in the question using DOM innerHTML
Copying this text to clipboard using Javascript
Is anyone aware of any gotchas here? E.g. related to clipboard handling - when one is not using documentEditable mode do I need to create a hidden where to put the HTML payload for copying?
Also if possible I'd like to make the interaction with WYSIWYG components, like TinyMCE, work so that when one pastes the HTML in the visual edit mode it comes through as formatted HTML instead of plain text.
It is enough if solution works in Chrome and Firefox. Internet Explorer does not need to be supported.
Javascript has no way of adding things to the clipboard. Well at least not any that works cross browser.
There is however a flash solution which works well. http://code.google.com/p/zeroclipboard/
We developed a small Firefox-AddOn to remove special characters (hyphens) when copy/pasting content from the editor. This has been necessary because there is no javascript way to fill anyting into the clipboard. I guess it should be possible to write an extension for Chrome too (googel is your friend here). This seems to be the only way to get what you want from my point of view.
Example:
Here is the necessary code snippet for a FireFox-Addon to remove special characters onCopy
// get Clipboard Object
var clip = Components.classes["#mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
// get Transferable Object
var tr_unicode = new Transferable();
var tr_html = new Transferable();
// read "text/unicode flavors" (the clipboard has several "flavours" (html, plain text, ...))
tr_unicode.addDataFlavor("text/unicode");
tr_html.addDataFlavor("text/html");
clip.getData(tr_unicode, clip.kGlobalClipboard); // Systemclipboard
clip.getData(tr_html, clip.kGlobalClipboard); // Systemclipboard
// generate objects to write the contents into (used for the clipboard)
var unicode = { }, ulen = { }, html = { }, hlen = { };
tr_html.getTransferData("text/html", html, hlen);
tr_unicode.getTransferData("text/unicode", unicode, ulen);
var unicode_obj = unicode.value.QueryInterface(Components.interfaces.nsISupportsString);
var html_obj = html.value.QueryInterface(Components.interfaces.nsISupportsString);
// we remove Softhyphen and another control character here
var re = new RegExp('[\u200b' + String.fromCharCode(173)+ ']','g');
if (unicode_obj && html_obj)
{
var unicode_str = unicode_obj.data.replace(re, '');
var html_str = html_obj.data.replace(re, '');
// Neue Stringkomponenten für unicode und HTML-Content anlegen
var unicode_in = new StringComponent();
unicode_in.data = unicode_str;
var html_in = new StringComponent();
html_in.data = html_str;
// generate new transferable to write the data back to the clipboard
// fill html + unicode flavors
var tr_in = new Transferable();
tr_in.setTransferData("text/html", html_in, html_in.data.length * 2);
tr_in.setTransferData("text/unicode", unicode_in, unicode_in.data.length * 2);
// copy content from transferable back to clipboard
clip.setData(tr_in, null, clip.kGlobalClipboard);
}

Categories