Example usage for com.lowagie.text Image scaleToFit

List of usage examples for com.lowagie.text Image scaleToFit

Introduction

In this page you can find the example usage for com.lowagie.text Image scaleToFit.

Prototype

public void scaleToFit(float fitWidth, float fitHeight) 

Source Link

Document

Scales the image so that it fits a certain width and height.

Usage

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes information about the provided optimizing job to the document.
 *
 * @param  document       The document to which the job information should be
 *                        written.//from w  w w  .ja va 2s. com
 * @param  optimizingJob  The optimizing job to include in the document.
 *
 * @throws  DocumentException  If a problem occurs while writing the contents.
 */
private void writeOptimizingJob(Document document, OptimizingJob optimizingJob) throws DocumentException {
    Anchor anchor = new Anchor("Optimizing Job " + optimizingJob.getOptimizingJobID(),
            FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, Color.BLACK));
    anchor.setName(optimizingJob.getOptimizingJobID());
    Paragraph p = new Paragraph(anchor);
    document.add(p);

    // Write the general information to the document.
    p = new Paragraph("General Information",
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    document.add(p);

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setWidths(new int[] { 30, 70 });
    writeTableCell(table, "Optimizing Job ID");
    writeTableCell(table, optimizingJob.getOptimizingJobID());

    writeTableCell(table, "Job Type");
    writeTableCell(table, optimizingJob.getJobClassName());

    String descriptionStr = optimizingJob.getDescription();
    if ((descriptionStr == null) || (descriptionStr.length() == 0)) {
        descriptionStr = "(Not Specified)";
    }
    writeTableCell(table, "Base Description");
    writeTableCell(table, descriptionStr);

    writeTableCell(table, "Include Thread Count in Description");
    writeTableCell(table, String.valueOf(optimizingJob.includeThreadsInDescription()));

    writeTableCell(table, "Job State");
    writeTableCell(table, Constants.jobStateToString(optimizingJob.getJobState()));
    document.add(table);

    // Write the schedule config to the document if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Schedule Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date startTime = optimizingJob.getStartTime();
        String startStr;
        if (startTime == null) {
            startStr = "(Not Available)";
        } else {
            startStr = dateFormat.format(startTime);
        }
        writeTableCell(table, "Scheduled Start Time");
        writeTableCell(table, startStr);

        int duration = optimizingJob.getDuration();
        String durationStr;
        if (duration > 0) {
            durationStr = duration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Job Duration");
        writeTableCell(table, durationStr);

        writeTableCell(table, "Delay Between Iterations");
        writeTableCell(table, optimizingJob.getDelayBetweenIterations() + " seconds");

        writeTableCell(table, "Number of Clients");
        writeTableCell(table, String.valueOf(optimizingJob.getNumClients()));

        String[] requestedClients = optimizingJob.getRequestedClients();
        if ((requestedClients != null) && (requestedClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < requestedClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(requestedClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Requested Clients");
            table.addCell(clientTable);
        }

        String[] monitorClients = optimizingJob.getResourceMonitorClients();
        if ((monitorClients != null) && (monitorClients.length > 0)) {
            PdfPTable clientTable = new PdfPTable(1);
            for (int i = 0; i < monitorClients.length; i++) {
                PdfPCell clientCell = new PdfPCell(new Phrase(monitorClients[i]));
                clientCell.setBorder(0);
                clientTable.addCell(clientCell);
            }

            writeTableCell(table, "Resource Monitor Clients");
            table.addCell(clientTable);
        }

        writeTableCell(table, "Minimum Number of Threads");
        writeTableCell(table, String.valueOf(optimizingJob.getMinThreads()));

        int maxThreads = optimizingJob.getMaxThreads();
        String maxThreadsStr;
        if (maxThreads > 0) {
            maxThreadsStr = String.valueOf(maxThreads);
        } else {
            maxThreadsStr = "(Not Specified)";
        }
        writeTableCell(table, "Maximum Number of Threads");
        writeTableCell(table, maxThreadsStr);

        writeTableCell(table, "Thread Increment Between Iterations");
        writeTableCell(table, String.valueOf(optimizingJob.getThreadIncrement()));

        writeTableCell(table, "Statistics Collection Interval");
        writeTableCell(table, optimizingJob.getCollectionInterval() + " seconds");
        document.add(table);
    }

    // Get the optimization algorithm used.
    OptimizationAlgorithm optimizationAlgorithm = optimizingJob.getOptimizationAlgorithm();
    ParameterList paramList = optimizationAlgorithm.getOptimizationAlgorithmParameters();
    Parameter[] optimizationParams = paramList.getParameters();

    // Write the optimizing config to the document if appropriate.
    if (includeScheduleConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Optimization Settings",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        for (int i = 0; i < optimizationParams.length; i++) {
            writeTableCell(table, optimizationParams[i].getDisplayName());
            writeTableCell(table, optimizationParams[i].getDisplayValue());
        }

        writeTableCell(table, "Maximum Consecutive Non-Improving Iterations");
        writeTableCell(table, String.valueOf(optimizingJob.getMaxNonImproving()));

        writeTableCell(table, "Re-Run Best Iteration");
        writeTableCell(table, String.valueOf(optimizingJob.reRunBestIteration()));

        int reRunDuration = optimizingJob.getReRunDuration();
        String durationStr;
        if (reRunDuration > 0) {
            durationStr = reRunDuration + " seconds";
        } else {
            durationStr = "(Not Specified)";
        }
        writeTableCell(table, "Re-Run Duration");
        writeTableCell(table, durationStr);

        document.add(table);
    }

    // Write the job-specific config to the document if appropriate.
    if (includeJobConfig) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Parameter Information",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Parameter[] params = optimizingJob.getParameters().getParameters();
        for (int i = 0; i < params.length; i++) {
            writeTableCell(table, params[i].getDisplayName());
            writeTableCell(table, params[i].getDisplayValue());
        }

        document.add(table);
    }

    // Write the statistical data to the document if appropriate.
    if (includeStats && optimizingJob.hasStats()) {
        document.add(new Paragraph(" "));
        p = new Paragraph("Execution Data",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
        document.add(p);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 30, 70 });

        Date actualStartTime = optimizingJob.getActualStartTime();
        String startTimeStr;
        if (actualStartTime == null) {
            startTimeStr = "(Not Available)";
        } else {
            startTimeStr = dateFormat.format(actualStartTime);
        }
        writeTableCell(table, "Actual Start Time");
        writeTableCell(table, startTimeStr);

        Date actualStopTime = optimizingJob.getActualStopTime();
        String stopTimeStr;
        if (actualStopTime == null) {
            stopTimeStr = "(Not Available)";
        } else {
            stopTimeStr = dateFormat.format(actualStopTime);
        }
        writeTableCell(table, "Actual Stop Time");
        writeTableCell(table, stopTimeStr);

        Job[] iterations = optimizingJob.getAssociatedJobs();
        if ((iterations != null) && (iterations.length > 0)) {
            writeTableCell(table, "Job Iterations Completed");
            writeTableCell(table, String.valueOf(iterations.length));

            int optimalThreadCount = optimizingJob.getOptimalThreadCount();
            String threadStr;
            if (optimalThreadCount > 0) {
                threadStr = String.valueOf(optimalThreadCount);
            } else {
                threadStr = "(Not Available)";
            }
            writeTableCell(table, "Optimal Thread Count");
            writeTableCell(table, threadStr);

            double optimalValue = optimizingJob.getOptimalValue();
            String valueStr;
            if (optimalThreadCount > 0) {
                valueStr = decimalFormat.format(optimalValue);
            } else {
                valueStr = "(Not Available)";
            }
            writeTableCell(table, "Optimal Value");
            writeTableCell(table, valueStr);

            String optimalID = optimizingJob.getOptimalJobID();
            writeTableCell(table, "Optimal Job Iteration");
            if ((optimalID == null) || (optimalID.length() == 0)) {
                writeTableCell(table, "(Not Available)");
            } else if (includeOptimizingIterations) {
                anchor = new Anchor(optimalID,
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + optimalID);
                table.addCell(new PdfPCell(anchor));
            } else {
                writeTableCell(table, optimalID);
            }
        }

        Job reRunIteration = optimizingJob.getReRunIteration();
        if (reRunIteration != null) {
            writeTableCell(table, "Re-Run Iteration");
            if (includeOptimizingIterations) {
                anchor = new Anchor(reRunIteration.getJobID(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + reRunIteration.getJobID());
                table.addCell(new PdfPCell(anchor));
            } else {
                writeTableCell(table, reRunIteration.getJobID());
            }

            String valueStr;
            try {
                double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(reRunIteration);
                valueStr = decimalFormat.format(iterationValue);
            } catch (Exception e) {
                valueStr = "N/A";
            }

            writeTableCell(table, "Re-Run Iteration Value");
            writeTableCell(table, valueStr);
        }

        document.add(table);

        if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) {
            document.add(new Paragraph(" "));
            p = new Paragraph("Job Iterations",
                    FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
            document.add(p);

            table = new PdfPTable(2);
            table.setWidthPercentage(100);
            table.setWidths(new int[] { 50, 50 });

            for (int i = 0; i < iterations.length; i++) {
                String valueStr;
                try {
                    double iterationValue = optimizationAlgorithm.getIterationOptimizationValue(iterations[i]);
                    valueStr = decimalFormat.format(iterationValue);
                } catch (Exception e) {
                    valueStr = "N/A";
                }

                anchor = new Anchor(iterations[i].getJobID(),
                        FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, Color.BLUE));
                anchor.setReference('#' + iterations[i].getJobID());
                table.addCell(new PdfPCell(anchor));
                writeTableCell(table, valueStr);
            }

            document.add(table);
        }

        if (includeGraphs && (iterations != null) && (iterations.length > 0)) {
            String[] statNames = iterations[0].getStatTrackerNames();
            for (int j = 0; j < statNames.length; j++) {
                StatTracker[] trackers = iterations[0].getStatTrackers(statNames[j]);
                if ((trackers != null) && (trackers.length > 0)) {
                    StatTracker tracker = trackers[0].newInstance();
                    tracker.aggregate(trackers);

                    try {
                        document.newPage();
                        ParameterList params = tracker.getGraphParameterStubs(iterations);
                        BufferedImage graphImage = tracker.createGraph(iterations,
                                Constants.DEFAULT_GRAPH_WIDTH, Constants.DEFAULT_GRAPH_HEIGHT, params);
                        Image image = Image.getInstance(imageToByteArray(graphImage));
                        image.scaleToFit(inchesToPoints(5.5), inchesToPoints(4.5));
                        document.add(image);
                    } catch (Exception e) {
                    }
                }
            }
        }

        if (includeOptimizingIterations && (iterations != null) && (iterations.length > 0)) {
            for (int i = 0; i < iterations.length; i++) {
                document.newPage();
                writeJob(document, iterations[i]);
            }
        }
        if (includeOptimizingIterations && (reRunIteration != null)) {
            document.newPage();
            writeJob(document, reRunIteration);
        }
    }
}

From source file:cz.incad.kramerius.rest.api.k5.client.pdf.PDFResource.java

License:Open Source License

private static StreamingOutput streamingOutput(final File file, final String format) {
    return new StreamingOutput() {
        public void write(OutputStream output) throws IOException, WebApplicationException {
            try {
                Rectangle formatRect = formatRect(format);
                Document document = new Document(formatRect);
                PdfWriter.getInstance(document, output);
                document.open();/*  w w  w . j  av  a  2s.  c o  m*/

                Image image = Image.getInstance(file.toURI().toURL());

                image.scaleToFit(
                        document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(),
                        document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin());
                document.add(image);

                document.close();

            } catch (Exception e) {
                throw new WebApplicationException(e);
            } finally {
                if (file != null)
                    file.delete();
            }
        }
    };
}

From source file:de.appplant.cordova.plugin.printer.Printer.java

License:Apache License

/**
 * Slices the screenshot into pages, merges those into a single pdf
 * and saves it in the public accessible /sdcard dir.
 *//*ww w .  ja v a  2 s.c  om*/
private File saveWebViewAsPdf(Bitmap screenshot) {
    try {

        File sdCard = Environment.getExternalStorageDirectory();
        File dir = new File(sdCard.getAbsolutePath() + "/" + this.publicTmpDir + "/");
        dir.mkdirs();
        File file;
        FileOutputStream stream;

        double pageWidth = PageSize.A4.getWidth() * 0.85; // width of the image is 85% of the page
        double pageHeight = PageSize.A4.getHeight() * 0.80; // max height of the image is 80% of the page
        double pageHeightToWithRelation = pageHeight / pageWidth; // e.g.: 1.33 (4/3)

        Bitmap currPage;
        int totalSize = screenshot.getHeight();
        int currPos = 0;
        int currPageCount = 0;
        int sliceWidth = screenshot.getWidth();
        int sliceHeight = (int) Math.round(sliceWidth * pageHeightToWithRelation);
        while (totalSize > currPos && currPageCount < 100) // max 100 pages
        {
            currPageCount++;

            Log.v(LOG_TAG, "Creating page nr. " + currPageCount);

            // slice bitmap
            currPage = Bitmap.createBitmap(screenshot, 0, currPos, sliceWidth,
                    (int) Math.min(sliceHeight, totalSize - currPos));

            // save page as png
            stream = new FileOutputStream(new File(dir, "print-page-" + currPageCount + ".png"));
            currPage.compress(Bitmap.CompressFormat.PNG, 100, stream);
            stream.close();

            // move current position indicator
            currPos += sliceHeight;
        }

        // create pdf
        Log.v(LOG_TAG, "Creating pdf");
        Document document = new Document();
        File filePdf = new File(dir, this.printTitle + ".pdf"); // change the output name of the pdf here
        PdfWriter.getInstance(document, new FileOutputStream(filePdf));
        document.open();
        for (int i = 1; i <= currPageCount; ++i) {
            Log.v(LOG_TAG, "Adding page nr. " + i + " to the pdf file.");
            file = new File(dir, "print-page-" + i + ".png");
            Image image = Image.getInstance(file.getAbsolutePath());
            image.scaleToFit((float) pageWidth, 9999);
            image.setAlignment(Element.ALIGN_CENTER);
            document.add(image);
            document.newPage();
        }
        document.close();

        // delete tmp image files
        for (int i = 1; i <= currPageCount; ++i) {
            file = new File(dir, "print-page-" + i + ".png");
            file.delete();
        }

        return filePdf;

    } catch (IOException e) {
        Log.e(LOG_TAG, "ERROR: " + e.getMessage());
        e.printStackTrace();
        // return error answer to cordova
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
        result.setKeepCallback(false);
        ctx.sendPluginResult(result);
    } catch (DocumentException e) {
        Log.e(LOG_TAG, "ERROR: " + e.getMessage());
        e.printStackTrace();
        // return error answer to cordova
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
        result.setKeepCallback(false);
        ctx.sendPluginResult(result);
    }

    Log.e(LOG_TAG, "Uncaught ERROR!");

    return null;
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Set the logo of Humboldt on the left corner and the current date on the
 * right corner/*from www  . jav a 2  s .  c  o  m*/
 * 
 * @param document
 *            reference of the pdfDocument object
 */
protected void addHeading(Document document) {
    Paragraph paragraph = new Paragraph();
    PdfPTable table = createMyStandardTable(2);

    table.setTotalWidth(TABLEWIDTH);
    PdfPCell cell;

    Image img = new ResourceLoader("pdf/humboldt_logo.png").getImage();
    img.setAlignment(Element.ALIGN_BOTTOM);
    img.scaleToFit(205f, 65f);
    cell = new PdfPCell(img);

    cell.setBorder(0);
    table.addCell(cell);

    String date = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN).format(Calendar.getInstance().getTime());

    cell = new PdfPCell(new Phrase(date));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);

    paragraph.add(table);
    addEmptyLine(paragraph, 1);

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java

License:Open Source License

/**
 * method to create PDF/*from   w  w  w. ja  v a  2s.c o  m*/
 * @param adminUser The admin user
 * @param locale The locale
 * @param strNameFile PDF name
 * @param out OutputStream
 * @param nIdRecord the id record
 * @param listIdEntryConfig list of config id entry
 * @param bExtractNotFilledField if true, extract empty fields, false
 */
public static void doCreateDocumentPDF(AdminUser adminUser, Locale locale, String strNameFile, OutputStream out,
        int nIdRecord, List<Integer> listIdEntryConfig, Boolean bExtractNotFilledField) {
    Document document = new Document(PageSize.A4);

    Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);

    EntryFilter filter;

    Record record = RecordHome.findByPrimaryKey(nIdRecord, plugin);

    filter = new EntryFilter();
    filter.setIdDirectory(record.getDirectory().getIdDirectory());
    filter.setIsGroup(EntryFilter.FILTER_TRUE);

    List<IEntry> listEntry = DirectoryUtils.getFormEntries(record.getDirectory().getIdDirectory(), plugin,
            adminUser);
    int nIdDirectory = record.getDirectory().getIdDirectory();
    Directory directory = DirectoryHome.findByPrimaryKey(nIdDirectory, plugin);

    try {
        PdfWriter.getInstance(document, out);
    } catch (DocumentException e) {
        AppLogService.error(e);
    }

    document.open();

    if (record.getDateCreation() != null) {
        SimpleDateFormat monthDayYearformatter = new SimpleDateFormat(
                AppPropertiesService.getProperty(PROPERTY_POLICE_FORMAT_DATE));

        Font fontDate = new Font(
                DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)),
                DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_DATE)),
                DirectoryUtils
                        .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_DATE)));

        Paragraph paragraphDate = new Paragraph(
                new Phrase(monthDayYearformatter.format(record.getDateCreation()).toString(), fontDate));

        paragraphDate.setAlignment(DirectoryUtils
                .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_ALIGN_DATE)));

        try {
            document.add(paragraphDate);
        } catch (DocumentException e) {
            AppLogService.error(e);
        }
    }

    Image image;

    try {

        image = Image.getInstance(ImageIO.read(new File(AppPathService
                .getAbsolutePathFromRelativePath(AppPropertiesService.getProperty(PROPERTY_IMAGE_URL)))), null);
        image.setAlignment(
                DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_IMAGE_ALIGN)));
        float fitWidth;
        float fitHeight;

        try {
            fitWidth = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITWIDTH));
            fitHeight = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITHEIGHT));
        } catch (NumberFormatException e) {
            fitWidth = 100f;
            fitHeight = 100f;
        }

        image.scaleToFit(fitWidth, fitHeight);

        try {
            document.add(image);
        } catch (DocumentException e) {
            AppLogService.error(e);
        }
    } catch (BadElementException e) {
        AppLogService.error(e);
    } catch (MalformedURLException e) {
        AppLogService.error(e);
    } catch (IOException e) {
        AppLogService.error(e);
    }

    directory.getTitle();

    Font fontTitle = new Font(
            DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)),
            DirectoryUtils
                    .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_TITLE_DIRECTORY)),
            DirectoryUtils.convertStringToInt(
                    AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_TITLE_DIRECTORY)));
    fontTitle.isUnderlined();

    Paragraph paragraphHeader = new Paragraph(new Phrase(directory.getTitle(), fontTitle));
    paragraphHeader.setAlignment(Element.ALIGN_CENTER);
    paragraphHeader.setSpacingBefore(DirectoryUtils.convertStringToInt(
            AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_BEFORE_TITLE_DIRECTORY)));
    paragraphHeader.setSpacingAfter(DirectoryUtils.convertStringToInt(
            AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_AFTER_TITLE_DIRECTORY)));

    try {
        document.add(paragraphHeader);
    } catch (DocumentException e) {
        AppLogService.error(e);
    }

    builderPDFWithEntry(document, plugin, nIdRecord, listEntry, listIdEntryConfig, locale,
            bExtractNotFilledField);
    document.close();
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

public void createLogoContent(Document document)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
    checkBundleDimensions(iwb);/*from  w  ww. j a  va  2 s.  c  o m*/
    Image image = Image.getInstance(iwb.getResourcesRealPath() + "/shared/commune_logo.png");
    image.scaleToFit(getPointsFromMM(logoScaleWidth), getPointsFromMM(logoScaleHeight));
    image.setAbsolutePosition(getPointsFromMM(logoAbsPosX), getPointsFromMM(logoAbsPosY));
    document.add(image);

}

From source file:model.relatorio.java

public void getRelatorioTodosAlunos() throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Alunos.pdf"));
    doc.open();/*from   w ww  . j  ava  2 s .  c om*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                            RELATORIO ALUNOS"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aluno");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_aluno") + "   Nome : " + rs.getString("nome")
                    + "\nCpf : " + rs.getString("cpf") + "   Endereo : " + rs.getString("endereco")
                    + "\nTelefone : " + rs.getString("telefone") + "  Idade : " + rs.getInt("idade")
                    + "  Altura : " + rs.getString("altura") + "  Peso : " + rs.getString("peso")));
            doc.add(new Paragraph(" "));
            doc.add(new Paragraph(
                    "_____________________________________________________________________________"));
            doc.add(new Paragraph(" "));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Alunos.pdf"));

}

From source file:model.relatorio.java

public void getRelatorioTodosProfessores() throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Professores.pdf"));
    doc.open();/*from  w  ww.  jav  a  2s .co  m*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO PROFESSORES"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from professor");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_prof") + "   Nome : " + rs.getString("nome")
                    + "\nCpf : " + rs.getString("cpf") + "   Endereo : " + rs.getString("endereco")
                    + "\nTelefone : " + rs.getString("telefone") + "     Salario : "
                    + rs.getDouble("salario")));

            doc.add(new Paragraph(" "));
            doc.add(new Paragraph(
                    "_____________________________________________________________________________"));
            doc.add(new Paragraph(" "));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Professores.pdf"));

}

From source file:model.relatorio.java

public void getRelatorioTodasAulas() throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Aulas.pdf"));
    doc.open();/* ww  w.  j av  a2 s .c  o  m*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO AULAS"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aula");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_aula") + "   Nome : " + rs.getString("nome")
                    + "\nPreo : " + rs.getDouble("preco") + "   Horario : " + rs.getString("horario")));

            doc.add(new Paragraph(" "));
            doc.add(new Paragraph(
                    "_____________________________________________________________________________"));
            doc.add(new Paragraph(" "));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Aulas.pdf"));

}

From source file:model.relatorio.java

public void getRelatorioAula(String idParaProcurar)
        throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Aula ID " + idParaProcurar + ".pdf"));
    doc.open();/*w w w .jav  a  2s .com*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO AULA"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aula where id_aula = " + idParaProcurar);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {

            doc.add(new Paragraph("ID: " + rs.getInt("id_aula") + "  Nome : " + rs.getString("nome")
                    + "  Preo : " + rs.getDouble("preco") + "   Horario : " + rs.getString("horario")));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" ALUNOS MATRICULADOS:"));

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select aluno.id_aluno, aluno.nome from aluno\n" + "inner join matricula\n"
                + "on aluno.id_aluno = matricula.id_aluno\n" + "inner join aula\n"
                + "on aula.id_aula = matricula.id_aula\n" + " where aula.id_aula =" + idParaProcurar);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {

            doc.add(new Paragraph("\nID: " + rs.getInt("id_aluno") + "   | Nome : " + rs.getString("nome")));

        }

        doc.close();
        JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
        Desktop.getDesktop().open(new File("Relatorio Aula ID " + idParaProcurar + ".pdf"));

    } catch (SQLException ex) {
        Logger.getLogger(relatorio.class.getName()).log(Level.SEVERE, null, ex);
    }

}