Example usage for org.apache.pdfbox.pdmodel.font PDType1Font HELVETICA_OBLIQUE

List of usage examples for org.apache.pdfbox.pdmodel.font PDType1Font HELVETICA_OBLIQUE

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.font PDType1Font HELVETICA_OBLIQUE.

Prototype

PDType1Font HELVETICA_OBLIQUE

To view the source code for org.apache.pdfbox.pdmodel.font PDType1Font HELVETICA_OBLIQUE.

Click Source Link

Usage

From source file:airviewer.BoxAnnotationMaker.java

License:Apache License

/**
 *
 * @param document/*from w w  w  . j av a 2  s  .  c  o m*/
 * @param arguments(lowerLeftX, lowerLeftY, width, height)
 * @return
 */
public static List<PDAnnotation> make(PDDocument document, ArrayList<String> arguments) {
    assert null != arguments && arguments.size() == 5;
    assert null != document;

    List<PDAnnotation> result;

    try {
        int pageNumber = parseInt(arguments.get(0));
        float lowerLeftX = parseFloat(arguments.get(1));
        float lowerLeftY = parseFloat(arguments.get(2));
        float width = parseFloat(arguments.get(3));
        float height = parseFloat(arguments.get(4));
        String contents = "";
        PDFont font = PDType1Font.HELVETICA_OBLIQUE;
        float fontSize = 16; // Or whatever font size you want.
        //float textWidth = font.getStringWidth(contents) * fontSize / 1000.0f;
        //float textHeight = 32;

        try {
            PDPage page = document.getPage(pageNumber);
            PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
            PDBorderStyleDictionary borderThick = new PDBorderStyleDictionary();
            borderThick.setWidth(72 / 12); // 12th inch
            PDRectangle position = new PDRectangle();
            position.setLowerLeftX(lowerLeftX);
            position.setLowerLeftY(lowerLeftY);
            position.setUpperRightX(lowerLeftX + width);
            position.setUpperRightY(lowerLeftY + height);

            PDAnnotationSquareCircle aSquare = new PDAnnotationSquareCircle(
                    PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
            aSquare.setAnnotationName(new UID().toString());
            aSquare.setContents(contents);
            aSquare.setColor(red); // Outline in red, not setting a fill
            PDColor fillColor = new PDColor(new float[] { .8f, .8f, .8f }, PDDeviceRGB.INSTANCE);
            aSquare.setInteriorColor(fillColor);
            aSquare.setBorderStyle(borderThick);
            aSquare.setRectangle(position);
            result = new ArrayList<>(page.getAnnotations()); // copy
            page.getAnnotations().add(aSquare);

            // The following lines are needed for PDFRenderer to render 
            // annotations. Preview and Acrobat don't seem to need these.
            if (null == aSquare.getAppearance()) {
                aSquare.setAppearance(new PDAppearanceDictionary());
                PDAppearanceStream annotationAppearanceStream = new PDAppearanceStream(document);
                position.setLowerLeftX(lowerLeftX - borderThick.getWidth() * 0.5f);
                position.setLowerLeftY(lowerLeftY - borderThick.getWidth() * 0.5f);
                position.setUpperRightX(lowerLeftX + width + borderThick.getWidth() * 0.5f);
                position.setUpperRightY(lowerLeftY + height + borderThick.getWidth() * 0.5f);
                annotationAppearanceStream.setBBox(position);
                annotationAppearanceStream.setMatrix(new AffineTransform());
                annotationAppearanceStream.setResources(page.getResources());

                try (PDPageContentStream appearanceContent = new PDPageContentStream(document,
                        annotationAppearanceStream)) {
                    Matrix transform = new Matrix();
                    appearanceContent.transform(transform);
                    appearanceContent.addRect(lowerLeftX, lowerLeftY, width, height);
                    appearanceContent.setLineWidth(borderThick.getWidth());
                    appearanceContent.setNonStrokingColor(fillColor);
                    appearanceContent.setStrokingColor(red);
                    appearanceContent.fillAndStroke();
                    appearanceContent.beginText();

                    // Center text vertically, left justified
                    appearanceContent.newLineAtOffset(lowerLeftX, lowerLeftY + height * 0.5f - fontSize * 0.5f);
                    appearanceContent.setFont(font, fontSize);
                    appearanceContent.setNonStrokingColor(red);
                    appearanceContent.showText(contents);
                    appearanceContent.endText();
                }
                aSquare.getAppearance().setNormalAppearance(annotationAppearanceStream);
            }
            //System.out.println(page.getAnnotations().toString());

        } catch (IOException ex) {
            Logger.getLogger(DocumentCommandWrapper.class.getName()).log(Level.SEVERE, null, ex);
            result = null;
        }
    } catch (NumberFormatException | NullPointerException ex) {
        System.err.println("\tNon number encountered where floating point number expected.");
        result = null;
    }

    return result;
}

From source file:airviewer.EllipseAnnotationMaker.java

License:Apache License

/**
 * /*  www  . ja v a  2  s . c om*/
 * @param document
 * @param arguments(pageNumber, lowerLeftX, lowerLeftY, width, height, contents)
 * @return 
 */
public static List<PDAnnotation> make(PDDocument document, ArrayList<String> arguments) {
    assert null != arguments && arguments.size() == 6;
    assert null != document;

    List<PDAnnotation> result;

    try {
        int pageNumber = parseInt(arguments.get(0));
        float lowerLeftX = parseFloat(arguments.get(1));
        float lowerLeftY = parseFloat(arguments.get(2));
        float width = parseFloat(arguments.get(3));
        float height = parseFloat(arguments.get(4));
        String contents = arguments.get(5);

        PDFont font = PDType1Font.HELVETICA_OBLIQUE;
        final float fontSize = 16.0f; // Or whatever font size you want.
        //final float lineSpacing = 4.0f;
        width = max(width, font.getStringWidth(contents) * fontSize / 1000.0f);
        //final float textHeight = fontSize + lineSpacing;

        try {
            PDPage page = document.getPage(pageNumber);
            PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
            PDColor black = new PDColor(new float[] { 0, 0, 0 }, PDDeviceRGB.INSTANCE);
            PDBorderStyleDictionary borderThick = new PDBorderStyleDictionary();
            borderThick.setWidth(72 / 12); // 12th inch
            PDRectangle position = new PDRectangle();
            position.setLowerLeftX(lowerLeftX);
            position.setLowerLeftY(lowerLeftY);
            position.setUpperRightX(lowerLeftX + width);
            position.setUpperRightY(lowerLeftY + height);

            PDAnnotationSquareCircle aCircle = new PDAnnotationSquareCircle(
                    PDAnnotationSquareCircle.SUB_TYPE_CIRCLE);
            aCircle.setAnnotationName(new UID().toString());
            aCircle.setContents(contents);
            PDColor fillColor = new PDColor(new float[] { .8f, .8f, .8f }, PDDeviceRGB.INSTANCE);
            aCircle.setInteriorColor(fillColor);
            aCircle.setColor(red);
            aCircle.setBorderStyle(borderThick);
            aCircle.setRectangle(position);

            result = new ArrayList<>(page.getAnnotations()); // Copy
            page.getAnnotations().add(aCircle);

            // The following lines are needed for PDFRenderer to render 
            // annotations. Preview and Acrobat don't seem to need these.
            if (null == aCircle.getAppearance()) {
                aCircle.setAppearance(new PDAppearanceDictionary());
                PDAppearanceStream annotationAppearanceStream = new PDAppearanceStream(document);
                position.setLowerLeftX(lowerLeftX - borderThick.getWidth() * 0.5f);
                position.setLowerLeftY(lowerLeftY - borderThick.getWidth() * 0.5f);
                position.setUpperRightX(lowerLeftX + width + borderThick.getWidth() * 0.5f);
                position.setUpperRightY(lowerLeftY + height + borderThick.getWidth() * 0.5f);
                annotationAppearanceStream.setBBox(position);
                annotationAppearanceStream.setMatrix(new AffineTransform());
                annotationAppearanceStream.setResources(page.getResources());

                try (PDPageContentStream appearanceContent = new PDPageContentStream(document,
                        annotationAppearanceStream)) {
                    Matrix transform = new Matrix();
                    appearanceContent.transform(transform);
                    appearanceContent.moveTo(lowerLeftX, lowerLeftY + height * 0.5f);
                    appearanceContent.curveTo(lowerLeftX, lowerLeftY + height * 0.75f,
                            lowerLeftX + width * 0.25f, lowerLeftY + height, lowerLeftX + width * 0.5f,
                            lowerLeftY + height);
                    appearanceContent.curveTo(lowerLeftX + width * 0.75f, lowerLeftY + height,
                            lowerLeftX + width, lowerLeftY + height * 0.75f, lowerLeftX + width,
                            lowerLeftY + height * 0.5f);
                    appearanceContent.curveTo(lowerLeftX + width, lowerLeftY + height * 0.25f,
                            lowerLeftX + width * 0.75f, lowerLeftY, lowerLeftX + width * 0.5f, lowerLeftY);
                    appearanceContent.curveTo(lowerLeftX + width * 0.25f, lowerLeftY, lowerLeftX,
                            lowerLeftY + height * 0.25f, lowerLeftX, lowerLeftY + height * 0.5f);
                    appearanceContent.setLineWidth(borderThick.getWidth());
                    appearanceContent.setNonStrokingColor(fillColor);
                    appearanceContent.setStrokingColor(red);
                    appearanceContent.fillAndStroke();
                    appearanceContent.moveTo(0, 0);

                    appearanceContent.beginText();
                    appearanceContent.setNonStrokingColor(black);
                    // Center text vertically, left justified
                    appearanceContent.newLineAtOffset(lowerLeftX + borderThick.getWidth(),
                            lowerLeftY + height * 0.5f - fontSize * 0.5f);
                    appearanceContent.setFont(font, fontSize);
                    appearanceContent.showText(contents);
                    appearanceContent.endText();
                }
                aCircle.getAppearance().setNormalAppearance(annotationAppearanceStream);
            }

        } catch (IOException ex) {
            Logger.getLogger(DocumentCommandWrapper.class.getName()).log(Level.SEVERE, null, ex);
            result = null;
        }
    } catch (NumberFormatException | NullPointerException ex) {
        System.err.println("Non number encountered where floating point number expected.");
        result = null;
    } catch (IOException ex) {
        Logger.getLogger(EllipseAnnotationMaker.class.getName()).log(Level.SEVERE, null, ex);
        result = null;
    }

    return result;
}

From source file:airviewer.TextAnnotationMaker.java

License:Apache License

/**
 * //from w  w w.  j  a v a2  s. c  o m
 * @param document
 * @param arguments(pageNumber, lowerLeftX, lowerLeftY);
        
    String contents 
 * @return 
 */
public static List<PDAnnotation> make(PDDocument document, ArrayList<String> arguments) {
    assert null != arguments && arguments.size() == 4;
    assert null != document;

    List<PDAnnotation> result;

    try {
        int pageNumber = parseInt(arguments.get(0));
        float lowerLeftX = parseFloat(arguments.get(1));
        float lowerLeftY = parseFloat(arguments.get(2));

        String contents = arguments.get(3);
        PDFont font = PDType1Font.HELVETICA_OBLIQUE;
        final float fontSize = 16.0f; // Or whatever font size you want.
        final float lineSpacing = 4.0f;
        float width = font.getStringWidth(contents) * fontSize / 1000.0f; // font.getStringWidth(contents) returns thousanths of PS point
        final float textHeight = fontSize + lineSpacing;

        try {
            PDPage page = document.getPage(pageNumber);
            PDColor red = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
            PDBorderStyleDictionary borderThick = new PDBorderStyleDictionary();
            borderThick.setWidth(72 / 12); // 12th inch
            PDRectangle position = new PDRectangle();
            position.setLowerLeftX(lowerLeftX);
            position.setLowerLeftY(lowerLeftY);
            position.setUpperRightX(lowerLeftX + width);
            position.setUpperRightY(lowerLeftY + textHeight);

            PDAnnotationSquareCircle aSquare = new PDAnnotationSquareCircle(
                    PDAnnotationSquareCircle.SUB_TYPE_SQUARE);
            aSquare.setAnnotationName(new UID().toString());
            aSquare.setContents(contents);
            PDColor fillColor = new PDColor(new float[] { .8f, .8f, .8f }, PDDeviceRGB.INSTANCE);
            aSquare.setInteriorColor(fillColor);
            aSquare.setRectangle(position);
            result = new ArrayList<>(page.getAnnotations()); // copy
            page.getAnnotations().add(aSquare);

            // The following lines are needed for PDFRenderer to render 
            // annotations. Preview and Acrobat don't seem to need these.
            if (null == aSquare.getAppearance()) {
                aSquare.setAppearance(new PDAppearanceDictionary());
                PDAppearanceStream annotationAppearanceStream = new PDAppearanceStream(document);
                position.setLowerLeftX(lowerLeftX - borderThick.getWidth() * 0.5f);
                position.setLowerLeftY(lowerLeftY - borderThick.getWidth() * 0.5f);
                position.setUpperRightX(lowerLeftX + width + borderThick.getWidth() * 0.5f);
                position.setUpperRightY(lowerLeftY + textHeight + borderThick.getWidth() * 0.5f);
                annotationAppearanceStream.setBBox(position);
                annotationAppearanceStream.setMatrix(new AffineTransform());
                annotationAppearanceStream.setResources(page.getResources());

                try (PDPageContentStream appearanceContent = new PDPageContentStream(document,
                        annotationAppearanceStream)) {
                    Matrix transform = new Matrix();
                    appearanceContent.transform(transform);
                    appearanceContent.addRect(lowerLeftX, lowerLeftY, width, textHeight);
                    appearanceContent.setNonStrokingColor(fillColor);
                    appearanceContent.fill();
                    appearanceContent.beginText();

                    // Center text vertically, left justified
                    appearanceContent.newLineAtOffset(lowerLeftX,
                            lowerLeftY + textHeight * 0.5f - fontSize * 0.5f);
                    appearanceContent.setFont(font, fontSize);
                    appearanceContent.setNonStrokingColor(red);
                    appearanceContent.showText(contents);
                    appearanceContent.endText();
                }
                aSquare.getAppearance().setNormalAppearance(annotationAppearanceStream);
            }
            //System.out.println(page.getAnnotations().toString());

        } catch (IOException ex) {
            Logger.getLogger(DocumentCommandWrapper.class.getName()).log(Level.SEVERE, null, ex);
            result = null;
        }
    } catch (NumberFormatException | NullPointerException ex) {
        System.err.println("Non number encountered where floating point number expected.");
        result = null;
    } catch (IOException ex) {
        Logger.getLogger(TextAnnotationMaker.class.getName()).log(Level.SEVERE, null, ex);
        result = null;
    }

    return result;
}

From source file:com.baseprogramming.pdwriter.html.HtmlStyle.java

License:Apache License

private void createFontMap() {
    fontMap = new HashMap<>();
    fontMap.put("TIMES NEW ROMAN", PDType1Font.TIMES_ROMAN);
    fontMap.put("TIMES NEW ROMAN_BOLD", PDType1Font.TIMES_BOLD);
    fontMap.put("TIMES NEW ROMAN_ITALIC", PDType1Font.TIMES_ITALIC);
    fontMap.put("TIMES NEW ROMAN_OBLIQUE", PDType1Font.TIMES_ITALIC);
    fontMap.put("TIMES NEW ROMAN_BOLD_ITALIC", PDType1Font.TIMES_BOLD_ITALIC);

    fontMap.put("COURIER", PDType1Font.COURIER);
    fontMap.put("COURIER_BOLD", PDType1Font.COURIER_BOLD);
    fontMap.put("COURIER_ITALIC", PDType1Font.COURIER_OBLIQUE);
    fontMap.put("COURIER_OBLIQUE", PDType1Font.COURIER_OBLIQUE);
    fontMap.put("COURIER_BOLD_ITALIC", PDType1Font.COURIER_BOLD_OBLIQUE);

    fontMap.put("HELVATICA", PDType1Font.TIMES_ROMAN);
    fontMap.put("HELVATICA_ITALIC", PDType1Font.HELVETICA_BOLD);
    fontMap.put("HELVATICA_OBLIQUE", PDType1Font.HELVETICA_BOLD);
    fontMap.put("HELVATICA_BOLD_ITALIC", PDType1Font.HELVETICA_OBLIQUE);
    fontMap.put("HELVATICA_BOLD_ITALIC", PDType1Font.HELVETICA_BOLD_OBLIQUE);
}

From source file:controldeadministradores.Admin.java

public void crearPDF(String file, String body) throws Exception {
    String outputFileName = file + ".pdf";
    //        if (args.length > 0)
    //            outputFileName = args[0];

    // Create a document and add a page to it
    PDDocument document = new PDDocument();
    PDPage page1 = new PDPage(PDPage.PAGE_SIZE_A4);
    // PDPage.PAGE_SIZE_LETTER is also possible
    PDRectangle rect = page1.getMediaBox();
    // rect can be used to get the page width and height
    document.addPage(page1);//from   w w  w .j  av a  2 s  . c  om

    // Create a new font object selecting one of the PDF base fonts
    PDFont fontPlain = PDType1Font.HELVETICA;
    PDFont fontBold = PDType1Font.HELVETICA_BOLD;
    PDFont fontItalic = PDType1Font.HELVETICA_OBLIQUE;
    PDFont fontMono = PDType1Font.COURIER;

    // Start a new content stream which will "hold" the to be created content
    PDPageContentStream cos = new PDPageContentStream(document, page1);

    int line = 0;

    // Define a text content stream using the selected font, move the cursor and draw some text
    cos.beginText();
    cos.setFont(fontPlain, 14);
    cos.moveTextPositionByAmount(100, rect.getHeight() - 50 * (++line));
    cos.drawString("Reporte de " + file);
    cos.endText();

    String[] txtLine = body.split("-");
    for (int k = 0; k < txtLine.length; k++) {
        cos.beginText();
        cos.setFont(fontPlain, 12);
        cos.moveTextPositionByAmount(100, rect.getHeight() - 50 * (++line));
        cos.drawString(txtLine[k]);
        cos.endText();
        cos.close();
    }

    // Make sure that the content stream is closed:

    // Save the results and ensure that the document is properly closed:
    document.save(outputFileName);
    document.close();
}

From source file:geotheme.pdf.generatePDF.java

License:Open Source License

public ByteArrayOutputStream createPDFFromImage(wmsParamBean wpb, String host)
        throws IOException, COSVisitorException {
    PDDocument doc = null;/*from ww  w  . j  av a2s  .  c om*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    OutputStreamWriter wr = null;
    OutputStreamWriter wl = null;
    URLConnection geoConn = null;
    URLConnection legConn = null;

    int width = 500;
    int height = 500;

    wpb.setBBOX(retainAspectRatio(wpb.getBBOX()));

    StringBuffer sb = new StringBuffer();
    sb.append(this.pdfURL);
    sb.append("&layers=").append(this.pdfLayers);
    sb.append("&bbox=").append(wpb.getBBOX());
    sb.append("&Format=image/jpeg");
    sb.append("&width=").append(width);
    sb.append("&height=").append(height);

    try {
        wpb.setREQUEST("GetMap");
        wpb.setWIDTH(Integer.toString(width));
        wpb.setHEIGHT(Integer.toString(height));

        URL url = new URL(host);
        URL urll = new URL(host);
        URL osm = new URL(sb.toString());

        geoConn = url.openConnection();
        geoConn.setDoOutput(true);

        legConn = urll.openConnection();
        legConn.setDoOutput(true);

        wr = new OutputStreamWriter(geoConn.getOutputStream(), "UTF-8");
        wr.write(wpb.getURL_PARAM());

        wr.flush();

        wpb.setREQUEST("GetLegendGraphic");
        wpb.setTRANSPARENT("FALSE");
        wpb.setWIDTH("");
        wpb.setHEIGHT("");

        wl = new OutputStreamWriter(legConn.getOutputStream(), "UTF-8");
        wl.write(wpb.getURL_PARAM() + "&legend_options=fontSize:9;");
        wl.flush();

        doc = new PDDocument();

        PDPage page = new PDPage(/*PDPage.PAGE_SIZE_A4*/);
        doc.addPage(page);

        BufferedImage img = ImageIO.read(geoConn.getInputStream());
        BufferedImage leg = ImageIO.read(legConn.getInputStream());

        PDXObjectImage ximage = new PDPixelMap(doc, img);
        PDXObjectImage xlegend = new PDPixelMap(doc, leg);
        PDXObjectImage xosm = new PDJpeg(doc, osm.openStream());

        PDPageContentStream contentStream = new PDPageContentStream(doc, page);

        PDFont font = PDType1Font.HELVETICA_OBLIQUE;

        contentStream.beginText();
        contentStream.setFont(font, 8);
        contentStream.moveTextPositionByAmount(450, 10);
        Date date = new Date();
        contentStream.drawString(date.toString());
        contentStream.endText();

        contentStream.beginText();
        contentStream.setFont(font, 8);
        contentStream.moveTextPositionByAmount(10, 10);
        contentStream.drawString("GeoFuse Report: mario.basa@gmail.com");
        contentStream.endText();

        contentStream.drawImage(xosm, 20, 160);
        contentStream.drawImage(ximage, 20, 160);
        contentStream.drawImage(xlegend, width - xlegend.getWidth() - 3, 170);

        contentStream.beginText();
        contentStream.setFont(font, 50);
        contentStream.moveTextPositionByAmount(20, 720);
        contentStream.drawString(wpb.getPDF_TITLE());
        contentStream.endText();

        contentStream.beginText();
        contentStream.setFont(font, 18);
        contentStream.moveTextPositionByAmount(20, 695);
        contentStream.drawString(wpb.getPDF_NOTE());
        contentStream.endText();

        contentStream.setStrokingColor(180, 180, 180);

        float bx[] = { 10f, 10f, 30 + width, 30 + width, 10f };
        float by[] = { 150f, 170 + height, 170 + height, 150f, 150f };
        contentStream.drawPolygon(bx, by);

        contentStream.close();

        doc.save(baos);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (doc != null) {
            doc.close();
        }

        if (wr != null) {
            wr.close();
        }

        if (wl != null) {
            wl.close();
        }
    }

    return baos;
}

From source file:org.dspace.disseminate.CitationDocument.java

License:BSD License

private void generateCoverPage(PDDocument document, PDPage coverPage, Item item)
        throws IOException, COSVisitorException {
    PDPageContentStream contentStream = new PDPageContentStream(document, coverPage);
    try {/*from   w ww . jav  a 2 s. c  om*/
        int ypos = 760;
        int xpos = 30;
        int xwidth = 550;
        int ygap = 20;

        PDFont fontHelvetica = PDType1Font.HELVETICA;
        PDFont fontHelveticaBold = PDType1Font.HELVETICA_BOLD;
        PDFont fontHelveticaOblique = PDType1Font.HELVETICA_OBLIQUE;
        contentStream.setNonStrokingColor(Color.BLACK);

        String[][] content = { header1 };
        drawTable(coverPage, contentStream, ypos, xpos, content, fontHelveticaBold, 11, false);
        ypos -= (ygap);

        String[][] content2 = { header2 };
        drawTable(coverPage, contentStream, ypos, xpos, content2, fontHelveticaBold, 11, false);
        ypos -= ygap;

        contentStream.fillRect(xpos, ypos, xwidth, 1);
        contentStream.closeAndStroke();

        String[][] content3 = { { getOwningCommunity(item), getOwningCollection(item) } };
        drawTable(coverPage, contentStream, ypos, xpos, content3, fontHelvetica, 9, false);
        ypos -= ygap;

        contentStream.fillRect(xpos, ypos, xwidth, 1);
        contentStream.closeAndStroke();
        ypos -= (ygap * 2);

        for (String field : fields) {
            field = field.trim();
            PDFont font = fontHelvetica;
            int fontSize = 11;
            if (field.contains("title")) {
                fontSize = 26;
                ypos -= ygap;
            } else if (field.contains("creator") || field.contains("contributor")) {
                fontSize = 16;
            }

            if (field.equals("_line_")) {
                contentStream.fillRect(xpos, ypos, xwidth, 1);
                contentStream.closeAndStroke();
                ypos -= (ygap);

            } else if (StringUtils.isNotEmpty(item.getMetadata(field))) {
                ypos = drawStringWordWrap(coverPage, contentStream, item.getMetadata(field), xpos, ypos, font,
                        fontSize);
            }

            if (field.contains("title")) {
                ypos -= ygap;
            }
        }

        contentStream.beginText();
        contentStream.setFont(fontHelveticaOblique, 11);
        contentStream.moveTextPositionByAmount(xpos, ypos);
        contentStream.drawString(footer);
        contentStream.endText();
    } finally {
        contentStream.close();
    }
}

From source file:org.dspace.disseminate.CitationDocumentServiceImpl.java

License:BSD License

protected void generateCoverPage(Context context, PDDocument document, PDPage coverPage, Item item)
        throws IOException {
    PDPageContentStream contentStream = new PDPageContentStream(document, coverPage);
    try {//from  ww w.j av a2  s . c o m
        int ypos = 760;
        int xpos = 30;
        int xwidth = 550;
        int ygap = 20;

        PDFont fontHelvetica = PDType1Font.HELVETICA;
        PDFont fontHelveticaBold = PDType1Font.HELVETICA_BOLD;
        PDFont fontHelveticaOblique = PDType1Font.HELVETICA_OBLIQUE;
        contentStream.setNonStrokingColor(Color.BLACK);

        String[][] content = { header1 };
        drawTable(coverPage, contentStream, ypos, xpos, content, fontHelveticaBold, 11, false);
        ypos -= (ygap);

        String[][] content2 = { header2 };
        drawTable(coverPage, contentStream, ypos, xpos, content2, fontHelveticaBold, 11, false);
        ypos -= ygap;

        contentStream.fillRect(xpos, ypos, xwidth, 1);
        contentStream.closeAndStroke();

        String[][] content3 = { { getOwningCommunity(context, item), getOwningCollection(item) } };
        drawTable(coverPage, contentStream, ypos, xpos, content3, fontHelvetica, 9, false);
        ypos -= ygap;

        contentStream.fillRect(xpos, ypos, xwidth, 1);
        contentStream.closeAndStroke();
        ypos -= (ygap * 2);

        for (String field : fields) {
            field = field.trim();
            PDFont font = fontHelvetica;
            int fontSize = 11;
            if (field.contains("title")) {
                fontSize = 26;
                ypos -= ygap;
            } else if (field.contains("creator") || field.contains("contributor")) {
                fontSize = 16;
            }

            if (field.equals("_line_")) {
                contentStream.fillRect(xpos, ypos, xwidth, 1);
                contentStream.closeAndStroke();
                ypos -= (ygap);

            } else if (StringUtils.isNotEmpty(itemService.getMetadata(item, field))) {
                ypos = drawStringWordWrap(coverPage, contentStream, itemService.getMetadata(item, field), xpos,
                        ypos, font, fontSize);
            }

            if (field.contains("title")) {
                ypos -= ygap;
            }
        }

        contentStream.beginText();
        contentStream.setFont(fontHelveticaOblique, 11);
        contentStream.moveTextPositionByAmount(xpos, ypos);
        contentStream.drawString(footer);
        contentStream.endText();
    } finally {
        contentStream.close();
    }
}

From source file:org.fit.cssbox.render.PDFRenderer.java

License:Open Source License

private PDFont tryBuiltinFallback(String fontFamily, boolean isItalic, boolean isBold) {
    PDFont font;//from  ww w  . java 2 s . com

    fontFamily = fontFamily.toLowerCase();
    switch (fontFamily) {
    case "courier":
    case "courier new":
    case "lucida console":
        if (isBold && isItalic) {
            font = PDType1Font.COURIER_BOLD_OBLIQUE;
        } else if (isBold) {
            font = PDType1Font.COURIER_BOLD;
        } else if (isItalic) {
            font = PDType1Font.COURIER_OBLIQUE;
        } else {
            font = PDType1Font.COURIER;
        }
        break;
    case "times":
    case "garamond":
    case "georgia":
    case "times new roman":
    case "serif":
        if (isBold && isItalic) {
            font = PDType1Font.TIMES_BOLD_ITALIC;
        } else if (isBold) {
            font = PDType1Font.TIMES_BOLD;
        } else if (isItalic) {
            font = PDType1Font.TIMES_ITALIC;
        } else {
            font = PDType1Font.TIMES_ROMAN;
        }
        break;
    default:
        if (isBold && isItalic) {
            font = PDType1Font.HELVETICA_BOLD_OBLIQUE;
        } else if (isBold) {
            font = PDType1Font.HELVETICA_BOLD;
        } else if (isItalic) {
            font = PDType1Font.HELVETICA_OBLIQUE;
        } else {
            font = PDType1Font.HELVETICA;
        }
        break;
    }
    return font;
}

From source file:org.gfbio.idmg.util.PDFUtil.java

private void toggleTextColorAndType(PDPageContentStream content, boolean oblique) throws IOException {
    if (!oblique) {
        content.setNonStrokingColor(Color.GRAY);
        content.setFont(PDType1Font.HELVETICA_OBLIQUE, 11);
    } else {// w  w  w .  ja  va  2  s  .c o  m
        content.setNonStrokingColor(51, 90, 163);
        content.setFont(boldFont, 11);
    }
}