Search in sources :

Example 1 with PDFlibException

use of com.pdflib.PDFlibException in project jaffa-framework by jaffa-projects.

the class FormPrintEnginePdfLib method endPage.

/**
 * Any work to end printing the page
 */
protected void endPage() throws FormPrintException {
    if (log.isDebugEnabled())
        log.debug("Closing Page " + getCurrentPage());
    try {
        // close the current PDF page
        m_pdf.end_page_ext("");
        m_pdf.close_pdi_page(m_pdfPage);
    } catch (PDFlibException e) {
        log.error("PDFlibException: " + m_pdf.get_errmsg());
        throw new EngineProcessingException(m_pdf.get_errmsg());
    }
}
Also used : PDFlibException(com.pdflib.PDFlibException) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException)

Example 2 with PDFlibException

use of com.pdflib.PDFlibException in project jaffa-framework by jaffa-projects.

the class FormPrintEnginePdfLib method endDocument.

/**
 * Any work to end printing the document
 */
protected void endDocument() throws FormPrintException {
    if (log.isDebugEnabled())
        log.debug("Closing Document");
    try {
        // close the document
        m_pdf.end_document("");
        // close PDF Template
        m_pdf.close_pdi(m_pdfTemplate);
    } catch (PDFlibException e) {
        log.error("PDFlibException: " + m_pdf.get_errmsg());
        throw new EngineProcessingException(m_pdf.get_errmsg());
    }
}
Also used : PDFlibException(com.pdflib.PDFlibException) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException)

Example 3 with PDFlibException

use of com.pdflib.PDFlibException in project jaffa-framework by jaffa-projects.

the class FormPrintEnginePdfLib method writeForm.

/**
 * Write the PDF to a specified file
 * @param fileout file handle to use to write out the pdf
 * @throws FormPrintException thrown if any pdf access error occurs
 * @return return the file handle to the file that was written containing
 * the generated PDF document. This will be null if there were any
 * write errors.
 */
public File writeForm(File fileout) throws FormPrintException {
    if (!isProcessed())
        throw new IllegalStateException("The form not been processed yet");
    try {
        if (fileout == null)
            fileout = File.createTempFile("form_", ".pdf");
        OutputStream bos = new FileOutputStream(fileout);
        bos.write(m_pdf.get_buffer());
        bos.flush();
        bos.close();
        if (log.isDebugEnabled())
            log.debug("PDFLib wrote out form " + fileout.getAbsolutePath());
    } catch (IOException e) {
        log.error("Error Reading Uploaded File", e);
        return null;
    } catch (PDFlibException e) {
        log.error("PDFlibException: " + m_pdf.get_errmsg());
        throw new EngineProcessingException(m_pdf.get_errmsg());
    }
    return fileout;
}
Also used : PDFlibException(com.pdflib.PDFlibException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException)

Example 4 with PDFlibException

use of com.pdflib.PDFlibException 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());
    }
}
Also used : PDFlibException(com.pdflib.PDFlibException) ArrayList(java.util.ArrayList) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException) PageDetails(org.jaffa.modules.printing.services.FormPrintEngine.PageDetails)

Example 5 with PDFlibException

use of com.pdflib.PDFlibException in project jaffa-framework by jaffa-projects.

the class FormPrintEnginePdfLib method fillPageFields.

/**
 * This will fill in the page with data,
 * getCurrentPage()Data contains the details of the current page being printed
 */
protected void fillPageFields() throws FormPrintException {
    if (log.isDebugEnabled())
        log.debug("Fill in data for Page " + getCurrentPage() + " based on template page " + getCurrentTemplatePage());
    try {
        for (Iterator i = getCurrentPageData().fieldList.iterator(); i.hasNext(); ) {
            String fieldname = (String) i.next();
            String sampleData = null;
            // @TODO - could store SampleData in PageDetail in a per field HashMap
            // sampleData=getCurrentPageData().sampleData.get(fieldName);
            String data = (new DomValue(fieldname, sampleData)).getValue();
            if (log.isDebugEnabled())
                log.debug("  Set Page " + getCurrentPage() + " [id=" + m_pdfPage + "] " + fieldname + "=" + data);
            if (data != null)
                if (m_pdf.fill_textblock(m_pdfPage, fieldname, data, "embedding encoding=winansi") == -1) {
                    log.warn("Fill Warning on " + fieldname + " = " + m_pdf.get_errmsg());
                }
        }
    } catch (PDFlibException e) {
        log.error("PDFlibException: " + m_pdf.get_errmsg());
        throw new EngineProcessingException(m_pdf.get_errmsg());
    }
}
Also used : PDFlibException(com.pdflib.PDFlibException) Iterator(java.util.Iterator) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException)

Aggregations

PDFlibException (com.pdflib.PDFlibException)7 EngineProcessingException (org.jaffa.modules.printing.services.exceptions.EngineProcessingException)7 com.pdflib.pdflib (com.pdflib.pdflib)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 PageDetails (org.jaffa.modules.printing.services.FormPrintEngine.PageDetails)1