Skip to content

Commit

Permalink
chore: fixed issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
LitixThomas committed Jan 8, 2016
1 parent 23abd73 commit 4563b21
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
38 changes: 31 additions & 7 deletions lib/lx-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ module.exports = function (template) {
document.page = document.pages[index + pageOffset];
}

function isSectionExists(sectionName) {
return !!getValue('options.sections.' + sectionName, undefined);
}

/**
* Get the Dimension for a Section of the current Page, returns empty object if section doesent exits
*
Expand Down Expand Up @@ -929,6 +933,14 @@ module.exports = function (template) {
currentPDFDocument = new PDFDocument(currentPageSettings),
errors = [];

// Error Helper Function
var addError = function (error) {
if (error && error.message) {
console.log(error.message);
errors.push(error.message);
}
};

for (var currentDocumentIndex = 0; currentDocumentIndex <= documentIndex; currentDocumentIndex++) {
var pageAdded = false;

Expand Down Expand Up @@ -991,9 +1003,8 @@ module.exports = function (template) {
sectionInfo = addTextToDocument(currentPDFDocument, sectionName, sectionInfo);

// All content a added to document from this section, then break
if (sectionInfo.error && sectionInfo.error.message) {
console.log(sectionInfo.error.message);
errors.push(sectionInfo.error.message);
if (sectionInfo.error) {
addError(sectionInfo.error);
}

if (sectionInfo.done === true) {
Expand All @@ -1014,11 +1025,20 @@ module.exports = function (template) {
return true;
});

if (sectionInfo.error && sectionInfo.error.message) {
console.log(sectionInfo.error.message);
errors.push(sectionInfo.error.message);
if (sectionInfo.error) {
addError(sectionInfo.error);
}
} else if (entry.image && entry.image.filename) {
if (!isSectionExists(sectionName)) {
addError({message: 'WARNING: Image could not be added. Section "' + sectionName + '" not found on Page ' + contentPageIndex + '.'});
return;
}
} else if (entry.image) {

if (!filestream.existsSync(entry.image.filename) || !filestream.statSync(entry.image.filename).isFile()) {
addError({message: 'ERROR: Image "' + entry.image.filename + '" not found.'});
return;
}

var sectionDimension = getSectionDimension(sectionName),
options = entry.image.options || {};

Expand All @@ -1027,6 +1047,10 @@ module.exports = function (template) {
reqPageBreak = (sectionInfo.topIndex + imgHeight > sectionDimension.height),
imageTop = reqPageBreak ? sectionDimension.top || 0 : null;

if (!sectionInfo.topIndex && !imageTop) {
imageTop = sectionDimension.top;
}

// New Page if picture to big
if (reqPageBreak) {
setPage(currentPDFDocument, ++contentPageIndex);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lx-pdf",
"description": "Litixsoft pdf library for creating pdf files in node.js.",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "https://github.com/litixsoft/lx-pdf",
"author": {
"name": "Litixsoft GmbH",
Expand Down

0 comments on commit 4563b21

Please sign in to comment.