Search in sources :

Example 1 with Image

use of com.itextpdf.text.Image in project summer-bean by cn-cerc.

the class BarcodeDemo2 method createPdf.

public void createPdf(String filename) throws IOException, DocumentException {
    BaseFont bf = null;
    Font fontChinese = null;
    try {
        // 使用iTextAsian.jar中的字体
        bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 使用Windows系统字体(TrueType)
        // BaseFont.createFont("C:/WINDOWS/Fonts/SIMYOU.TTF",
        // BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
        // 使用资源字体(ClassPath)
        // BaseFont.createFont("/SIMYOU.TTF",
        // BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
        fontChinese = new Font(bf, 12, Font.NORMAL);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // step 1
    Document document = new Document(new Rectangle(340, 842));
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();
    document.add(new Paragraph("各类条码生成范例:", fontChinese));
    // EAN 13
    document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();
    codeEAN.setCode("4512345678906");
    document.add(new Paragraph("default:"));
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setGuardBars(false);
    document.add(new Paragraph("without guard bars"));
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setBaseline(-1f);
    codeEAN.setGuardBars(true);
    document.add(new Paragraph("text above:"));
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setBaseline(codeEAN.getSize());
    // UPC A
    document.add(new Paragraph("Barcode UCC-12 (UPC-A)"));
    codeEAN.setCodeType(Barcode.UPCA);
    codeEAN.setCode("785342304749");
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    // EAN 8
    document.add(new Paragraph("Barcode EAN.UCC-8"));
    codeEAN.setCodeType(Barcode.EAN8);
    codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    codeEAN.setCode("34569870");
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    // UPC E
    document.add(new Paragraph("Barcode UPC-E"));
    codeEAN.setCodeType(Barcode.UPCE);
    codeEAN.setCode("03456781");
    document.add(codeEAN.createImageWithBarcode(cb, null, null));
    codeEAN.setBarHeight(codeEAN.getSize() * 3f);
    // EANSUPP
    document.add(new Paragraph("Bookland"));
    document.add(new Paragraph("ISBN 0-321-30474-8"));
    codeEAN.setCodeType(Barcode.EAN13);
    codeEAN.setCode("9781935182610");
    BarcodeEAN codeSUPP = new BarcodeEAN();
    codeSUPP.setCodeType(Barcode.SUPP5);
    codeSUPP.setCode("55999");
    codeSUPP.setBaseline(-2);
    BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
    document.add(eanSupp.createImageWithBarcode(cb, null, BaseColor.BLUE));
    // CODE 128
    document.add(new Paragraph("Barcode 128"));
    Barcode128 code128 = new Barcode128();
    code128.setCode("0123456789 hello");
    document.add(code128.createImageWithBarcode(cb, null, null));
    code128.setCode("0123456789\uffffMy Raw Barcode (0 - 9)");
    code128.setCodeType(Barcode.CODE128_RAW);
    document.add(code128.createImageWithBarcode(cb, null, null));
    // Data for the barcode :
    String code402 = "24132399420058289";
    String code90 = "3700000050";
    String code421 = "422356";
    StringBuffer data = new StringBuffer(code402);
    data.append(Barcode128.FNC1);
    data.append(code90);
    data.append(Barcode128.FNC1);
    data.append(code421);
    Barcode128 shipBarCode = new Barcode128();
    shipBarCode.setX(0.75f);
    shipBarCode.setN(1.5f);
    shipBarCode.setSize(10f);
    shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
    shipBarCode.setBaseline(10f);
    shipBarCode.setBarHeight(50f);
    shipBarCode.setCode(data.toString());
    document.add(shipBarCode.createImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLUE));
    // it is composed of 3 blocks whith AI 01, 3101 and 10
    Barcode128 uccEan128 = new Barcode128();
    uccEan128.setCodeType(Barcode.CODE128_UCC);
    uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
    document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.BLACK));
    uccEan128.setCode("0191234567890121310100035510ABC123");
    document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.RED));
    uccEan128.setCode("(01)28880123456788");
    document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.BLACK));
    // INTER25
    document.add(new Paragraph("Barcode Interleaved 2 of 5"));
    BarcodeInter25 code25 = new BarcodeInter25();
    code25.setGenerateChecksum(true);
    code25.setCode("41-1200076041-001");
    document.add(code25.createImageWithBarcode(cb, null, null));
    code25.setCode("411200076041001");
    document.add(code25.createImageWithBarcode(cb, null, null));
    code25.setCode("0611012345678");
    code25.setChecksumText(true);
    document.add(code25.createImageWithBarcode(cb, null, null));
    // POSTNET
    document.add(new Paragraph("Barcode Postnet"));
    BarcodePostnet codePost = new BarcodePostnet();
    document.add(new Paragraph("ZIP"));
    codePost.setCode("01234");
    document.add(codePost.createImageWithBarcode(cb, null, null));
    document.add(new Paragraph("ZIP+4"));
    codePost.setCode("012345678");
    document.add(codePost.createImageWithBarcode(cb, null, null));
    document.add(new Paragraph("ZIP+4 and dp"));
    codePost.setCode("01234567890");
    document.add(codePost.createImageWithBarcode(cb, null, null));
    document.add(new Paragraph("Barcode Planet"));
    BarcodePostnet codePlanet = new BarcodePostnet();
    codePlanet.setCode("01234567890");
    codePlanet.setCodeType(Barcode.PLANET);
    document.add(codePlanet.createImageWithBarcode(cb, null, null));
    // CODE 39
    document.add(new Paragraph("Barcode 3 of 9"));
    Barcode39 code39 = new Barcode39();
    code39.setCode("ITEXT IN ACTION");
    document.add(code39.createImageWithBarcode(cb, null, null));
    document.add(new Paragraph("Barcode 3 of 9 extended"));
    Barcode39 code39ext = new Barcode39();
    code39ext.setCode("iText in Action");
    code39ext.setStartStopText(false);
    code39ext.setExtended(true);
    document.add(code39ext.createImageWithBarcode(cb, null, null));
    // CODABAR
    document.add(new Paragraph("Codabar"));
    BarcodeCodabar codabar = new BarcodeCodabar();
    codabar.setCode("A123A");
    codabar.setStartStopText(true);
    document.add(codabar.createImageWithBarcode(cb, null, null));
    // PDF417
    document.add(new Paragraph("Barcode PDF417"));
    BarcodePDF417 pdf417 = new BarcodePDF417();
    String text = "Call me Ishmael. Some years ago--never mind how long " + "precisely --having little or no money in my purse, and nothing " + "particular to interest me on shore, I thought I would sail about " + "a little and see the watery part of the world.";
    pdf417.setText(text);
    Image img = pdf417.getImage();
    img.scalePercent(50, 50 * pdf417.getYHeight());
    document.add(img);
    document.add(new Paragraph("Barcode Datamatrix"));
    BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();
    datamatrix.generate(text);
    img = datamatrix.createImage();
    document.add(img);
    document.add(new Paragraph("Barcode QRCode"));
    BarcodeQRCode qrcode = new BarcodeQRCode("http://www.mimrc.com", 1, 1, null);
    img = qrcode.getImage();
    document.add(img);
    // step 5
    document.close();
}
Also used : BarcodeEANSUPP(com.itextpdf.text.pdf.BarcodeEANSUPP) PdfWriter(com.itextpdf.text.pdf.PdfWriter) BarcodeQRCode(com.itextpdf.text.pdf.BarcodeQRCode) BarcodeInter25(com.itextpdf.text.pdf.BarcodeInter25) BarcodePDF417(com.itextpdf.text.pdf.BarcodePDF417) Rectangle(com.itextpdf.text.Rectangle) IOException(java.io.IOException) Document(com.itextpdf.text.Document) BarcodePostnet(com.itextpdf.text.pdf.BarcodePostnet) Image(com.itextpdf.text.Image) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) BarcodeCodabar(com.itextpdf.text.pdf.BarcodeCodabar) Paragraph(com.itextpdf.text.Paragraph) Barcode39(com.itextpdf.text.pdf.Barcode39) Barcode128(com.itextpdf.text.pdf.Barcode128) BarcodeEAN(com.itextpdf.text.pdf.BarcodeEAN) DocumentException(com.itextpdf.text.DocumentException) FileOutputStream(java.io.FileOutputStream) BarcodeDatamatrix(com.itextpdf.text.pdf.BarcodeDatamatrix) BaseFont(com.itextpdf.text.pdf.BaseFont) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte)

Example 2 with Image

use of com.itextpdf.text.Image in project bamboobsc by billchen198318.

the class KpiReportPdfCommand method createDateRange.

private void createDateRange(PdfPTable table, VisionVO vision, Context context, int maxRows) throws Exception {
    String frequency = (String) context.get("frequency");
    String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim();
    String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim();
    String startDate = StringUtils.defaultString((String) context.get("startDate")).trim();
    String endDate = StringUtils.defaultString((String) context.get("endDate")).trim();
    String date1 = startDate;
    String date2 = endDate;
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        date1 = startYearDate + "/01/01";
        date2 = endYearDate + "/12/" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12);
    }
    Map<String, Object> headContentMap = new HashMap<String, Object>();
    this.fillHeadContent(context, headContentMap);
    String content = "Frequency: " + BscMeasureDataFrequency.getFrequencyMap(false).get(frequency) + " Date range: " + date1 + " ~ " + date2 + "\n" + StringUtils.defaultString((String) headContentMap.get("headContent"));
    PdfPCell cell = null;
    cell = new PdfPCell();
    cell.addElement(new Phrase(content, this.getFont(BscReportPropertyUtils.getFontColor(), false)));
    this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor());
    cell.setColspan(maxRows);
    table.addCell(cell);
    for (PerspectiveVO perspective : vision.getPerspectives()) {
        for (ObjectiveVO objective : perspective.getObjectives()) {
            for (KpiVO kpi : objective.getKpis()) {
                cell = new PdfPCell();
                cell.addElement(new Phrase(kpi.getName(), this.getFont(kpi.getFontColor(), false)));
                this.setCellBackgroundColor(cell, kpi.getBgColor());
                cell.setColspan(4);
                cell.setRowspan(2);
                table.addCell(cell);
                for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
                    cell = new PdfPCell();
                    cell.addElement(new Phrase(dateScore.getDate(), this.getFont(dateScore.getFontColor(), false)));
                    this.setCellBackgroundColor(cell, dateScore.getBgColor());
                    table.addCell(cell);
                }
                for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
                    Image image = Image.getInstance(BscReportSupportUtils.getByteIcon(kpi, dateScore.getScore()));
                    image.setWidthPercentage(20f);
                    cell = new PdfPCell();
                    cell.addElement(new Phrase(BscReportSupportUtils.parse2(dateScore.getScore()), this.getFont(dateScore.getFontColor(), false)));
                    cell.addElement(image);
                    this.setCellBackgroundColor(cell, dateScore.getBgColor());
                    table.addCell(cell);
                }
            }
        }
    }
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) HashMap(java.util.HashMap) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) DateRangeScoreVO(com.netsteadfast.greenstep.vo.DateRangeScoreVO) Phrase(com.itextpdf.text.Phrase) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) BufferedImage(java.awt.image.BufferedImage) Image(com.itextpdf.text.Image)

Example 3 with Image

use of com.itextpdf.text.Image in project MtgDesktopCompanion by nicho92.

the class PDFExport method getCells.

private PdfPCell getCells(MagicCard card) throws BadElementException, IOException {
    Image image1 = null;
    try {
        image1 = Image.getInstance(MTGControler.getInstance().getEnabledPicturesProvider().getPicture(card, null), null);
    } catch (Exception e) {
        image1 = Image.getInstance(MTGControler.getInstance().getEnabledPicturesProvider().getBackPicture(), null);
    }
    image1.scalePercent(60);
    PdfPCell cell = new PdfPCell(image1, false);
    cell.setBorder(0);
    cell.setPadding(5);
    return cell;
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) Image(com.itextpdf.text.Image) NotImplementedException(org.apache.commons.lang3.NotImplementedException) BadElementException(com.itextpdf.text.BadElementException) IOException(java.io.IOException)

Example 4 with Image

use of com.itextpdf.text.Image in project trainning by fernandotomasio.

the class ApostilaDECEAPageFooter method onEndPage.

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte canvas = writer.getDirectContentUnder();
    Image imageBottom;
    Image imageTop;
    Image imageCover;
    try {
        imageTop = Image.getInstance(IMAGE_TOP);
        imageTop.scaleAbsoluteHeight(42);
        imageBottom = Image.getInstance(IMAGE_BOTTOM);
        imageBottom.scaleAbsoluteHeight(14);
        imageCover = Image.getInstance(IMAGE_COVER);
        imageCover.scalePercent(30.3f);
        if (writer.getPageNumber() > 2) {
            // image.scaleAbsolute(PageSize.A4.rotate());
            imageBottom.setAbsolutePosition(0, 0);
            imageTop.setAbsolutePosition(0, 800);
            canvas.addImage(imageBottom);
            canvas.addImage(imageTop);
        } else {
            if (writer.getPageNumber() == 1) {
                imageCover.setAbsolutePosition(0, 490);
                canvas.addImage(imageCover);
            }
        }
    } catch (BadElementException ex) {
        Logger.getLogger(ApostilaDECEAPageFooter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ApostilaDECEAPageFooter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ApostilaDECEAPageFooter.class.getName()).log(Level.SEVERE, null, ex);
    }
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(527);
    table.setLockedWidth(true);
    table.getDefaultCell().setFixedHeight(20);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    if (writer.getPageNumber() > 2) {
        PdfPCell numberCell = new PdfPCell(new Phrase(String.format("%d", writer.getPageNumber()), new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 129, 201))));
        numberCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        numberCell.setBorder(Rectangle.NO_BORDER);
        table.addCell(numberCell);
    }
    table.writeSelectedRows(0, -1, 0, 34, writer.getDirectContent());
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) BaseColor(com.itextpdf.text.BaseColor) PdfPTable(com.itextpdf.text.pdf.PdfPTable) BadElementException(com.itextpdf.text.BadElementException) DocumentException(com.itextpdf.text.DocumentException) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) IOException(java.io.IOException) Phrase(com.itextpdf.text.Phrase) Image(com.itextpdf.text.Image) Font(com.itextpdf.text.Font)

Example 5 with Image

use of com.itextpdf.text.Image in project trainning by fernandotomasio.

the class DOC001PDF method buildCover.

private void buildCover(Document document, CurriculoMinimoDTO curriculoMinimo) throws DocumentException {
    Paragraph spaceParagraph = new Paragraph();
    spaceParagraph.add(new Phrase("\n"));
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    Paragraph p1 = new Paragraph();
    p1.setAlignment(Element.ALIGN_CENTER);
    p1.add(new Phrase("MINISTÉRIO DA DEFESA", fontManager.getH1Font()));
    document.add(p1);
    Paragraph p2 = new Paragraph();
    p2.setAlignment(Element.ALIGN_CENTER);
    p2.add(new Phrase("COMANDO DA AERONÁUTICA", fontManager.getH1Font()));
    document.add(p2);
    Paragraph p3 = new Paragraph();
    p3.setAlignment(Element.ALIGN_CENTER);
    // p3.add(Chunk.NEWLINE);
    // p3.add(new Phrase("DEPARTAMENTO DE CONTROLE DO ESPAÇO AÉREO", fontManager.getDefaultFont()));
    document.add(p3);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    try {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        String path = classLoader.getResource("aer.png").getPath();
        Image image = Image.getInstance(path);
        image.setAlignment(Element.ALIGN_CENTER);
        image.scalePercent(18.5f);
        document.add(image);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(DOC001PDF.class.getName()).log(Level.SEVERE, null, ex);
    }
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    Paragraph p4 = new Paragraph();
    p4.setAlignment(Element.ALIGN_CENTER);
    p4.add(new Phrase("ENSINO", fontManager.getH0Font()));
    document.add(p4);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    PdfPTable t = new PdfPTable(1);
    t.setTotalWidth(286);
    t.setLockedWidth(true);
    PdfPCell unica = new PdfPCell();
    unica.setFixedHeight(140);
    unica.setPaddingTop(5);
    unica.setVerticalAlignment(Element.ALIGN_MIDDLE);
    Paragraph p5 = new Paragraph();
    p5.setAlignment(Element.ALIGN_CENTER);
    p5.add(new Phrase(curriculoMinimo.getNumeroPublicacaoCM(), fontManager.getSmallXBoldFont()));
    Paragraph p6 = new Paragraph();
    p6.setAlignment(Element.ALIGN_CENTER);
    p6.add(new Phrase("CURRÍCULO MÍNIMO DO CURSO " + curriculoMinimo.getCurso().getDescricao(), fontManager.getSmallXBoldFont()));
    Paragraph p7 = new Paragraph();
    p7.setAlignment(Element.ALIGN_CENTER);
    p7.add(new Phrase(curriculoMinimo.getCurso().getCodigo(), fontManager.getSmallXBoldFont()));
    Paragraph p8 = new Paragraph();
    p8.setAlignment(Element.ALIGN_CENTER);
    p8.add(new Phrase(curriculoMinimo.getAnoPublicacaoCM(), fontManager.getSmallXBoldFont()));
    unica.addElement(p5);
    unica.addElement(Chunk.NEWLINE);
    unica.addElement(p6);
    unica.addElement(p7);
    unica.addElement(Chunk.NEWLINE);
    unica.addElement(p8);
    t.addCell(unica);
    document.add(t);
    // document.add(Chunk.NEXTPAGE);
    // 
    // document.add(buildPrefacio(curriculoMinimo));
    document.add(Chunk.NEXTPAGE);
    document.add(Chunk.NEXTPAGE);
}
Also used : BadElementException(com.itextpdf.text.BadElementException) Phrase(com.itextpdf.text.Phrase) IOException(java.io.IOException) Image(com.itextpdf.text.Image) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

Image (com.itextpdf.text.Image)20 PdfPCell (com.itextpdf.text.pdf.PdfPCell)10 IOException (java.io.IOException)10 BadElementException (com.itextpdf.text.BadElementException)7 Phrase (com.itextpdf.text.Phrase)7 Paragraph (com.itextpdf.text.Paragraph)5 BufferedImage (java.awt.image.BufferedImage)5 DocumentException (com.itextpdf.text.DocumentException)3 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)3 PdfPTable (com.itextpdf.text.pdf.PdfPTable)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Font (com.itextpdf.text.Font)2 PdfReader (com.itextpdf.text.pdf.PdfReader)2 PdfStamper (com.itextpdf.text.pdf.PdfStamper)2 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)2 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)2 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)2 URL (java.net.URL)2 BaseColor (com.itextpdf.text.BaseColor)1 Document (com.itextpdf.text.Document)1