Skip to content
/ toDoc Public

JavaScript library to create create a Word document with Text/HTML

License

Notifications You must be signed in to change notification settings

abs1337/toDoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toDoc.js

JS library to create create a Word document with Text/HTML

Methods :

toDoc.createSection(sectionType, contentType, content, position, align, size, font)

Creates a Header or a Footer Section in the document

Kind: static method of toDoc Access: public

Param Type Description
sectionType string Specifies whether to create content for the header or footer of the document
Accepts : "header" | "footer"
Required
contentType string Defines whether the content is Text or stringified HTML markup
Accepts : "text" | "html"
Required
content string The content that will be inserted in the document
Accepts : stringified text | stringified HTML markup
Required
position number Specifies the content's position in the section
Header/Footer content will be sorted by positon during document generation
Accepts : Numbers > 0
Default position : 0
Optional
align string Specifies the content's alignemnt
Accepts : "left" | "center" | "right" | "justify"
Default alignment : left
Optional
size string Specifies the content's font size
Accepts : CSS font-size
Default size : 12pt/16px/1em
Optional
font string Specifies the content's font family
Accepts : CSS font-family
Default font : Times New Roman
Optional

toDoc.createContent(type, content, position, align, size, font)

Creates a Paragraph or Page in the document

Kind: static method of toDoc Access: public

Param Type Description
type string Defines whether the content is a Paragraph or a Page
Accepts : "paragraph" : Inserts a paragraph in the next line
                "page" : Inserts a paragraph in the next page

Required
content string The content that will be created in the document
Accepts : Text | Stringified HTML
Required
position number Specifies the content's position in the document
Paragraphs and pages will be sorted by positon during document generation
Accepts : Numbers > 0
Default position : 0
Required for pagagraphs and pages
Optional if passing a whole HTML document
align string Specifies the content's alignemnt
Accepts : "left" | "center" | "right" | "justify"
Default alignment : left
Optional
size string Specifies the content's font size
Accepts : CSS font-size
Default size : 12pt/16px/1em
Optional
font string Specifies the content's font family
Accepts : CSS font-family
Default font : Times New Roman
Optional

toDoc.createImage(sectionType, imageURL, position, align, imageWidth, imageHeight)

Creates an image in the Header, Footer or Body of the document

Kind: static method of toDoc Access: public

Param Type Description
sectionType string Defines the section where the image will be created
Accepts : "header" | "footer" | "body"
Required
imageURL string Specifies the image's URL
Accepts : image URL | base64 data URL
Required
position number Specifies the image's position in the document
Images will be sorted by position along with Header/Footer/Paragraphs/Pages during document generation
Accepts : Numbers > 0
Default position : 0
Optional
align string Defines the image's alignemnt
Accepts : "left" | "center" | "right"
Default alignment : left
Optional
imageWidth number Specify a custom width for images
Use only for resizing images
Accepts : Numbers > 0
Optional
imageHeight number Specify a custom height for images
Use only for resizing images
Accepts : Numbers > 0
Optional

toDoc.createPagenumber(sectionType, format, align, size, font)

Inserts a page number in specified section of the document

Kind: static method of toDoc Access: public

Param Type Description
sectionType string Defines the section where the page number is inserted in the document
Accepts : "header" | "footer"
Required
format number Specifies the page number's format
Accepts : 1 : Only page number
                2 : Page X of Y
Default value : 1
Optional
align string Specifies the page number's alignemnt
Accepts : "left" | "center" | "right"
Default alignment : left
Optional
size string Specifies the page number's font size
Accepts : CSS font-size
Default size : 12pt/16px/1em
Optional
font string Specifies the page number's font family
Accepts : CSS font-family
Default font : Times New Roman
Optional

toDoc.createDocument(fileName, params)

Generates and saves a Word document

Default document layout, use this as template for custom parameters:

{
   "pageSizeX": "8.5in",
   "pageSizeY": "11in",
   "marginTop": "1in",
   "marginBottom": "1in",
   "marginLeft": "1in",
   "marginRight": "1in",
   "headerMargin": "0.5in",
   "footerMargin": "0.5in",
}

Kind: static method of toDoc Access: public

Param Type Description
fileName string Specifies the name of the document
Required
params object Define custom parameters for the document's layout
Accepts : JSON Object
Optional

toDoc.clearDocument()

Clears all created document data

Kind: static method of toDoc Access: public

About

JavaScript library to create create a Word document with Text/HTML

Resources

License

Stars

Watchers

Forks

Packages

No packages published