Example usage for com.itextpdf.text.pdf ColumnText showTextAligned

List of usage examples for com.itextpdf.text.pdf ColumnText showTextAligned

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf ColumnText showTextAligned.

Prototype

public static void showTextAligned(final PdfContentByte canvas, final int alignment, final Phrase phrase,
        final float x, final float y, final float rotation) 

Source Link

Document

Shows a line of text.

Usage

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

public static void styleLink(PdfContentByte canvas, String styleClass, String extraInfo, float x, float y,
        EnhancedMap settings, LayerManager layerAware) {
    if (styleClass == null) {
        log.warning("not showing link to styleClass because there is no styleClass");
        return;// w w w.j  av  a  2  s  .c  o m
    }
    Font dbf = DebugHelper.debugFontLink(canvas, settings);
    layerAware.startLayerInGroup(DEBUG, canvas);

    PdfAction act = PdfAction.gotoLocalPage(styleClass, true);
    Chunk c = new Chunk(styleClass + extraInfo, dbf);
    float w = ItextHelper.getTextWidth(c);
    float h = ItextHelper.getTextHeight(c);
    float tan = (float) Math.tan(Math.toRadians(8));
    canvas.setAction(act, x, y, x + w, y + h + tan * w);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(c), x, y, 8);
    canvas.endLayer();
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * when failure information is appended to the report, a header on each page will be printed refering to this
 * information.//w ww.  ja  v  a 2s  . c o m
 *
 * @param template
 * @param x
 * @param y
 */
protected void printFailureHeader(PdfTemplate template, float x, float y) {
    Font f = DebugHelper.debugFontLink(template, getSettings());
    Chunk c = new Chunk(getSettings().getProperty("failures in report, see end of report", "failureheader"), f);
    ColumnText.showTextAligned(template, Element.ALIGN_LEFT, new Phrase(c), x, y, 0);
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * When the setting {@link ReportConstants#PRINTFOOTER} is true prints the total number of pages on each page when
 * the document is closed. Note that/*from   w w w.ja  va  2s  . c om*/
 *
 * @param template
 * @see #PAGEFOOTERSTYLEKEY
 * @param x
 * @param y
 */
protected void printTotalPages(PdfTemplate template, float x, float y)
        throws VectorPrintException, InstantiationException, IllegalAccessException {
    if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) {
        Phrase p = elementProducer.createElement(String.valueOf(lastPage), Phrase.class,
                stylerFactory.getStylers(PAGEFOOTERSTYLEKEY));
        ColumnText.showTextAligned(template, Element.ALIGN_LEFT, p, x, y, 0);
    }
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * prints a failure and / or a debug header when applicable.
 *
 * @see #getTemplateImage(com.itextpdf.text.pdf.PdfTemplate)
 * @param writer// w  w w .j av  a 2s.  co m
 * @param document
 * @throws DocumentException
 * @throws VectorPrintException
 */
private final void renderHeader(PdfWriter writer, Document document)
        throws DocumentException, VectorPrintException {
    if ((!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG))
            || (!failuresHereAfter && !getSettings().getBooleanProperty(false, DEBUG))) {

        writer.getDirectContent().addImage(getTemplateImage(template));

        if (getSettings().getBooleanProperty(false, DEBUG)) {
            ArrayList a = new ArrayList(2);
            a.add(PdfName.TOGGLE);
            a.add(elementProducer.initLayerGroup(DEBUG, writer.getDirectContent()));
            PdfAction act = PdfAction.setOCGstate(a, true);
            Chunk h = new Chunk("toggle debug info",
                    DebugHelper.debugFontLink(writer.getDirectContent(), getSettings())).setAction(act);

            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(h), 10,
                    document.top() - 15, 0);
            Font f = DebugHelper.debugFontLink(writer.getDirectContent(), getSettings());
            //            act = PdfAction.gotoLocalPage("debugpage", true);

            elementProducer.startLayerInGroup(DEBUG, writer.getDirectContent());

            h = new Chunk(getSettings().getProperty("go to debug legend", "debugheader"), f)
                    .setLocalGoto(BaseReportGenerator.DEBUGPAGE);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(h), 10,
                    document.top() - 3, 0);

            writer.getDirectContent().endLayer();

        }
    }
}

From source file:comisionesafis.informes.CintaComisionesPie.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    //Rectangle rect = writer.getBoxSize("art");
    Font font = new Font(Font.FontFamily.COURIER, 10, Font.NORMAL);
    Phrase texto = new Phrase("Pgina " + Integer.toString(document.getPageNumber()), font);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, texto, 300, 30, 0);
}

From source file:comisionesafis.informes.FacturasComisionesAgentesCabecera.java

@Override
public void onStartPage(PdfWriter writer, Document document) {
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("FFF"), 200, 830, 0);
}

From source file:comisionesafis.informes.FacturasComisionesAgentesPie.java

@Override
public void onEndPage(PdfWriter writer, Document document) {

    Font font = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT,
            new Phrase("FacturasAgentes", font), 100, 80, 0);
}

From source file:comisionesafis.informes.LiquidacionComisionesCabecera.java

@Override
public void onStartPage(PdfWriter writer, Document document) {
    Font fontFecha = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT,
            new Phrase("11/04/2014", fontFecha), 500, 830, 0);
    Font fontPaginaNum = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT,
            new Phrase("Pgina " + document.getPageNumber(), fontPaginaNum), 500, 823, 0);
    Font fontLIQ03 = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT,
            new Phrase("LIQ03_0202", fontLIQ03), 500, 816, 0);
    Font fontTitulo = new Font(Font.FontFamily.COURIER, 12, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase("LIQUIDACIN DE COMISIONES: Marzo 2014", fontTitulo), 300, 800, 0);
    Font fontDireccion = new Font(Font.FontFamily.COURIER, 10, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT,
            new Phrase("PELAYO MUTUA DE SEGUROS", fontDireccion), 400, 750, 0);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT,
            new Phrase("CL SANTA ENGRACIA, 67", fontDireccion), 400, 730, 0);
}

From source file:comisionesafis.informes.LiquidacionComisionesPie.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    Font font = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT,
            new Phrase("Ejemplar para el mediador", font), 60, 20, 0);
}

From source file:controller.DownloadCVServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request/*from  w ww  . j a v a 2  s . c o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //protect servlet
    HttpSession session = request.getSession();
    Admin loggedInAdmin = (Admin) session.getAttribute("admin");

    //check if admin is logged in
    if (loggedInAdmin == null) {
        response.sendRedirect("login.jsp");
        return;
    }

    String[] appIDs = request.getParameterValues("download");

    ServletOutputStream sOut = response.getOutputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);

    //prepare fonts
    Font font = FontFactory.getFont("Arial", 10);

    for (String appIDStr : appIDs) {
        int appID = Integer.parseInt(appIDStr);
        Application application = ApplicationDAO.retrieveByAppID(appID);
        Job job = JobDAO.retrieveJobById(application.getJobID());

        ZipEntry entry = new ZipEntry(application.getFullname() + "_CV.pdf");
        zos.putNextEntry(entry);

        String path = System.getenv("OPENSHIFT_DATA_DIR");

        if (path == null) {
            path = getServletContext().getRealPath("/templates/Personal_Particulars_Form.pdf");
        } else {
            path += "Personal_Particulars_Form.pdf";
        }

        try {
            //Prepare PdfStamper
            PdfReader reader = new PdfReader(path);
            PdfStamper stamper = new PdfStamper(reader, zos);
            stamper.setRotateContents(false);
            stamper.getWriter().setCloseStream(false);

            //Get first page
            PdfContentByte canvas = stamper.getOverContent(1);

            //Application ID
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getAppID() + "", font), 110, 555, 0);

            //Date Applied
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getDateApplied(), font), 110, 526, 0);

            //Position Applied
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(job.getPostingTitle(), font), 36,
                    442, 0);

            //Job ID
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getJobID() + "", font), 405, 442, 0);

            //Name
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getFullname(), font),
                    36, 350, 0);

            //Street
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getBlkStreetUnit(), font), 36, 305, 0);

            //Postal Code
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getPostalCode(), font), 377, 305, 0);

            //Nationality
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getNricType(), font),
                    36, 260, 0);

            //NRIC
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getNric(), font), 289,
                    260, 0);

            //DOB
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getDob(), font), 36,
                    215, 0);

            //Gender
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getGender(), font),
                    379, 215, 0);

            //Contact Number
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getContactNo(), font),
                    36, 170, 0);

            //Email Address
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getEmailAddress(), font), 36, 125, 0);

            //Declaration
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("X", font), 50, 80, 0);

            //Generated on
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
            Date date = new Date();
            String today = dateFormat.format(date);
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(today, font), 437, 15, 0);

            stamper.close();
            reader.close();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }

    zos.close();
    response.setContentType("application/zip");
    response.addHeader("Content-Disposition", "attachment; filename=CVs.zip");

    sOut.write(baos.toByteArray());
    sOut.close();
}