Example usage for com.itextpdf.text Image setAlt

List of usage examples for com.itextpdf.text Image setAlt

Introduction

In this page you can find the example usage for com.itextpdf.text Image setAlt.

Prototype


public void setAlt(final String alt) 

Source Link

Document

Sets the alternative information for the image.

Usage

From source file:org.opentox.io.publishable.PDFObject.java

License:Open Source License

public void publish(YaqpIOStream stream) throws YaqpException {
    if (stream == null) {
        throw new NullPointerException("Cannot public pdf to a null output stream");
    }/*from w  w w . j  a  va  2  s  . c o  m*/
    try {
        Document doc = new Document();
        try {
            PdfWriter.getInstance(doc, (OutputStream) stream.getStream());
        } catch (ClassCastException ex) {
            throw new ClassCastException("The stream you provided is not a valid output stream");
        }
        doc.open();
        doc.addAuthor(pdfAuthor);
        doc.addCreationDate();
        doc.addProducer();
        doc.addSubject(subject);
        doc.addCreator(pdfCreator);
        doc.addTitle(pdfTitle);
        doc.addKeywords(pdfKeywords);
        doc.addHeader("License", "GNU GPL v3");
        Image image = null;
        try {
            image = Image.getInstance(new URL(OpenToxLogoUrl));
        } catch (Exception ex) {// OpenTox Logo was not found on the web...
            try {// use the cached image instead
                YaqpLogger.LOG.log(new Trace(getClass(), "OpenTox Logo not found at " + OpenToxLogoUrl));
                image = Image.getInstance(alternativeLogoPath);
            } catch (Exception ex1) {// if no image at local folder
                YaqpLogger.LOG.log(new Debug(getClass(),
                        "OpenTox Logo not found at " + alternativeLogoPath + " :: " + ex1));
            }
        }
        if (image != null) {
            image.scalePercent(40);
            image.setAnnotation(new Annotation(0, 0, 0, 0, "http://opentox.org"));
            Chunk ck_ot = new Chunk(image, -5, -30);
            doc.add(ck_ot);
        }
        try {
            Image yaqp = Image.getInstance(yaqpLogo);
            yaqp.scalePercent(30);
            yaqp.setAnnotation(new Annotation(0, 0, 0, 0, "https://opentox.ntua.gr"));
            yaqp.setAlt("YAQP(R), yet another QSAR Project");
            Chunk ck_yaqp = new Chunk(yaqp, 15, -30);
            doc.add(ck_yaqp);
        } catch (Exception ex) {
            YaqpLogger.LOG
                    .log(new Warning(getClass(), "YAQP Logo not found at " + kinkyDesignLogo + " :: " + ex));
        }
        doc.add(new Paragraph("\n\n\n"));
        for (Element e : elements) {
            doc.add(e);
        }
        doc.close();
    } catch (DocumentException ex) {
        String message = "Error while generating PDF representation.";
        YaqpLogger.LOG.log(new Warning(getClass(), message));
        throw new YaqpException(XPDF18, message, ex);
    }

}

From source file:principal.Informes.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  ww .j a  v a2s.c o m
 *
 * @param request servlet request
 * @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, DocumentException, InterruptedException {
    // SERVLET PARA LA IMPRESIN DE LOS REGISTROS DE SISTEMA
    try {
        // Ejecucion de comando que sera introducido en el pdf
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("/opt/script/owncloud/logOwncloud");
        process.waitFor();
        BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String linea;

        //Imagen para documento PDF
        Image imagen = Image.getInstance("images/owncloud.png");
        imagen.setAlignment(Element.ALIGN_CENTER); //donde estara la imagen localizada           
        imagen.setAlt("50");

        // Creo objeto document de la clase Document     
        Document document = new Document();

        // paso 2
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        // Abro nuevo documento PDF
        document.open();
        document.addAuthor("Administrator");

        //Nuevo parrafo con texto centrado
        Paragraph parrafo1 = new Paragraph("Informe de servidor Owncloud");
        parrafo1.setAlignment(1); //Centrar el texto
        document.add(imagen); //introduccion de la imagen en el documento pdf
        document.add(parrafo1);

        // bucle ejecutando el comando e introduciendolo en un nuevo parrafo del PDF
        while ((linea = buffer.readLine()) != null) {
            document.add(new Paragraph(linea));
        }

        // Cierre del documento PDF
        document.close();

        // Response headers
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        // Tipo de contenido que ser
        response.setContentType("application/pdf");
        // the contentlength
        response.setContentLength(baos.size());
        // Extrae todo el PDF para introducirlo en el servlet
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }

}

From source file:Tables.Printer.java

public void header(Document doc, String reportType) throws DocumentException {
    String companyInfo = "NJEIFORBI ACCOUNTS BOOK \nFINANCIAL REPORTS";

    Paragraph newLine = new Paragraph("\n");
    doc.add(newLine);/*from   www  .j a va2  s  .  c  o m*/

    // add the paragraph to the document            

    /*new heading*/
    //adding the company logo.
    try {
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(80f, 80f);
        img.setAlt("Unity Systems");
        img.setAlignment(Element.ALIGN_CENTER);

        //            Image img = Image.getInstance(this.companyLogo);

        /*with the next 3 lines oc code, the image will align at the center of the page.*/
        //            img.setAbsolutePosition(
        //                (PageSize.A4.getWidth() - img.getScaledWidth()) / 2,
        //                (PageSize.A4.getHeight() - img.getScaledHeight()) / 2);

        doc.add(img);
    } catch (IOException | DocumentException ex) {
        Dialogs.create().title("Logo Not found").message(
                "The Company's logo has not been located. So the printout will be without the logo of the company")
                .showError();
        ex.printStackTrace();
    }

    Paragraph companyName = new Paragraph(companyInfo, this.companyNameFont);
    Paragraph reportTitle = new Paragraph(reportType, this.reportTitleFont);

    companyName.setAlignment(Element.ALIGN_CENTER);
    reportTitle.setAlignment(Element.ALIGN_CENTER);
    newLine.setAlignment(Element.ALIGN_CENTER);

    doc.add(companyName);
    doc.add(reportTitle);
    doc.add(newLine);

    /*new heading ends*/

}

From source file:Tables.PrinterClass.java

/***************HEADINGS HEADINGS HEADINGS */

private void makeCompanyHeading(Document doc) throws DocumentException, BadElementException, IOException {

    //adding the company logo.
    try {/* w w  w . j av a 2 s  . c  om*/
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(80f, 80f);
        img.setAlt("Unity Systems");
        img.setAlignment(Element.ALIGN_CENTER);

        //            Image img = Image.getInstance(this.companyLogo);

        /*with the next 3 lines oc code, the image will align at the center of the page.*/
        //            img.setAbsolutePosition(
        //                (PageSize.A4.getWidth() - img.getScaledWidth()) / 2,
        //                (PageSize.A4.getHeight() - img.getScaledHeight()) / 2);

        doc.add(img);
    } catch (IOException | DocumentException ex) {
        Dialogs.create().title("Logo Not found").message(
                "The Company's logo has not been located. So the printout will be without the logo of the company")
                .showError();
        ex.printStackTrace();
    }

    Paragraph companyName = new Paragraph(this.companyName, this.companyNameFont);
    Paragraph newLine = new Paragraph("\n");
    Paragraph companyLocation = new Paragraph(
            this.companyLocation + "\n" + this.companyPoBox + "\n " + this.companyTel, this.companySubInfoFont);

    companyName.setAlignment(Element.ALIGN_CENTER);
    companyLocation.setAlignment(Element.ALIGN_CENTER);
    newLine.setAlignment(Element.ALIGN_CENTER);

    doc.add(companyName);
    doc.add(companyLocation);
    doc.add(newLine);

}

From source file:Tables.PrinterClass.java

public void footer(Document doc) throws DocumentException {
    Paragraph paragraph = new Paragraph("@" + this.companyName);
    doc.add(paragraph);/*www.  j  av a  2  s  .co m*/
    dNow = new Date();

    String prodDate;
    prodDate = "Created on the " + dateOnly.format(dNow) + " at " + timeOnly.format(dNow);

    //////////////////

    PdfPTable timeOfProduction = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(prodDate.trim(), smallFooter));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setColspan(3);
    cell.setBorder(0);
    if (prodDate.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    timeOfProduction.addCell(cell);
    doc.add(timeOfProduction);

    try {
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(20f, 20f);

        img.setAbsolutePosition((PageSize.A4.getWidth() - img.getScaledWidth()),
                (PageSize.A4.getHeight() - img.getScaledHeight())); //place the image at the bottom right position

        img.setAlt("Unity Systems");
    } catch (Exception ex) {

    }

}