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

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

Introduction

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

Prototype

boolean NOT_EMBEDDED

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

Click Source Link

Document

if the font doesn't have to be embedded

Usage

From source file:com.iisigroup.cap.report.AbstractReportPdfService.java

License:Open Source License

public ByteArrayOutputStream generateReport(Request request) throws CapException {
    ByteArrayOutputStream templateOut = null;
    ByteArrayOutputStream out = null;
    Writer writer = null;/*  w  w  w.java  2  s.c  o  m*/
    OutputStreamWriter wr = null;
    try {
        Template t = getFmConfg().getConfiguration().getTemplate(getReportDefinition() + REPORT_SUFFIX);
        Map<String, Object> reportData = excute(request);

        templateOut = new ByteArrayOutputStream();
        wr = new OutputStreamWriter(templateOut,
                getSysConfig().getProperty(ReportParamEnum.defaultEncoding.toString(), DEFAULT_ENCORDING));
        writer = new BufferedWriter(wr);
        t.process(reportData, writer);

        /**
         * 1.FOR ? JDK 1.7 ???TransformerFactoryImpl org.apache.xalanz 2. org.apache.xalan.processor.TransformerFactoryImpl org.w3c.dom.DOMException: NAMESPACE_ERR:
         */
        System.setProperty("javax.xml.transform.TransformerFactory",
                "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");

        // process core-render
        Document document = XMLResource.load(new ByteArrayInputStream(templateOut.toByteArray())).getDocument();

        ITextRenderer iTextRenderer = new ITextRenderer();
        out = new ByteArrayOutputStream();

        // 
        ITextFontResolver fontResolver = iTextRenderer.getFontResolver();
        fontResolver.addFont(getFontPath(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

        PDFEncryption pdfEncryption = new PDFEncryption();
        // 
        if (reportData.containsKey(ReportParamEnum.encrypt.toString())) {
            String password = (String) reportData.get(ReportParamEnum.encrypt.toString());
            if (!CapString.isEmpty(password)) {
                pdfEncryption.setUserPassword(password.getBytes());
            }
        }
        // ?
        if (getAllowedPrivileges() != -1) {
            pdfEncryption.setAllowedPrivileges(getAllowedPrivileges());
        }
        iTextRenderer.setPDFEncryption(pdfEncryption);

        iTextRenderer.setDocument(document,
                FIL_URL_PREFIX + servletContext.getRealPath("").replace("\\", "/") + "/");

        iTextRenderer.layout();
        iTextRenderer.createPDF(out);

    } catch (Exception e) {
        if (e.getCause() != null) {
            throw new CapException(e.getCause(), e.getClass());
        } else {
            throw new CapException(e, e.getClass());
        }
    } finally {
        if (templateOut != null) {
            try {
                templateOut.close();
            } catch (IOException e) {
                if (logger.isErrorEnabled()) {
                    logger.error(e.getMessage());
                }
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                if (logger.isErrorEnabled()) {
                    logger.error(e.getMessage());
                }
            }
        }
    }
    return out;
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private BaseFont getBaseFont(String id, String name, String encoding) {
    BaseFont font = getFonts().get(id);/* w  ww  . j  av  a 2s  . c  om*/
    if (font == null) {
        try {
            font = BaseFont.createFont(name, encoding, BaseFont.NOT_EMBEDDED);
        } catch (Exception e) {
            e.printStackTrace();
            font = getDefaultFont();
        }
        getFonts().put(id, font);
    }
    return font;
}

From source file:com.mycompany.mavenproject1.Createpdf.java

private void initializeFonts() {

    try {/* w w  w . java 2s  .co m*/
        bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:com.ots.jsp1.itext.ADAStamper.java

License:Open Source License

public void addADAAsWatermark(InputStream inStream, OutputStream outputStream, String ADA)
        throws DocumentException, IOException {
    PdfStamper stamper = null;//from w w  w .  j  a v a2 s  . c o  m
    PdfReader reader = null;
    try {

        reader = new PdfReader(inStream);
        //The zero byte means we dont want to change the version number of the PDF file.
        //true->not to change any of the original bytes
        stamper = new PdfStamper(reader, outputStream, '\0', true);
        int numberOfPages = reader.getNumberOfPages();

        for (int currentPage = 1; currentPage <= numberOfPages; currentPage++) {

            PdfAppearance canvas = PdfAppearance.createAppearance(stamper.getWriter(), 100, 30);
            canvas.setFontAndSize(
                    BaseFont.createFont(fontFilePath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED, true), 11);
            Rectangle pageSize = reader.getPageSizeWithRotation(currentPage);
            Rectangle watermarkPosition = new Rectangle(pageSize.getRight() - 150, pageSize.getTop() - 30,
                    pageSize.getRight() - 50, pageSize.getTop() - 10, 0);
            PdfAnnotation annotation = PdfAnnotation.createFreeText(stamper.getWriter(), watermarkPosition, ADA,
                    canvas);
            annotation.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_READONLY));

            //  annotation.put(PdfName.FONT, canvas);
            //  PdfAnnotation annotation = PdfAnnotation.createText(stamper.getWriter(), watermarkPosition, "", ADA, true, "Key");
            // 

            PdfBorderDictionary borderDictionary = new PdfBorderDictionary(0, PdfBorderDictionary.STYLE_SOLID);

            annotation.setBorderStyle(borderDictionary);
            stamper.addAnnotation(annotation, currentPage);
        }
    } finally {
        stamper.close();
        reader.close();
    }

}

From source file:com.poscoict.license.service.CertificateService.java

private Font getFont(Fonts name) {
    try {/*from ww  w  .  j  a va  2s  .  c om*/
        BaseFont baseFont = BaseFont.createFont(Consts.FONT_FILE_PATH, BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
        switch (name) {
        case FONT12NOAML:
            this.FONT = new Font(baseFont, 12, Font.NORMAL);
            break;
        case FONT12BOLD:
            this.FONT = new Font(baseFont, 12, Font.BOLD);
            break;
        case FONT18NOAML:
            this.FONT = new Font(baseFont, 18, Font.NORMAL);
            break;
        case FONT20BOLD:
            this.FONT = new Font(baseFont, 20, Font.BOLD);
            break;
        default:
            this.FONT = new Font(baseFont, 12, Font.NORMAL);
        }
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return this.FONT;
}

From source file:com.shiyq.itext.PdfUtil.java

public static FontSelector getSelector(int fontsize) {
    FontSelector selector = new FontSelector();
    selector.addFont(FontFactory.getFont(FontFactory.TIMES_ROMAN, fontsize));
    selector.addFont(FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED, fontsize));
    return selector;
}

From source file:com.stee.emer.util.PdfGenerator.java

License:Open Source License

public static byte[] generate(Map<String, String> map) throws IOException, DocumentException {
    URL classPath = PdfGenerator.class.getClassLoader().getResource("");
    PdfReader pdfReader = new PdfReader(classPath + "com/stee/emer/model/model.pdf");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PdfStamper pdfStamper = new PdfStamper(pdfReader, os);
    AcroFields acroFields = pdfStamper.getAcroFields();
    BaseFont baseFont = BaseFont.createFont(classPath + "MSYH.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    ArrayList<BaseFont> list = new ArrayList<BaseFont>();
    list.add(baseFont);/*from   w  w  w  .  jav  a2 s.c  o m*/
    acroFields.setSubstitutionFonts(list);
    Iterator<Entry<String, String>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, String> next = iterator.next();
        acroFields.setField(next.getKey(), next.getValue());
    }

    pdfStamper.setFormFlattening(true);
    pdfStamper.close();

    // File file = new File("e:/temp.pdf");
    // FileOutputStream fileOutputStream = new FileOutputStream(file);
    // fileOutputStream.write(os.toByteArray());
    // fileOutputStream.flush();
    // fileOutputStream.close();
    return os.toByteArray();
}

From source file:com.wabacus.system.assistant.PdfAssistant.java

License:Open Source License

private PdfAssistant() {
    try {/*from ww  w  .  j  a va2 s  .  c  o  m*/
        bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    } catch (Exception e) {
        throw new WabacusRuntimeException("?PDF", e);
    }
}

From source file:com.yqboots.web.thymeleaf.support.Html2PdfGenerator.java

License:Apache License

/**
 * Add fonts to {@link ITextRenderer}, for chinese support.
 *
 * @param renderer renderer/*from  www.  j a  v  a 2s  .com*/
 * @param fonts    fonts
 * @throws Exception
 */
private void addFonts(final ITextRenderer renderer, final String[] fonts) throws Exception {
    if (ArrayUtils.isEmpty(fonts)) {
        return;
    }

    Assert.notNull(renderer);

    final ITextFontResolver fontResolver = renderer.getFontResolver();
    for (final String font : fonts) {
        final String fontPath = ResourceUtils.getFile(font).getAbsolutePath();
        fontResolver.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    }
}

From source file:Compras.altaCompras.java

   private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
    // TODO add your handling code here:
    if(t_datos.getRowCount()>0)
    {/*  w w  w  . jav  a 2 s .c  o m*/
        javax.swing.JFileChooser jF1= new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
        String ruta = null;
        if(jF1.showSaveDialog(null)==jF1.APPROVE_OPTION)
        {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if(ruta!=null)
            {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try
                {
                    DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
                    formatoPorcentaje.setMinimumFractionDigits(2);
                    session.beginTransaction().begin();
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                    //Orden ord=buscaApertura();
                    PDF reporte = new PDF();
                    Date fecha = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
                    String valor=dateFormat.format(fecha);

                    reporte.Abrir2(PageSize.LETTER.rotate(), "Valuacin", ruta+".pdf");
                    Font font = new Font(Font.FontFamily.HELVETICA, 5, Font.BOLD);
                    BaseColor contenido=BaseColor.WHITE;
                    int centro=Element.ALIGN_CENTER;
                    int izquierda=Element.ALIGN_LEFT;
                    int derecha=Element.ALIGN_RIGHT;
                    float tam[]=new float[]{10,10,80,5,5,5,5,5,14,10,25,23,8,8,8,10,10,10};
                        

                    PdfPTable tabla=reporte.crearTabla(tam.length, tam, 100, Element.ALIGN_LEFT);

                    cabecera(reporte, bf, tabla);
                    int ren=0;
                        
                    //double dm=0d, cam=0d, min=0d, med=0d, max=0d, pin=0d, tot=0d;

                    for(int i=0; i<t_datos.getRowCount(); i++)
                    {
                        tabla.addCell(reporte.celda(t_titulos.getValueAt(i, 0).toString(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_titulos.getValueAt(i, 1).toString(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_titulos.getValueAt(i, 2).toString(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE));
                        if( ((boolean)t_datos.getValueAt(i, 1)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 2)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 3)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 4)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( (t_datos.getValueAt(i, 6)) != null)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 14)), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 8).toString(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 10).toString(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 17)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 18)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 19)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if(t_datos.getValueAt(i, 20)!=null)
                            tabla.addCell(reporte.celda(t_datos.getValueAt(i, 20).toString(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if(t_datos.getValueAt(i, 26)!=null)
                            tabla.addCell(reporte.celda(t_datos.getValueAt(i, 26).toString(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                        if( ((boolean)t_datos.getValueAt(i, 27)) ==true)
                            tabla.addCell(reporte.celda("x", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                        else
                            tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                            
                    }
                        
                    tabla.setHeaderRows(1);
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta+".pdf");
                }catch(Exception e)
                {
                    System.out.println(e);
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto.");
                }
                if(session!=null)
                if(session.isOpen())
                session.close();
            }
        }
    }
}