-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting a Two-Columns layout for the pdf generation in the Sections Pages
- Loading branch information
Showing
2 changed files
with
826 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,95 @@ | ||
/**********************/ | ||
/*** PDF generation ***/ | ||
/**********************/ | ||
/** | ||
* Generate the PDF from the current playset | ||
*/ | ||
function generate_pdf() | ||
{ | ||
var jsonPlayset = get_generated_json(); | ||
|
||
var docDefinition = { | ||
content: [ ], | ||
styles: { | ||
sectionHeader: { | ||
fontSize: 22, | ||
bold: true, | ||
marginBottom: 8 | ||
}, | ||
sectionFooter: { | ||
fontSize: 20, | ||
bold: true, | ||
alignment: 'right', | ||
marginTop: 5 | ||
}, | ||
category: { | ||
fontSize: 14, | ||
bold: true, | ||
marginLeft: 10, | ||
marginTop: 3, | ||
marginBottom: 2, | ||
background: '#AAAAAA' | ||
}, | ||
details: { | ||
fontSize: 12, | ||
marginLeft: 22, | ||
marginTop: 1 | ||
} | ||
} | ||
styles: get_pdf_style() | ||
}; | ||
|
||
// Generation of the Sections | ||
for(var iSection = 0; iSection < jsonPlayset.sections.length; iSection++) | ||
{ | ||
var currentSection = jsonPlayset.sections[iSection]; | ||
docDefinition.content.push({ text: currentSection.label + " ...", style: 'sectionHeader' }); | ||
// Chaque catégorie de la page | ||
for (var iCategory = 0; iCategory < currentSection.categories.length; iCategory++) | ||
pdf_add_section(docDefinition.content, currentSection, jsonPlayset.teaser); | ||
} | ||
|
||
pdfMake.createPdf(docDefinition).download(); | ||
} | ||
|
||
function pdf_add_introduction(content, jsonPlayset) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Add the Sections part for the PDF generation | ||
* @param {json} content Json data for pdfmake generation | ||
* @param {json} jsonSection Json data for the Section description | ||
* @param {string} playsetTeaser Teaser (bottom description) for the playset | ||
*/ | ||
function pdf_add_section(content, jsonSection, playsetTeaser) | ||
{ | ||
content.push({ text: jsonSection.label + " ...", style: 'sectionHeader', pageBreak: 'before', pageOrientation: 'landscape' }); | ||
|
||
var columns = [ ]; | ||
var iColumn = 0; | ||
// For each category of the page, add the 6 Details and put it in the right column | ||
for (var iCategory = 0; iCategory < jsonSection.categories.length; iCategory++) | ||
{ | ||
if ((iCategory % 3) == 0) | ||
{ | ||
columns.push([ ]); | ||
iColumn = columns.length - 1; | ||
} | ||
|
||
var currentCategory = jsonSection.categories[iCategory]; | ||
columns[iColumn].push({ text: (iCategory + 1) + " - " + currentCategory.label, style: 'category' } ); | ||
// Chaque élément de la catégorie | ||
for (var iDetail = 0; iDetail < currentCategory.details.length; iDetail++) | ||
{ | ||
var currentCategory = currentSection.categories[iCategory]; | ||
docDefinition.content.push({ text: (iCategory + 1) + " - " + currentCategory.label, style: 'category' } ); | ||
// Chaque élément de la catégorie | ||
for (var iDetail = 0; iDetail < currentCategory.details.length; iDetail++) | ||
{ | ||
var currentDetail = currentCategory.details[iDetail]; | ||
docDefinition.content.push({ text: (iDetail + 1) + " - " + currentDetail.label, style: 'details' }); | ||
} | ||
var currentDetail = currentCategory.details[iDetail]; | ||
columns[iColumn].push({ text: (iDetail + 1) + " - " + currentDetail.label, style: 'details' }); | ||
} | ||
docDefinition.content.push({ text: "... " + jsonPlayset.teaser, style: 'sectionFooter', pageBreak: 'after' }); | ||
} | ||
content.push({ columns: columns }); | ||
content.push({ text: "... " + playsetTeaser, style: 'sectionFooter' }); | ||
} | ||
|
||
pdfMake.createPdf(docDefinition).download(); | ||
/** | ||
* Get the style for the pdfmake generation | ||
* @return {json} Json for pdfmake styling | ||
*/ | ||
function get_pdf_style() | ||
{ | ||
var styles = { | ||
sectionHeader: { | ||
fontSize: 22, | ||
bold: true, | ||
marginBottom: 8 | ||
}, | ||
sectionFooter: { | ||
fontSize: 20, | ||
bold: true, | ||
alignment: 'right', | ||
marginTop: 5 | ||
}, | ||
category: { | ||
fontSize: 14, | ||
bold: true, | ||
marginLeft: 10, | ||
marginTop: 3, | ||
marginBottom: 2, | ||
background: '#AAAAAA' | ||
}, | ||
details: { | ||
fontSize: 12, | ||
marginLeft: 22, | ||
marginTop: 1 | ||
} | ||
}; | ||
return styles; | ||
} |
Oops, something went wrong.