Example usage for com.lowagie.text Document addTitle

List of usage examples for com.lowagie.text Document addTitle

Introduction

In this page you can find the example usage for com.lowagie.text Document addTitle.

Prototype


public boolean addTitle(String title) 

Source Link

Document

Adds the title to a Document.

Usage

From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java

License:Open Source License

private MemoryFileBuffer getPDFBuffer() throws DocumentException {
    MemoryFileBuffer buffer = new MemoryFileBuffer();
    MemoryOutputStream mos = new MemoryOutputStream(buffer);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, mos);

    String titleKey = this._reportModel.getReportTitleLocalizationKey();
    String title = localize(titleKey, titleKey);
    this._normalFont = new Font(Font.HELVETICA, 7, Font.NORMAL);
    this._boldFont = new Font(Font.HELVETICA, 7, Font.BOLD);

    document.addTitle(title);
    document.addAuthor("Agura IT Reports");
    document.addSubject(title);//from w ww  . j  a v a  2 s  . c o m
    document.open();

    String dateString = new Date(System.currentTimeMillis()).toString();

    document.add(new Phrase(title + " " + dateString + "\n\n", this._boldFont));
    document.add(new Phrase("\n", this._boldFont));

    int cols = this._reportModel.getColumnSize() + 1;
    Table table = new Table(cols);
    this._widths = new int[cols];
    for (int i = 0; i < cols; i++) {
        this._widths[i] = 1;
    }

    table.setSpacing(1.5f);

    buildColumnHeaders(table);
    buildRowHeaders(table);
    buildReportCells(table);

    int totalWidth = 0;
    for (int i = 0; i < cols; i++) {
        this._widths[i] += 1;
        totalWidth += this._widths[i];
    }
    int width = (100 * totalWidth) / 95;
    if (width > 100) {
        width = 100;
    }
    table.setWidth(width);
    table.setWidths(this._widths);
    document.add(table);
    document.close();
    writer.setPdfVersion(PdfWriter.VERSION_1_2);

    return buffer;
}

From source file:songscribe.ui.mainframeactions.ExportPDFAction.java

License:Open Source License

public static void createPDF(Data data, File outputFile, Boolean isGUI) {
    float resolution = 72f / MusicSheet.RESOLUTION;
    float paperWidth = data.paperWidth * resolution;
    float paperHeight = data.paperHeight * resolution;
    MainFrame mainFrame = data.mainFrame;
    Document document = new Document(new Rectangle(0, 0, paperWidth, paperHeight), 0, 0, 0, 0);
    document.addCreator(mainFrame.PROG_NAME);
    document.addTitle(mainFrame.getMusicSheet().getComposition().getSongTitle());

    // Scale to fit
    int sheetWidth = mainFrame.getMusicSheet().getSheetWidth();
    int sheetHeight = mainFrame.getMusicSheet().getSheetHeight();
    double horizontalMargin = (data.leftInnerMargin + data.rightOuterMargin) * resolution;
    double horizontalScale = (paperWidth - horizontalMargin) / sheetWidth;
    double verticalMargin = (data.topMargin + data.bottomMargin) * resolution;
    double verticalScale = (paperHeight - verticalMargin) / sheetHeight;
    double scale;
    double leftMargin = data.leftInnerMargin * resolution;

    if (horizontalScale < verticalScale) {
        scale = horizontalScale;//www .jav a2s.  c o m
    } else {
        // If scaling vertically, the horizontal margin will be larger than
        // what is specified in Data. So we calculate the total margin available,
        // then give the left margin the same fraction of the total margin
        // it would have had before scaling.
        scale = verticalScale;
        double scaledMargin = paperWidth - (sheetWidth * scale);
        double leftMarginFactor = (double) data.leftInnerMargin
                / (double) (data.leftInnerMargin + data.rightOuterMargin);
        leftMargin = scaledMargin * leftMarginFactor;
    }

    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Graphics2D g2 = cb.createGraphicsShapes(paperWidth, paperHeight);
        g2.translate(leftMargin, data.topMargin * resolution);
        mainFrame.getMusicSheet().getBestDrawer().drawMusicSheet(g2, false, scale);
        g2.dispose();
        document.close();

        if (isGUI) {
            Utilities.openExportFile(mainFrame, outputFile);
        }
    } catch (DocumentException e1) {
        if (isGUI) {
            mainFrame.showErrorMessage("An unexpected error occurred and could not export as PDF.");
        }

        logger.error("PDF save", e1);
    } catch (FileNotFoundException e1) {
        if (isGUI) {
            mainFrame.showErrorMessage(MainFrame.COULD_NOT_SAVE_MESSAGE);
        }

        logger.error("PDF save", e1);
    }
}