Example usage for com.lowagie.text.pdf PdfReader PdfReader

List of usage examples for com.lowagie.text.pdf PdfReader PdfReader

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfReader PdfReader.

Prototype

public PdfReader(PdfReader reader) 

Source Link

Document

Creates an independent duplicate.

Usage

From source file:classroom.newspaper_b.Newspaper11.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from  w  w  w .  jav  a  2 s  . co m*/
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        PdfContentByte canvas = stamper.getOverContent(1);
        canvas.setRGBColorFill(0xFF, 0xFF, 0xFF);
        canvas.rectangle(LLX1, LLY1, W1, H1);
        canvas.rectangle(LLX2, LLY2, W2, H2);
        canvas.fill();
        addTextField(stamper, new Rectangle(LLX1, LLY1, URX1, URY1), "field1", 1);
        addTextField(stamper, new Rectangle(LLX2, LLY2, URX2, URY2), "field2", 1);
        stamper.close();

        reader = new PdfReader(RESULT);
        AcroFields fields = reader.getAcroFields();
        Set<String> fieldnames = fields.getFields().keySet();
        for (String fieldname : fieldnames) {
            System.out.print(fieldname);
            System.out.print(": page ");
            float[] positions = fields.getFieldPositions(fieldname);
            System.out.print(positions[0]);
            System.out.print(" [ ");
            System.out.print(positions[1]);
            System.out.print(", ");
            System.out.print(positions[2]);
            System.out.print(", ");
            System.out.print(positions[3]);
            System.out.print(", ");
            System.out.print(positions[4]);
            System.out.println("]");
        }

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

From source file:classroom.newspaper_b.Newspaper12.java

public static void main(String[] args) {
    Newspaper11.main(args);/*from w  w w.ja v a2 s.  c o m*/
    try {
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        AcroFields fields = stamper.getAcroFields();
        fields.setField("field1", "Advertissement 1");
        float[] positions1 = fields.getFieldPositions("field1");
        putImage(stamper.getOverContent((int) positions1[0]), IMG1, positions1);
        fields.setField("field2", "Advertissement 2");
        float[] positions2 = fields.getFieldPositions("field2");
        putImage(stamper.getOverContent((int) positions2[0]), IMG2, positions2);
        stamper.setFormFlattening(true);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:classroom.newspaper_b.Newspaper13.java

public static void main(String[] args) {
    try {/*from w  w w  . j a  v  a2  s.c o  m*/
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        addButton(stamper, new Rectangle(LLX1, LLY1, URX1, URY1), PATH1, "button1", 1);
        addButton(stamper, new Rectangle(LLX2, LLY2, URX2, URY2), PATH2, "button2", 1);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:classroom.newspaper_b.Newspaper13.java

public static void addButton(PdfStamper stamper, Rectangle rect, String path, String name, int pagenumber)
        throws IOException, DocumentException {
    PushbuttonField field = new PushbuttonField(stamper.getWriter(), rect, name);
    if (path.endsWith(".pdf")) {
        PdfReader reader = new PdfReader(path);
        field.setTemplate(stamper.getImportedPage(reader, 1));
    } else {/* www  .j  ava2 s.  co m*/
        field.setImage(Image.getInstance(path));
    }
    field.setBackgroundColor(new Color(0xFF, 0xFF, 0xFF));
    field.setBorderColor(new Color(0xC0, 0xC0, 0xC0));
    field.setBorderWidth(0.5f);
    field.setScaleIcon(PushbuttonField.SCALE_ICON_ALWAYS);
    field.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
    stamper.addAnnotation(field.getField(), pagenumber);
}

From source file:classroom.newspaper_b.Newspaper14.java

public static void main(String[] args) {
    Newspaper13.main(args);/* w  ww.j  av  a2s  . co m*/
    try {
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        changeField(stamper, "button1", PATH1);
        changeField(stamper, "button2", PATH2);
        stamper.setFormFlattening(true);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:classroom.newspaper_b.Newspaper14.java

public static void changeField(PdfStamper stamper, String button, String path)
        throws IOException, DocumentException {
    AcroFields fields = stamper.getAcroFields();
    PushbuttonField bt = fields.getNewPushbuttonFromField(button);
    bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
    bt.setProportionalIcon(true);//from  www .  ja v a2 s.co m
    PdfReader reader = new PdfReader(path);
    bt.setTemplate(stamper.getImportedPage(reader, 1));
    fields.replacePushbuttonField(button, bt.getField());
}

From source file:cn.hanbell.rpt.control.ReportManagedBean.java

@Override
public void print() throws Exception {
    String system = paramMap.get("system")[0];
    String api = paramMap.get("api")[0];
    systemProgram = systemProgramBean.findBySystemAndAPI(system, api);
    if (systemProgram == null) {
        FacesContext.getCurrentInstance().getExternalContext().redirect("deny.xhtml");
    }/*w  w w .j ava  2 s  . c o m*/
    HashMap<String, Object> reportParams = new HashMap<>();
    reportParams.put("JNDIName", systemProgram.getRptjndi());
    if (paramMap.containsKey("formid")) {
        if ("EFGP".equals(system)) {
            ProcessInstance pi = processInstanceBean.findByOID(paramMap.get("formid")[0]);
            reportParams.put("formid", pi.getSerialNumber());
        } else {
            reportParams.put("formid", paramMap.get("formid")[0]);
        }
    }
    if (paramMap.containsKey("filterFields")) {
        reportParams.put("filterFields", paramMap.get("filterFields")[0]);
    }
    if (paramMap.containsKey("sortFields")) {
        reportParams.put("sortFields", paramMap.get("sortFields")[0]);
    }
    reportOutputFormat = systemProgram.getRptformat();
    String fileName = systemProgram.getApi() + BaseLib.formatDate("yyyyMMddHHmmss", BaseLib.getDate()) + "."
            + reportOutputFormat;
    String reportName = reportPath + systemProgram.getRptdesign();
    String outputName = reportOutputPath + fileName;
    reportViewPath = reportViewContext + fileName;
    try {
        if ("EFGP".equals(system)) {
            OutputStream os = new FileOutputStream(outputName);
            PdfCopyFields pdfCopy = new PdfCopyFields(os);
            ByteArrayOutputStream baos;
            //??
            this.setReportClass(Class.forName(systemProgram.getRptclazz()).getClassLoader());
            //??
            this.reportInitAndConfig();
            //?
            baos = new ByteArrayOutputStream();
            this.reportRunAndOutput(reportName, reportParams, null, "pdf", baos);
            pdfCopy.addDocument(new PdfReader(baos.toByteArray()));
            //???
            if ("HZ_CW028".equals(api)) {
                String formSerialNumber = hzcw028Bean.findByPSN(reportParams.get("formid"))
                        .getFormSerialNumber();
                if (hzcw028Bean.getTrafficDetail(formSerialNumber).size() > 0) {
                    baos = new ByteArrayOutputStream();
                    this.reportRunAndOutput(reportPath + "hzcw02802.rptdesign", reportParams, null, "pdf",
                            baos);
                    pdfCopy.addDocument(new PdfReader(baos.toByteArray()));
                }
            }

            //??
            this.setReportClass(Class.forName("cn.hanbell.efgp.rpt.ProcessCheckReport").getClassLoader());//??
            reportParams.remove("JNDIName");
            reportParams.put("JNDIName",
                    "java:global/Hanbell-EAP/EFGP-ejb/ProcessCheckBean!cn.hanbell.oa.ejb.ProcessCheckBean");//??Bean
            //??
            this.reportInitAndConfig();
            //?
            baos = new ByteArrayOutputStream();
            this.reportRunAndOutput(reportPath + "processcheck.rptdesign", reportParams, null, "pdf", baos);
            pdfCopy.addDocument(new PdfReader(baos.toByteArray()));
            //??
            pdfCopy.close();
        } else {
            this.setReportClass(Class.forName(systemProgram.getRptclazz()).getClassLoader());
            //??
            this.reportInitAndConfig();
            //?
            this.reportRunAndOutput(reportName, reportParams, outputName, reportOutputFormat, null);
        }
        //
        this.preview();
    } catch (Exception ex) {
        throw ex;
    }
}

From source file:cn.hanbell.war.control.BillPrintManagedBean.java

public void print(String rptdesign) throws Exception {
    if (currentPrgGrant == null || entityList == null || entityList.isEmpty()) {
        return;//from  www . j  a v a  2  s .  c om
    }
    String reportName, outputName, reportFormat;
    //??
    reportName = reportPath + currentPrgGrant.getSysprg().getRptdesign();
    //??
    fileName = "BillPrint" + BaseLib.formatDate("yyyyMMddHHmmss", getDate()) + ".pdf";
    outputName = reportOutputPath + fileName;
    OutputStream os = new FileOutputStream(outputName);
    if (this.currentPrgGrant != null && this.currentPrgGrant.getSysprg().getRptclazz() != null) {
        reportClassLoader = Class.forName(this.currentPrgGrant.getSysprg().getRptclazz()).getClassLoader();
    }
    PdfCopyFields pdfCopy = new PdfCopyFields(os);
    HashMap<String, Object> reportParams = new HashMap<>();
    ByteArrayOutputStream baos;
    for (Armbill c : entityList) {
        //?
        baos = new ByteArrayOutputStream();
        reportParams.put("company", userManagedBean.getCurrentCompany().getName());
        reportParams.put("companyFullName", userManagedBean.getCurrentCompany().getFullname());
        reportParams.put("tel", userManagedBean.getCurrentCompany().getTel());
        reportParams.put("fax", userManagedBean.getCurrentCompany().getFax());
        reportParams.put("id", c.getId());
        reportParams.put("formid", c.getFormid());
        reportParams.put("JNDIName", currentPrgGrant.getSysprg().getRptjndi());
        try {
            //??
            this.reportInitAndConfig();
            //?
            this.reportRunAndOutput(reportName, reportParams, null, "pdf", baos);
        } catch (Exception ex) {
            throw ex;
        } finally {
            reportParams.clear();
            c.setStatus("P");
            currentEntity = c;
            update();
        }
        pdfCopy.addDocument(new PdfReader(baos.toByteArray()));
    }
    pdfCopy.close();
    this.reportViewPath = reportViewContext + fileName;
    this.preview();
}

From source file:cn.hanbell.war.control.ShipmentPrintManagedBean.java

public void print(String rptdesign) throws Exception {
    if (currentPrgGrant == null || entityList == null || entityList.isEmpty()) {
        return;/*w  w w . j  a  v  a 2 s .c o m*/
    }
    String reportName, outputName, reportFormat;
    //??
    //reportName = reportPath + currentPrgGrant.getSysprg().getRptdesign();
    //??
    fileName = "ShipmentPrint" + BaseLib.formatDate("yyyyMMddHHmmss", getDate()) + ".pdf";
    outputName = reportOutputPath + fileName;
    OutputStream os = new FileOutputStream(outputName);
    if (this.currentPrgGrant != null && this.currentPrgGrant.getSysprg().getRptclazz() != null) {
        reportClassLoader = Class.forName(this.currentPrgGrant.getSysprg().getRptclazz()).getClassLoader();
    }
    PdfCopyFields pdfCopy = new PdfCopyFields(os);
    HashMap<String, Object> reportParams = new HashMap<>();
    ByteArrayOutputStream baos;
    for (Shipment c : entityList) {
        //?
        baos = new ByteArrayOutputStream();
        reportParams.put("company", userManagedBean.getCurrentCompany().getName());
        reportParams.put("companyFullName", userManagedBean.getCurrentCompany().getFullname());
        reportParams.put("tel", userManagedBean.getCurrentCompany().getTel());
        reportParams.put("fax", userManagedBean.getCurrentCompany().getFax());
        reportParams.put("id", c.getId());
        reportParams.put("formid", c.getFormid());
        reportParams.put("JNDIName", currentPrgGrant.getSysprg().getRptjndi());
        try {
            //?????
            reportName = reportPath + c.getCustomerno() + rptdesign + ".rptdesign";
            //??
            this.reportInitAndConfig();
            //?
            this.reportRunAndOutput(reportName, reportParams, null, "pdf", baos);
        } catch (Exception ex) {
            throw ex;
        } finally {
            reportParams.clear();
            c.setStatus("P");
            currentEntity = c;
            update();
        }
        pdfCopy.addDocument(new PdfReader(baos.toByteArray()));
    }
    pdfCopy.close();
    this.reportViewPath = reportViewContext + fileName;
    this.preview();
}

From source file:cn.hanbell.war.control.WarrentyPrintManagedBean.java

public void print(String rptdesign) throws Exception {
    if (currentPrgGrant == null || entityList == null || entityList.isEmpty()) {
        return;/*w  w  w.  j  a v a 2 s  . c o  m*/
    }
    String reportName, outputName, reportFormat;
    //??
    //reportName = reportPath + currentPrgGrant.getSysprg().getRptdesign();
    //??
    fileName = "WarrentyPrint" + BaseLib.formatDate("yyyyMMddHHmmss", getDate()) + ".pdf";
    outputName = reportOutputPath + fileName;
    OutputStream os = new FileOutputStream(outputName);
    if (this.currentPrgGrant != null && this.currentPrgGrant.getSysprg().getRptclazz() != null) {
        reportClassLoader = Class.forName(this.currentPrgGrant.getSysprg().getRptclazz()).getClassLoader();
    }
    PdfCopyFields pdfCopy = new PdfCopyFields(os);
    HashMap<String, Object> reportParams = new HashMap<>();
    ByteArrayOutputStream baos;
    for (Shipment c : entityList) {
        //?
        baos = new ByteArrayOutputStream();
        reportParams.put("company", userManagedBean.getCurrentCompany().getName());
        reportParams.put("companyFullName", userManagedBean.getCurrentCompany().getFullname());
        reportParams.put("tel", userManagedBean.getCurrentCompany().getTel());
        reportParams.put("fax", userManagedBean.getCurrentCompany().getFax());
        reportParams.put("id", c.getId());
        reportParams.put("formid", c.getFormid());
        reportParams.put("JNDIName", currentPrgGrant.getSysprg().getRptjndi());
        try {
            reportName = reportPath + rptdesign + ".rptdesign";
            //??
            this.reportInitAndConfig();
            //?
            this.reportRunAndOutput(reportName, reportParams, null, "pdf", baos);
        } catch (Exception ex) {
            throw ex;
        } finally {
            reportParams.clear();
            c.setStatus("P");
            currentEntity = c;
            update();
        }
        pdfCopy.addDocument(new PdfReader(baos.toByteArray()));
    }
    pdfCopy.close();
    this.reportViewPath = reportViewContext + fileName;
    this.preview();
}