Example usage for com.itextpdf.text.pdf BaseFont IDENTITY_H

List of usage examples for com.itextpdf.text.pdf BaseFont IDENTITY_H

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BaseFont IDENTITY_H.

Prototype

String IDENTITY_H

To view the source code for com.itextpdf.text.pdf BaseFont IDENTITY_H.

Click Source Link

Document

The Unicode encoding with horizontal writing.

Usage

From source file:quanlyhoadon.PDFProcess.java

public boolean printPDF(String dest, Company company, Bill bill, LinhTinh lt) {
    try {//from  w ww. j a  v a 2s . c o  m
        BaseFont urName = BaseFont.createFont("font/Time_New_Roman.TTF", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        Font nameFont = new Font(urName, 16, Font.BOLD);
        Font addFont = new Font(urName, 12);
        Font boldFont = new Font(urName, 14, Font.BOLD);
        Font contentFont = new Font(urName, 14);
        Font footFont = new Font(urName, 16);

        Document document = new Document(PageSize.A4.rotate());
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();

        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setWidths(new float[] { 2, 6, 3 });

        //logo
        Image img = Image.getInstance("logo.jpg");
        img.scaleAbsolute(100, 100);
        PdfPCell cell = new PdfPCell(img);
        cell.setBorder(PdfPCell.NO_BORDER);

        //middle content
        String name = company.getName();
        String address = "\n\n?C: " + company.getAddress();
        String phone = "\n\n?T: " + company.getPhone();
        String hed = "\n\n     PHIU B?O GI?";

        Phrase mid = new Phrase();
        mid.add(new Chunk(name, nameFont));
        mid.add(new Chunk(address + phone, addFont));
        mid.add(new Chunk(hed, nameFont));

        PdfPCell midCell = new PdfPCell(mid);
        //      midCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        midCell.setPaddingTop(15);
        midCell.setPaddingLeft(40);
        midCell.setPaddingRight(15);
        midCell.setPaddingBottom(15);
        midCell.setBorder(PdfPCell.NO_BORDER);

        // right content
        String soCt = "S CT: " + bill.getId();
        String date = "\n\nNgy: " + bill.getDate() + "\n\nKho : " + lt.getKho();

        Phrase right = new Phrase();
        right.add(new Chunk(soCt + date, addFont));
        PdfPCell rightCell = new PdfPCell(right);
        rightCell.setPadding(15);
        rightCell.setBorder(PdfPCell.NO_BORDER);

        table.addCell(cell);
        table.addCell(midCell);
        table.addCell(rightCell);

        document.add(table);

        Phrase p1 = new Phrase();
        p1.add(new Chunk("?n v: ", addFont));
        p1.add(new Chunk(lt.getDonVi(), boldFont));
        p1.add(new Chunk("\n?a Ch: \n", addFont));

        Paragraph pagra = new Paragraph(p1);
        pagra.setIndentationLeft(15);
        pagra.setSpacingBefore(10);
        pagra.setSpacingAfter(10);
        document.add(pagra);

        //table lt
        PdfPTable tablList = new PdfPTable(6);

        tablList.setWidthPercentage(100);
        tablList.setWidths(new float[] { 1, 5, 7, 2, 3, 4 });

        String title[] = { "STT", "M Hng", "Tn Hng", "SL", "?n Gi", "Thnh Ti?n" };
        for (int i = 0; i < title.length; ++i) {
            Phrase phr = new Phrase();
            phr.add(new Chunk(title[i], boldFont));
            PdfPCell p = new PdfPCell(phr);
            p.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            tablList.addCell(p);
        }
        //--- add content
        for (int i = 0; i < bill.getCount(); ++i) {
            Phrase[] phrase = new Phrase[6];
            PdfPCell[] pCell = new PdfPCell[6];

            for (int k = 0; k < 6; ++k) {
                phrase[k] = new Phrase();
            }
            phrase[0].add(new Chunk((i + 1) + "", contentFont));
            phrase[1].add(new Chunk(bill.getMaHangAt(i), contentFont));
            phrase[2].add(new Chunk(bill.getTenHangAt(i), contentFont));
            phrase[3].add(new Chunk(bill.getSoLuongAt(i) + "", contentFont));
            phrase[4].add(new Chunk(bill.getDonGiaAt(i) + "", contentFont));
            phrase[5].add(new Chunk(bill.getThanhTienAt(i) + "", contentFont));

            for (int j = 0; j < 6; ++j) {
                pCell[j] = new PdfPCell(phrase[j]);
                pCell[j].setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

                tablList.addCell(pCell[j]);
            }
        }

        PdfPCell cell1 = new PdfPCell(new Phrase(new Chunk("Tng", boldFont)));
        cell1.setColspan(3);
        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell1);

        //
        PdfPCell cell2 = new PdfPCell(new Phrase(new Chunk("" + bill.getTong(), boldFont)));
        cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell2);

        //
        PdfPCell cell3 = new PdfPCell(new Phrase(new Chunk("", boldFont)));
        cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell3);

        //
        PdfPCell cell4 = new PdfPCell(new Phrase(new Chunk(String.format("%,d", bill.tongTien()), boldFont)));
        cell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        tablList.addCell(cell4);

        document.add(tablList);
        //-------------------in phuong thuc thanh toan
        Phrase p2 = new Phrase();
        p2.add(new Chunk("Phng thc thanh ton: ", contentFont));
        p2.add(new Chunk(lt.getThanhToan(), boldFont));
        p2.add(new Chunk("\nLu  mua hng min tr li. Vui lng gi phiu trong 7 ngy: ",
                contentFont));

        Paragraph pagra2 = new Paragraph(p2);
        pagra2.setSpacingBefore(5);
        pagra2.setSpacingAfter(5);
        document.add(pagra2);

        //---- footer content
        PdfPTable tblFoot = new PdfPTable(3);

        tblFoot.setWidthPercentage(100);
        tblFoot.setWidths(new float[] { 1, 1, 1 });

        PdfPCell leftFootCell = new PdfPCell(new Phrase(new Chunk("NGI LP ", footFont)));
        PdfPCell midFootCell = new PdfPCell(new Phrase(new Chunk("K TO?N ", footFont)));
        PdfPCell rightFootCell = new PdfPCell(new Phrase(new Chunk("TH TRNG ?N V ", footFont)));

        leftFootCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        leftFootCell.setBorder(PdfPCell.NO_BORDER);
        midFootCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        midFootCell.setBorder(PdfPCell.NO_BORDER);
        rightFootCell.setBorder(PdfPCell.NO_BORDER);
        rightFootCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        tblFoot.addCell(leftFootCell);
        tblFoot.addCell(midFootCell);
        tblFoot.addCell(rightFootCell);

        document.add(tblFoot);

        //
        document.close();
        JOptionPane.showMessageDialog(null, "In hoadon.pdf thnh cng");
        return true;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "hoadon.pdf ang c m\nVui lng ng li. Sau  th li");
        e.printStackTrace();
        return false;
    }
}

From source file:ru.trett.cis.services.PDFBuilderImpl.java

License:Open Source License

@Override
public String createPDF() throws IOException, DocumentException, ApplicationException {
    try {//from w  ww  .  ja  va2  s.  c  o m
        String templatePath = servletContext.getRealPath("WEB-INF/resources/template-settings.xml");
        Map<String, List<String>> data = TemplateParser.parse(new File(templatePath));
        String regularFontPath = servletContext.getRealPath("WEB-INF/resources/fonts/OpenSans-Regular.ttf");
        if (regularFontPath == null)
            throw new ApplicationException("Regular Font file was not found");
        BaseFont bfr = BaseFont.createFont(regularFontPath, BaseFont.IDENTITY_H, true);
        String boldFontPath = servletContext.getRealPath("WEB-INF/resources/fonts/OpenSans-Bold.ttf");
        if (boldFontPath == null)
            throw new ApplicationException("Bold Font file was not found");
        BaseFont bfb = BaseFont.createFont(boldFontPath, BaseFont.IDENTITY_H, true);
        regularFont = new Font(bfr);
        regularFont.setSize(10);
        boldFont = new Font(bfb);
        boldFont.setSize(10);

        File file = File.createTempFile("order", ".pdf");
        Document doc = new Document(PageSize.A4);
        Chunk glue = new Chunk(new VerticalPositionMark());
        PdfWriter.getInstance(doc, new FileOutputStream(file));
        doc.open();
        doc.newPage();

        //title
        Paragraph p = new Paragraph(data.get("header").get(0), boldFont);
        p.setAlignment(Element.ALIGN_CENTER);
        doc.add(p);
        doc.add(Chunk.NEWLINE);

        //body
        for (String text : data.get("text")) {
            p = new Paragraph(text, regularFont);
            doc.add(p);
        }

        //table
        doc.add(Chunk.NEWLINE);
        List<String> cols = data.get("cols");
        PdfPTable table = new PdfPTable(cols.size());
        table.setWidthPercentage(100);

        cols.forEach(x -> table.addCell(getCell(x, PdfPCell.ALIGN_CENTER, boldFont)));

        for (Asset asset : assets) {
            table.addCell(getCell(String.format("%s %s %s", asset.getDeviceModel().getDeviceType().getType(),
                    asset.getDeviceModel().getDeviceBrand().getBrand(), asset.getDeviceModel().getModel()),
                    PdfPCell.ALIGN_CENTER, regularFont));
            table.addCell(getCell(asset.getSerialNumber(), PdfPCell.ALIGN_CENTER, regularFont));
            table.addCell(getCell(asset.getInventoryNumber(), PdfPCell.ALIGN_CENTER, regularFont));
        }

        table.getRows();
        doc.add(table);
        doc.add(Chunk.NEWLINE);
        doc.add(Chunk.NEWLINE);

        //signers
        Phrase phrase = new Phrase(new Chunk(data.get("signers").get(0) + " ", regularFont));
        phrase.add(Chunk.NEWLINE);
        phrase.add(new Chunk(issuer.getFirstName() + " " + issuer.getLastName() + "  \\__________________",
                regularFont));
        phrase.add(Chunk.NEWLINE);
        phrase.add(Chunk.NEWLINE);
        phrase.add(new Chunk(data.get("signers").get(1) + " ", regularFont));
        phrase.add(Chunk.NEWLINE);
        phrase.add(new Chunk(employee.getFirstName() + " " + employee.getLastName() + "  \\__________________",
                regularFont));
        doc.add(phrase);

        //date
        doc.add(Chunk.NEWLINE);
        doc.add(Chunk.NEWLINE);
        p = new Paragraph(data.get("place").get(0), regularFont);
        p.add(new Chunk(glue));
        p.add(date.format(dateFormat));
        doc.add(p);
        doc.close();
        return file.getPath();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Screens.Print.java

public void ConvertPDF() throws DocumentException, FileNotFoundException, UnsupportedEncodingException,
        IOException, ParserConfigurationException, SAXException {
    FontFactory.register("tahoma.ttf", "MY_FONT");
    Document document = new Document(PageSize.A5, 20, 20, 10, 10);
    Image image = Image.getInstance("123.jpg");
    PdfPTable table = new PdfPTable(2);
    table.getDefaultCell().setBorder(0);
    //        table.setBorderColor(BaseColor.WHITE);

    PdfPTable tablefooter = new PdfPTable(3);
    tablefooter.getDefaultCell().setBorder(0);
    try {/*w  w  w  .  j ava2 s  . com*/

        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        image.setAbsolutePosition(350f, 520f);
        document.add(image);
        document.add(new Paragraph("\n\n        Telefon: " + PrintTel + "\n\n\n",
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph("Ad, Soyad, ID kod", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph(DataPrint.Ad + " " + DataPrint.Soyad + " (#" + DataPrint.idDaxilOlan + ")",
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Model, Marka", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph(DataPrint.Model + " " + DataPrint.Marka,
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Aksesuar", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.Aksesuar, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Problem", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.Problem, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Tarix", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.DatePlan, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Telefon", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.Telefon, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        document.add(table);
        document.add(
                new Paragraph(jEditorPane1.getText(), FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        //            document.add(new Paragraph(footer, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("Thvil Verdi:", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(new Paragraph("" + DataPrint.Ad + " " + DataPrint.Soyad + "",
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("_____________", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(new Paragraph("  ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(new Paragraph("  ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(new Paragraph("  ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(
                new Paragraph("Thvil ald:", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("Elxan ?sgrli", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("_____________", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        document.add(tablefooter);
    } catch (FileNotFoundException | DocumentException e) {
    }
    document.close();
}

From source file:se.billes.pdf.renderer.request.factory.FontFactory.java

License:Open Source License

public BaseFont createBaseFont(Font font) throws CreateFontException {

    if (font == null) {
        throw new CreateFontException("Font is null");
    }//w ww. j a v a 2 s .c  o  m

    if (font.getPath() == null) {
        throw new CreateFontException("Font path is null");
    }

    if (!new File(font.getPath()).exists()) {
        throw new CreateFontException("Font path " + font.getPath() + " does not exists");
    }

    if (font.getEncoding() == null) {
        font.setEncoding("");
    }
    if (font.getEncoding() != null && font.getEncoding().equals("utf-8")) {
        font.setEncoding(BaseFont.IDENTITY_H);
    }

    try {
        return BaseFont.createFont(font.getPath(), font.getEncoding(), BaseFont.EMBEDDED);
    } catch (DocumentException e) {
        throw new CreateFontException(e);
    } catch (IOException e) {
        throw new CreateFontException(e);
    }
}

From source file:se.inera.intyg.rehabstod.service.export.pdf.PdfExportServiceImpl.java

License:Open Source License

@Override
public byte[] export(List<SjukfallEnhet> sjukfallList, PrintSjukfallRequest printSjukfallRequest,
        RehabstodUser user, int total) {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {//from   www.  j a  va  2 s.  c  om
        unicodeCapableFont = new Font(
                BaseFont.createFont(UNICODE_CAPABLE_FONT_PATH, BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 9,
                Font.NORMAL);

        Document document = new Document();
        document.setPageSize(PageSize.A4);
        document.setMargins(20, 20, 60, 20);

        PdfWriter writer = PdfWriter.getInstance(document, bos);
        // Add handlers for page events

        writer.setPageEvent(new HeaderEventHandler(
                Image.getInstance(
                        IOUtils.toByteArray(resourcePatternResolver.getResource(LOGO_PATH).getInputStream())),
                user.getNamn(), user.getValdVardenhet().getNamn()));
        writer.setPageEvent(new PageNumberingEventHandler());

        document.open();

        // Add the front page with meta info
        document.add(createFrontPage(printSjukfallRequest, user, sjukfallList.size(), total));

        // Switch to landscape mode
        document.setPageSize(PageSize.A4.rotate());
        document.newPage();

        // Add table with all sjukfall (could span several pages)
        document.add(createSjukfallTable(sjukfallList, user.getUrval(), printSjukfallRequest.isShowPatientId(),
                isSrsFeatureActive(user)));

        // Finish off by closing the document (will invoke the event handlers)
        document.close();

    } catch (DocumentException | IOException | RuntimeException e) {
        throw new PdfExportServiceException("Failed to create PDF export!", e);
    }

    return bos.toByteArray();
}

From source file:watermarkpdf.FXMLDocumentController.java

@FXML
private void handleButtonAction(ActionEvent event) throws DocumentException, IOException {
    if (tfPhrase.getLength() > 0) {
        lbl_Result.setText("");
        PdfReader reader = new PdfReader(tf_PathFile.getText());
        Rectangle mediabox = reader.getPageSize(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(
                tf_PathFile.getText().substring(0, tf_PathFile.getLength() - 4) + "_out.pdf"));
        stamper.setRotateContents(false);
        BaseFont bf = BaseFont.createFont("TNR.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font = new Font(bf);
        int iPos = tfPhrase.getText().indexOf('#');
        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            PdfContentByte canvas = stamper.getOverContent(i);
            if (iPos >= 0) {
                if (cbox_LU.isSelected()) {
                    switch (i) {
                    case 1:
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos - 5)
                                        + "? ? "
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                        break;
                    case 2:
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos - 5)
                                        + " ? "
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                        break;
                    default:
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos) + (i - 1)
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                    }/*from w w w .  j  av a2s  . c o  m*/
                } else {
                    if (i == 1)
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos - 5)
                                        + " ? "
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                    else
                        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                                new Phrase((tfPhrase.getText().substring(0, iPos) + (i)
                                        + tfPhrase.getText().substring(iPos + 1)), font),
                                mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
                }

            } else {
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tfPhrase.getText(), font),
                        mediabox.getRight() / 3, mediabox.getTop() - 40, 0);
            }
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tf_append.getText(), font),
                    mediabox.getRight() * 2 / 3, mediabox.getTop() - 20, 0);
        }
        stamper.close();
        reader.close();
        if (tf_PagePrint.getLength() > 0) {
            reader = new PdfReader(
                    tf_PathFile.getText().substring(0, tf_PathFile.getLength() - 4) + "_out.pdf");
            reader.selectPages(tf_PagePrint.getText());
            stamper = new PdfStamper(reader, new FileOutputStream(
                    tf_PathFile.getText().substring(0, tf_PathFile.getLength() - 4) + "_out_cut.pdf"));
            stamper.close();
            reader.close();
        }
        lbl_Result.setText("  ");
    }
}

From source file:zzlorbittest3.PdfReporter.java

public PdfReporter() {
    try {//ww  w  . j ava  2s  .co m
        songBaseFont = BaseFont.createFont("C:\\Windows\\Fonts\\SIMSUN.TTC,1", BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
        titleFont = new Font(songBaseFont, 18, Font.BOLD, BaseColor.BLACK);
        subTitleFont = new Font(songBaseFont, 13);
        contentFont = new Font(songBaseFont, 10);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}