You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
newDocxGen()ThisfunctionreturnsanewDocxGenObjectnewDocxGen(content[,Tags,options])
content:
Type: stringThedocxtemplateyouwanttoloadasplaintext
Tags:
Type: Object{tag_name:tag_replacement}[{}]Objectcontainingforeachtag_name,thereplacementforthistag.Forexample,ifyouwanttoreplacefirstNamebyDavid,yourObjectwillbe: {"firstName":"David"}
options: object
parser:
Type: functionAcustomparsertouse.Seeangular.jslikeparsingintelligentTagging:
Type: boolean[false]IfintelligentTaggingisnotsettotrue,whenusingrecursivetags({#tag}and{/tag}),thesystemwillcopypastewhatisbetweenthestarttagandtheendtag,thiscouldbasicallycorruptthefilesifrecursivetagsareusedinsidetables.IfintelligentTaggingissettotrue,andwhenusingrecursivetagsinsidetables,thewholecolumnwillbecopypasted.qrCode:
Type: boolean[false]IfqrCodeissettotrue,DocxGenwilllookatalltheimagestofindaQr-Code.IftheQr-codematchestoaURL,thisURLwillbeloadedbyajax(Beawarethattheserveryouwanttoaccessneedstoallowyourrequest,oritwon't work. http://stackoverflow.com/questions/9310112/why-am-i-seeing-an-origin-is-not-allowed-by-access-control-allow-origin-error ) **Important**: the qrCode functionality only works for PNG, I don'tthinkIwillenablethisforotherfileformatsinthenearfuture.localImageCreatorType: function(arg,callback)[functionthatreturnsanarrow]ThefunctionhastobecustomizedonlyifyouwanttousetheqrCodeoptions(**qrCode=true**).Whentheqrcodetextstartswith**gen:**,theimageisnotgoingtobeloadedbyurlbutDocxGencallslocalImageCreatorwith**arg**=fullTextdecoded.ThecallbackneedstobecalledwiththeimageData:**callback(result)**,inplain/txtformat(ifyouwanttocreateitfromaData-URI,youcanuseJSZipBase64.decode(data)todecodeaData-URItoplain/txt)ThedefaultlocalImageCreatorreturnsaredarrow,nomatterwhattheargumentsare:
@localImageCreator=(arg,callback)->result=JSZipBase64.decode("iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACXSURBVDhPtY7BDYAwDAMZhCf7b8YMxeCoatOQJhWc/KGxT2zlCyaWcz8Y+X7Bs1TFVJSwIHIYyFkQufWIRVX9cNJyW1QpEo4rixaEe7JuQagAUctb7ZFYFh5MVJPBe84CVBnB42//YsZRgKjFDBVg3cI9WbRwXLktQJX8cNIiFhM1ZuTWk7PIYSBhkVcLzwIiCjCxhCjlAkBqYnqFoQQ2AAAAAElFTkSuQmCC")[DefaultImage](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACXSURBVDhPtY7BDYAwDAMZhCf7b8YMxeCoatOQJhWc/KGxT2zlCyaWcz8Y+X7Bs1TFVJSwIHIYyFkQufWIRVX9cNJyW1QpEo4rixaEe7JuQagAUctb7ZFYFh5MVJPBe84CVBnB42//YsZRgKjFDBVg3cI9WbRwXLktQJX8cNIiFhM1ZuTWk7PIYSBhkVcLzwIiCjCxhCjlAkBqYnqFoQQ2AAAAAElFTkSuQmCC)qrFinishedCallBack:
Type: function()[functionthatconsole.log(ready)]ThisfunctioniscalledifyouspecifyqrCodeargumenttotrueinthisconstructor,andwillbecalledwhenallqrCodeshavebeenreplaced(becausetheqrCodereplacingfunctionsare**async**)
Docxgen methods
load(content)
content:
Type: stringThedocxtemplateyouwanttoloadasplaintextloadFromFile(path)path
Type: stringLoadsadocxfromafilepathsetTags(Tags)
Tags:
Type: Object{tag_name:tag_replacement}Objectcontainingforeachtag_name,thereplacementforthistag.Forexample,ifyouwanttoreplacefirstNamebyDavid,yourObjectwillbe: {"firstName":"David"}applyTags([Tags])
Tags:
Type: Object{tag_name:tag_replacement}sameassetTags
Default:this.TagsThisfunctionreplacesalltemplatevariablesbytheirvaluesoutput([options])options: object[{}]
name:
Type:string["output.docx"]Thenameofthefilethatwillbeoutputed(doesntworkinthebrowserbecauseofdataUridownload)
callback:
Type:functionFunctionthatiscalledwithoutargumentswhentheoutputisdone.IsusedonlyinNode(becauseinthebrowser,theoperationissynchronous)download:
Type:boolean[true]Ifdownloadistrue,filewillbedownloadedautomaticallywithdataURI.returnstheoutputfile.type:
Type:string["base64"] The type of zip to return. The possible values are : (same as in http://stuk.github.io/jszip/ @generate) base64 (default) : the result will be a string, the binary in a base64 form. string : the result will be a string in "binary" form, 1 byte per char. uint8array : the result will be a Uint8Array containing the zip. This requires a compatible browser. arraybuffer : the result will be a ArrayBuffer containing the zip. This requires a compatible browser. blob : the result will be a Blob containing the zip. This requires a compatible browser. nodebuffer : the result will be a nodejs Buffer containing the zip. This requires nodejs. This function creates the docx file and downloads it on the user's computer. The name of the file is download.docx for Chrome, and some akward file names for Firefox: VEeTHCfS.docx.part.docx, and can't be changed because it is handled by the browser. For more informations about how to solve this problem, see the **Filename Problems** section on [http://stuk.github.io/jszip/](http://stuk.github.io/jszip/) Note: All browsers don't support the download of big files with Data URI, so you **should** use the `download` method for files bigger than 100kB data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACXSURBVDhPtY7BDYAwDAMZhCf7b8YMxeCoatOQJhWc/KGxT2zlCyaWcz8Y+X7Bs1TFVJSwIHIYyFkQufWIRVX9cNJyW1QpEo4rixaEe7JuQagAUctb7ZFYFh5MVJPBe84CVBnB42//YsZRgKjFDBVg3cI9WbRwXLktQJX8cNIiFhM1ZuTWk7PIYSBhkVcLzwIiCjCxhCjlAkBqYnqFoQQ2AAAAAElFTkSuQmCCdownload(swfpath,imgpath[,fileName]) swfpath Type:string Path to the swfobject.js in downloadify imgpath Type:string Path to the image of the download button [fileName] Type:string Default:"default.docx" Name of the file you would like the user to download. This requires to include Downloadify.js, that needs flash version 10. Have a look at the *output* function if you don't want to depend on it. This function has the advantage that it works regardless of the file sizegetImageList() this gets all images that have one of the following extension: 'gif','jpeg','jpg','emf','png' Return format: Array of Object: [{path:string,files:ZipFile Object}] You should'nt call this method before calling **applyTags()**, because applyTags can modify the images or their path when replacing images with other (particularly when qrCode is set to true, which is not the default case). You can call this method after **applyTags()** without any problemssetImage(path,imgData) path Type:"String" Path of the image, given by getImageList() imgData Type:"String" imgData in txt/plain This sets the image given by a path and an imgData in txt/plain. You should'nt call this method before calling **applyTags()**, because applyTags can modify the images or their path when replacing images with other (particularly when qrCode is set to true, which is not the default case). You can call this method after **applyTags()** without any problemsgetFullText:([path]) path Type:"String" Default:"word/document.xml" This argument determines from which document you want to get the text. The main document is called word/document.xml, but they are other documents: "word/header1.xml","word/footer1.xml"
@returns
Type:"String"ThestringcontainingallthetextfromthedocumentThismethodgetsonlythetextofagivendocument(nottheformatting)getTags()Thisfunctionreturnsthetemplatevariablescontainedintheopeneddocument.Forexampleifthecontentofthedocument.xmlisthefollowing:
{name}{first_name}{phone}Thefunctionwillreturn:
[{filename:"document.xml",vars:
{name:true,first_name:true,phone:true}}]Ifthecontentcontains tagLoops:
{title}{#customer}{name}{phone}{/customer}
Thefunctionwillreturn:
[{filename:"document.xml",vars:
{title:true,customer:
{name:true,phone:true}}}]