use of org.jaffa.modules.printing.services.FormPrintEngine.PageDetails in project jaffa-framework by jaffa-projects.
the class FormPrintEnginePdfLib method parseTemplatePages.
/**
* Process the template and do the following
* <ol>
* <li>Throw errors if there is something wrong with the template (in getTemplateName())
* <li>Determine to the total numer of pages in the template
* (The template should have at least one page)
* <li>Populate an array where each template page should have one entry in it.
* Each entry will a PageDetails object, containing a list of fields
* on the page, and a list of repeating entities.
* </ol>
* @throws FormPrintException Thrown if there is an error parsing the template pdf
* @return This returns a List of PageDetails objects which contain data about each page.
* It is assumed that the size of the list indicated the number of pages in
* the template document being used
*/
protected List parseTemplatePages() throws FormPrintException {
if (log.isDebugEnabled())
log.debug("Load the Template - " + getTemplateName());
try {
// Load Template Page, will look in search path relative to bin folder
m_pdfTemplate = m_pdf.open_pdi(getTemplateName(), "", 0);
if (m_pdfTemplate == -1) {
log.error("Loading Base PDF (" + getTemplateName() + ") : " + m_pdf.get_errmsg());
throw new PDFlibException("Error: " + m_pdf.get_errmsg());
}
// Set document properties
m_pdf.set_info("Creator", "From Template " + getTemplateName());
m_pdf.set_info("Author", "AuRA4D");
// Load referenced fonts
m_pdf.load_font(DEFAULT_FONT, "winansi", "");
// Find out how many pages are in the template.
int templatePages = 0;
for (; m_pdf.open_pdi_page(m_pdfTemplate, templatePages + 1, "") != -1; templatePages++) ;
if (log.isDebugEnabled())
log.debug("Template '" + getTemplateName() + "' has " + templatePages + " page(s)");
// Error if the template has no pages!!!
if (templatePages == 0) {
log.error("Template Form " + getTemplateName() + " has no pages!");
throw new EngineProcessingException("Template Form " + getTemplateName() + " has no pages!");
}
ArrayList pageData = new ArrayList();
for (int templatePage = 0; templatePage < templatePages; templatePage++) {
PageDetails page = new PageDetails();
pageData.add(page);
// Now get the names of all the fields on the form.
if (log.isDebugEnabled())
log.debug("Read the field names from template page " + (templatePage + 1) + " of " + templatePages);
// Get total number of Blocks on page
int blockCount = (int) m_pdf.get_pdi_value("vdp/blockcount", m_pdfTemplate, templatePage, 0);
if (log.isDebugEnabled())
log.debug(" Field Count = " + blockCount);
for (int i = 0; i < blockCount; i++) {
String name = m_pdf.get_pdi_parameter("vdp/Blocks[" + i + "]/Name", m_pdfTemplate, templatePage, 0);
if (log.isDebugEnabled())
log.debug(" " + i + ") " + name);
page.fieldList.add(name);
/* @TODO We could do something here like
get_pdi_parameter("vdp/Blocks["+i+"]/SampleData",...
to get a value from PDFlib to use as sample data in the
new DomValue() in template mode...
*/
}
}
// Return the created template data
return pageData;
} catch (PDFlibException e) {
log.error("PDFlibException: " + m_pdf.get_errmsg());
throw new EngineProcessingException(m_pdf.get_errmsg());
}
}
Aggregations