Search in sources :

Example 1 with PdfPageEventHelper

use of com.lowagie.text.pdf.PdfPageEventHelper in project mes by qcadoo.

the class DispositionOrderPdfService method buildPdfContent.

@Override
protected void buildPdfContent(PdfWriter writer, Document document, Entity entity, Locale locale) throws DocumentException {
    Entity documentPositionParameters = parameterService.getParameter().getBelongsToField("documentPositionParameters");
    acceptanceOfDocumentBeforePrinting = documentPositionParameters.getBooleanField("acceptanceOfDocumentBeforePrinting");
    class DispositionOrderHeader extends PdfPageEventHelper {

        @Override
        public void onEndPage(PdfWriter writer, Document document) {
            try {
                PdfContentByte cb = writer.getDirectContent();
                cb.saveState();
                float textBase = document.top();
                cb.setColorFill(ColorUtils.getLightColor());
                cb.setColorStroke(ColorUtils.getLightColor());
                cb.beginText();
                cb.setFontAndSize(FontUtils.getDejavu(), 7);
                cb.setTextMatrix(document.left(), textBase + 20);
                cb.showText((translationService.translate(L_PZ, locale) + ": " + DocumentDataProvider.pzLocation(entity)));
                cb.endText();
                cb.stroke();
                cb.restoreState();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    writer.setPageEvent(new DispositionOrderHeader());
    String documentHeader = getDocumentHeader(entity, locale);
    pdfHelper.addDocumentHeader(document, "", documentHeader, "", new Date());
    addHeaderTable(document, entity, locale);
    addPositionsTable(document, entity, locale);
    addPlaceForComments(document, locale);
    addPlaceForSignature(document, locale);
}
Also used : Entity(com.qcadoo.model.api.Entity) PdfWriter(com.lowagie.text.pdf.PdfWriter) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) Document(com.lowagie.text.Document) DocumentException(com.lowagie.text.DocumentException) PdfPageEventHelper(com.lowagie.text.pdf.PdfPageEventHelper) Date(java.util.Date)

Aggregations

Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)1 PdfPageEventHelper (com.lowagie.text.pdf.PdfPageEventHelper)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 Entity (com.qcadoo.model.api.Entity)1 Date (java.util.Date)1