diff --git a/README.md b/README.md index c8d5bd0..00e8bde 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,35 @@ Supported image formats: .PNG and .JPEG. } } ``` +#### Image or Multiple Images +You can use a image or multiple images by specifying the position of the image in template. Perfect for letter templates. +Supported image formats: .PNG and .JPEG. + +```js +{ + "multipleImage": [{ + "filename": "./image/Image1.png", + "imageformat": { + "fit": [50, 50] + }, + "position": { + "left": "50", + "top": "50" + } + }, + { + "filename": "./image/Image2.png", + "imageformat": { + "fit": [50, 50] + }, + "position": { + "left": "110", + "top": "50" + } + } + ] +} +``` #### Font and Format @@ -391,4 +420,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/lib/lx-pdf.js b/lib/lx-pdf.js index 61725b9..76a1bc4 100644 --- a/lib/lx-pdf.js +++ b/lib/lx-pdf.js @@ -187,6 +187,7 @@ module.exports = function (template) { */ function setUpPage(document, layout) { var pageBackgroundOptions = getValue('options.background'), + multipleImage = getValue('options.multipleImage'), pageSections = getValue('options.sections', {}), pageHeader = getValue('header'), pageFooter = getValue('footer'), @@ -197,7 +198,19 @@ module.exports = function (template) { if (pageBackgroundOptions && getKeyExist('filename', pageBackgroundOptions)) { document.image(getValue('filename', undefined, pageBackgroundOptions), 0, 0, getValue('imageformat', {}, pageBackgroundOptions)); } + + + // sets the multiple images + if (multipleImage && multipleImage.length != 0) { + for(var p = 0; p < multipleImage.length; p++) { + if(getKeyExist('filename', multipleImage[p])) { + document.image(getValue('filename', undefined, multipleImage[p]), getValue('position.left', 0, multipleImage[p]), getValue('position.top', 0, multipleImage[p]), getValue('imageformat', {}, multipleImage[p])); + } + } + } + + // render header if (showHeader === true && pageHeader && pageHeader.data) { var pageHeaderHeight = getValue('format.height', 60, pageHeader), @@ -1233,4 +1246,4 @@ module.exports = function (template) { pub.loadTemplate(template); return pub; -}; \ No newline at end of file +};