Java 类com.lowagie.text.PageSize 实例源码

项目:DWSurvey    文件:DocExportUtil.java   
public void createDoc() throws FileNotFoundException{
     /** 创建Document对象(word文档)  */
       Rectangle rectPageSize = new Rectangle(PageSize.A4);
       rectPageSize = rectPageSize.rotate();
       // 创建word文档,并设置纸张的大小
       doc = new Document(PageSize.A4);
       file=new File(path+docFileName);
       fileOutputStream=new FileOutputStream(file);
       /** 建立一个书写器与document对象关联,通过书写器可以将文档写入到输出流中 */
       RtfWriter2.getInstance(doc, fileOutputStream );
       doc.open();
       //设置页边距,上、下25.4毫米,即为72f,左、右31.8毫米,即为90f  
       doc.setMargins(90f, 90f, 72f, 72f);
       //设置标题字体样式,粗体、二号、华文中宋  
       tfont  = DocStyleUtils.setFontStyle("华文中宋", 22f, Font.BOLD);  
       //设置正文内容的字体样式,常规、三号、仿宋_GB2312  
       bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
项目:unitimes    文件:PdfExamGridTable.java   
public void export(OutputStream out) throws Exception {
    int nrCols = getNrColumns();
    iDocument = (iForm.getDispMode()==sDispModeInRowHorizontal || iForm.getDispMode()==sDispModeInRowVertical ?
        new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)).rotate(), 30, 30, 30, 30)
    :
        new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)), 30, 30, 30, 30));

    PdfEventHandler.initFooter(iDocument, out);
    iDocument.open();

    printTable();

    printLegend();

    iDocument.close();
}
项目:unitimes    文件:PdfInstructionalOfferingTableBuilder.java   
public void pdfTableForInstructionalOfferings(
        OutputStream out,
          ClassAssignmentProxy classAssignment,
          ExamAssignmentProxy examAssignment,
          InstructionalOfferingListForm form, 
          String[] subjectAreaIds, 
          SessionContext context,
          boolean displayHeader,
          boolean allCoursesAreGiven) throws Exception{

    setVisibleColumns(form);

    iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); 
iWriter = PdfEventHandler.initFooter(iDocument, out);

    for (String subjectAreaId: subjectAreaIds) {
        pdfTableForInstructionalOfferings(out, classAssignment, examAssignment,
                form.getInstructionalOfferings(Long.valueOf(subjectAreaId)), 
                Long.valueOf(subjectAreaId),
                context,
                displayHeader, allCoursesAreGiven,
                new ClassCourseComparator(form.getSortBy(), classAssignment, false));
    }

iDocument.close();
  }
项目:unitimes    文件:PdfLegacyReport.java   
public void open(OutputStream out, int mode) throws DocumentException, IOException {
    iOut = out;
    if (mode==sModeText) {
        iPrint = new PrintWriter(iOut);
    } else {
        iNrLines = (mode==sModeLedger?116:50);
        iDoc = new Document(mode==sModeLedger?PageSize.LEDGER.rotate():PageSize.LETTER.rotate());

        PdfWriter.getInstance(iDoc, iOut);

        iDoc.addTitle(iTitle);
        iDoc.addAuthor("UniTime "+Constants.getVersion()+", www.unitime.org");
        iDoc.addSubject(iSubject);
        iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org");

        iDoc.open();
    }
    iEmpty = true;
    iPageNo = 0; iLineNo = 0;
}
项目:itext2    文件:LandscapePortraitTest.java   
/**
 * Creates a PDF document with pages in portrait/landscape.
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4.rotate());

    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to a file

    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("LandscapePortrait.pdf"));

    // step 3: we open the document
    document.open();

    // step 4: we add some content
    document.add(new Paragraph(
            "To create a document in landscape format, just make the height smaller than the width. For instance by rotating the PageSize Rectangle: PageSize.A4.rotate()"));
    document.setPageSize(PageSize.A4);
    document.newPage();
    document.add(new Paragraph("This is portrait again"));

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:ArabicTextTest.java   
/**
 * Draws arabic text using java.awt.Graphics2D.
    */
@Test
public void main() throws Exception {
    // step 1
       Document document = new Document(PageSize.A4, 50, 50, 50, 50);
       try {
        // step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "arabictext.pdf"));
           // step 3
           document.open();
           // step 4
           String text1 = "This text has \u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631 123,456 \u0645\u0646 (Arabic)";
           java.awt.Font font = new java.awt.Font("arial", 0, 18);
           PdfContentByte cb = writer.getDirectContent();
           java.awt.Graphics2D g2 = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
           g2.setFont(font);
           g2.drawString(text1, 100, 100);
           g2.dispose();
           cb.sanityCheck();
           // step 5
           document.close();
       }
       catch (Exception de) {
           de.printStackTrace();
       }
   }
项目:itext2    文件:PageNumbersWatermarkTest.java   
/**
    * Generates a document with a header containing Page x of y and with a Watermark on every page.
    */
@Test
public void main() throws Exception {
        // step 1: creating the document
           Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
           // step 2: creating the writer
           PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf"));
           // step 3: initialisations + opening the document
           writer.setPageEvent(new PageNumbersWatermarkTest());
           doc.open();
           // step 4: adding content
           String text = "some padding text ";
           for (int k = 0; k < 10; ++k) {
               text += text;
           }
           Paragraph p = new Paragraph(text);
           p.setAlignment(Element.ALIGN_JUSTIFIED);
           doc.add(p);
           // step 5: closing the document
           doc.close();

   }
项目:itext2    文件:EndPageTest.java   
/**
 * Demonstrates the use of PageEvents.
 */
@Test
public void main() throws Exception {
    Document document = new Document(PageSize.A4, 50, 50, 70, 70);

    PdfWriter writer = PdfWriter.getInstance(document,
            PdfTestBase.getOutputStream("endpage.pdf"));
    writer.setPageEvent(new EndPageTest());
    document.open();
    String text = "Lots of text. ";
    for (int k = 0; k < 10; ++k)
        text += text;
    document.add(new Paragraph(text));
    document.close();

}
项目:itext2    文件:ShadingTest.java   
@Test
public void main() throws Exception {

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document,  PdfTestBase.getOutputStream( "shading.pdf"));
    document.open();

    PdfFunction function1 = PdfFunction.type2(writer, new float[] { 0, 1 },
            null, new float[] { .929f, .357f, 1, .298f }, new float[] {
                    .631f, .278f, 1, .027f }, 1.048f);
    PdfFunction function2 = PdfFunction.type2(writer, new float[] { 0, 1 },
            null, new float[] { .929f, .357f, 1, .298f }, new float[] {
                    .941f, .4f, 1, .102f }, 1.374f);
    PdfFunction function3 = PdfFunction.type3(writer, new float[] { 0, 1 },
            null, new PdfFunction[] { function1, function2 },
            new float[] { .708f }, new float[] { 1, 0, 0, 1 });
    PdfShading shading = PdfShading.type3(writer,
            new CMYKColor(0, 0, 0, 0),
            new float[] { 0, 0, .096f, 0, 0, 1 }, null, function3,
            new boolean[] { true, true });
    PdfContentByte cb = writer.getDirectContent();
    cb.moveTo(316.789f, 140.311f);
    cb.curveTo(303.222f, 146.388f, 282.966f, 136.518f, 279.122f, 121.983f);
    cb.lineTo(277.322f, 120.182f);
    cb.curveTo(285.125f, 122.688f, 291.441f, 121.716f, 298.156f, 119.386f);
    cb.lineTo(336.448f, 119.386f);
    cb.curveTo(331.072f, 128.643f, 323.346f, 137.376f, 316.789f, 140.311f);
    cb.clip();
    cb.newPath();
    cb.saveState();
    cb.concatCTM(27.7843f, 0, 0, -27.7843f, 310.2461f, 121.1521f);
    cb.paintShading(shading);
    cb.restoreState();

    cb.sanityCheck();

    document.close();
}
项目:itext2    文件:FixedFontWidthTest.java   
/**
 * Changing the width of font glyphs.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fixedfontwidth.pdf"));
    // step 3
    document.open();
    // step 4
    BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false, false, null, null);
    int widths[] = bf.getWidths();
    for (int k = 0; k < widths.length; ++k) {
        if (widths[k] != 0)
            widths[k] = 1000;
    }
    bf.setForceWidthsOutput(true);
    document.add(new Paragraph("A big text to show Helvetica with fixed width.", new Font(bf)));
    // step 5
    document.close();
}
项目:itext2    文件:OpenTypeFontTest.java   
/**
 * Using oth
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter.getInstance(document,
            PdfTestBase.getOutputStream("opentypefont.pdf"));
    // step 3
    document.open();
    // step 4
    BaseFont bf = BaseFont.createFont(PdfTestBase.RESOURCES_DIR
            + "liz.otf", BaseFont.CP1252, true);
    String text = "Some text with the otf font LIZ.";
    document.add(new Paragraph(text, new Font(bf, 14)));
    // step 5
    document.close();
}
项目:itext2    文件:FormComboTest.java   
/**
 * Generates an Acroform with a Combobox
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4);

    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("combo.pdf"));

    // step 3: we open the document
    document.open();

    // step 4:
    PdfContentByte cb = writer.getDirectContent();
    cb.moveTo(0, 0);
    String options[] = { "Red", "Green", "Blue" };
    PdfFormField field = PdfFormField.createCombo(writer, true, options, 0);
    field.setWidget(new Rectangle(100, 700, 180, 720), PdfAnnotation.HIGHLIGHT_INVERT);
    field.setFieldName("ACombo");
    field.setValueAsString("Red");
    writer.addAnnotation(field);

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:FormSignatureTest.java   
/**
 * Generates an Acroform with a Signature
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4);

    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("signature.pdf"));

    // step 3: we open the document
    document.open();

    // step 4:
    PdfAcroForm acroForm = writer.getAcroForm();
    document.add(new Paragraph("Hello World"));
    acroForm.addSignature("mysig", 73, 705, 149, 759);

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:OpenApplicationTest.java   
/**
 * Creates a document with Named Actions.
 * 
 * @param args The file to open
 */
public void main(String... args) throws Exception {

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    // step 2: we create a writer that listens to the document
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OpenApplication.pdf"));
    // step 3: we open the document
    document.open();
    // step 4: we add some content
    String application = args[0];
    Paragraph p = new Paragraph(new Chunk("Click to open " + application).setAction(
            new PdfAction(application, null, null, null)));
    document.add(p);

    // step 5: we close the document
    document.close();

}
项目:itext2    文件:AnnotatedImageTest.java   
/**
 * Adds some annotated images to a PDF file.
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2:
    // we create a writer that listens to the document
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("annotated_images.pdf"));
    // step 3: we open the document
    document.open();
    // step 4: we add some content
    Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
    jpeg.setAnnotation(new Annotation("picture", "This is my dog", 0, 0, 0, 0));
    jpeg.setAbsolutePosition(100f, 550f);
    document.add(jpeg);
    Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
    wmf.setAnnotation(new Annotation(0, 0, 0, 0, "http://www.lowagie.com/iText"));
    wmf.setAbsolutePosition(100f, 200f);
    document.add(wmf);

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:SpaceWordRatioTest.java   
/**
 * Space Word Ratio.
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document(PageSize.A4, 50, 350, 50, 50);
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf"));
    // step 3
    document.open();
    // step 4
    String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
    Paragraph p = new Paragraph(text);
    p.setAlignment(Element.ALIGN_JUSTIFIED);
    document.add(p);
    document.newPage();
    writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
    document.add(p);

    // step 5
    document.close();
}
项目:itext2    文件:SplitTableTest.java   
/**
 * Break a large table up into several smaller tables for memory management
 * purposes.
 * 
 */
@Test
public void main() throws Exception {
    // step1
    Document document = new Document(PageSize.A4, 10, 10, 10, 10);
    // step2
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SplitTable.pdf"));
    // step3
    document.open();
    // step4

    PdfContentByte cb = writer.getDirectContent();
    PdfPTable table = new PdfPTable(10);
    for (int k = 1; k <= 100; ++k) {
        table.addCell("The number " + k);
    }
    table.setTotalWidth(800);
    table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
    document.newPage();
    table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
    document.close();

    // step5
    document.close();
}
项目:sistra    文件:PDFDocument.java   
public void generate(OutputStream os) throws Exception
{
    document = new Document(PageSize.A4, 36, 36, 36, 50);
    writer = PdfWriter.getInstance(document,os);        
    writer.setEncryption(null, null, PdfWriter.AllowCopy | PdfWriter.AllowPrinting, PdfWriter.STRENGTH40BITS);
    writer.setPageEvent(new EndPage(this.getCabecera(),this.getPie(),this.getBarcode(),this.isPaginar()));      
    document.open();                
    //Pintar la cabecera que proceda: No pitar, cabecera normal o cabecera peque�a
    if(!noCabecera) {
        if (tipocabecera.equals(TYPE_HEAD_SMALL)) writeCabecera2();
        else writeCabecera();
    }


    for(int i=0; i<secciones.size(); i++)
    {
        Seccion obj = (Seccion)secciones.get(i);
        obj.write(this);
    }       

    document.close();
}
项目:OSCAR-ConCert    文件:OscarChartPrinter.java   
public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
    this.request = request;
    this.os = os;

    document = new Document();
    // writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

    writer = PdfWriter.getInstance(document,os);
    writer.setPageEvent(new EndPage());
    document.setPageSize(PageSize.LETTER);
    document.open();
    //Create the font we are going to print to
       bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
       font = new Font(bf, FONTSIZE, Font.NORMAL);
       boldFont = new Font(bf,FONTSIZE,Font.BOLD);
}
项目:OSCAR-ConCert    文件:PdfRecordPrinter.java   
public PdfRecordPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
    this.request = request;
    this.os = os;
    formatter = new SimpleDateFormat("dd-MMM-yyyy");

    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriter.getInstance(document,os);
    writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);

    document.open();
}
项目:OSCAR-ConCert    文件:PdfRecordPrinter.java   
public void start() throws DocumentException,IOException {
    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
    // writer = PdfWriter.getInstance(document,os);
    // writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    document.open();
}
项目:OSCAR-ConCert    文件:ConsultationPDFCreator.java   
/**
 * Prints the consultation request.
 * @throws IOException when an error with the output stream occurs
 * @throws DocumentException when an error in document construction occurs
 */
public void printPdf(LoggedInInfo loggedInInfo) throws IOException, DocumentException {

    // Create the document we are going to write to
    document = new Document();
    // PdfWriter.getInstance(document, os);
    PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

    document.setPageSize(PageSize.LETTER);
    document.addTitle(getResource("msgConsReq"));
    document.addCreator("OSCAR");
    document.open();

    // Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
            BaseFont.NOT_EMBEDDED);
    headerFont = new Font(bf, 14, Font.BOLD);
    infoFont = new Font(bf, 12, Font.NORMAL);
    font = new Font(bf, 9, Font.NORMAL);
    boldFont = new Font(bf, 10, Font.BOLD);
    bigBoldFont = new Font(bf, 12, Font.BOLD);

    createConsultationRequest(loggedInInfo);

    document.close();
}
项目:OSCAR-ConCert    文件:EFormPDFServlet.java   
private void addDocumentProps(Document document, String title, Properties props) {
    document.addTitle(title);
    document.addSubject("");
    document.addKeywords("pdf, itext");
    document.addCreator("OSCAR");
    document.addAuthor("");

    // A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA
    // and FLSE
    // the following shows a temp way to get a print page size
    final String PAGESIZE = "printPageSize";
    Rectangle pageSize = PageSize.LETTER;
    if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE)))
        pageSize = PageSize.HALFLETTER;
    if ("PageSize.A6".equals(props.getProperty(PAGESIZE)))
        pageSize = PageSize.A6;
    document.setPageSize(pageSize);
    document.open();
}
项目:Biblivre-3    文件:BaseBiblivreReport.java   
protected MemoryFileDTO generateReportFile(BaseReportDto reportData, String fileName) {
    Document document = new Document(PageSize.A4);
    MemoryFileDTO report = new MemoryFileDTO();
    report.setFileName(fileName);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(this);
        writer.setFullCompression();
        document.open();
        generateReportBody(document, reportData);
        writer.flush();
        document.close();
        report.setFileData(baos.toByteArray());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } 
    return report;
}
项目:collegeProjects    文件:JTable2Pdf.java   
private void print() {
  Document document = new Document(PageSize.A4.rotate());
  try {
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("jTable.pdf"));

    document.open();
    PdfContentByte cb = writer.getDirectContent();

    cb.saveState();
    Graphics2D g2 = cb.createGraphicsShapes(500, 500);

    Shape oldClip = g2.getClip();
    g2.clipRect(0, 0, 500, 500);

    table.print(g2);
    g2.setClip(oldClip);

    g2.dispose();
    cb.restoreState();
  } catch (Exception e) {
    System.err.println(e.getMessage());
  }
  document.close();
}
项目:unitime    文件:PdfExamGridTable.java   
public void export(OutputStream out) throws Exception {
    int nrCols = getNrColumns();
    iDocument = (iForm.getDispMode()==sDispModeInRowHorizontal || iForm.getDispMode()==sDispModeInRowVertical ?
        new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)).rotate(), 30, 30, 30, 30)
    :
        new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)), 30, 30, 30, 30));

    PdfEventHandler.initFooter(iDocument, out);
    iDocument.open();

    printTable();

    printLegend();

    iDocument.close();
}
项目:unitime    文件:PdfInstructionalOfferingTableBuilder.java   
public void pdfTableForInstructionalOfferings(
        OutputStream out,
          ClassAssignmentProxy classAssignment,
          ExamAssignmentProxy examAssignment,
          InstructionalOfferingListForm form, 
          String[] subjectAreaIds, 
          SessionContext context,
          boolean displayHeader,
          boolean allCoursesAreGiven) throws Exception{

    setVisibleColumns(form);

    iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); 
iWriter = PdfEventHandler.initFooter(iDocument, out);

    for (String subjectAreaId: subjectAreaIds) {
        pdfTableForInstructionalOfferings(out, classAssignment, examAssignment,
                form.getInstructionalOfferings(Long.valueOf(subjectAreaId)), 
                Long.valueOf(subjectAreaId),
                context,
                displayHeader, allCoursesAreGiven,
                new ClassCourseComparator(form.getSortBy(), classAssignment, false));
    }

iDocument.close();
  }
项目:unitime    文件:PdfLegacyReport.java   
public void open(OutputStream out, int mode) throws DocumentException, IOException {
    iOut = out;
    if (mode==sModeText) {
        iPrint = new PrintWriter(iOut);
    } else {
        iNrLines = (mode==sModeLedger?116:50);
        iDoc = new Document(mode==sModeLedger?PageSize.LEDGER.rotate():PageSize.LETTER.rotate());

        PdfWriter.getInstance(iDoc, iOut);

        iDoc.addTitle(iTitle);
        iDoc.addAuthor("UniTime "+Constants.getVersion()+", www.unitime.org");
        iDoc.addSubject(iSubject);
        iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org");

        iDoc.open();
    }
    iEmpty = true;
    iPageNo = 0; iLineNo = 0;
}
项目:kfs    文件:LockboxServiceImpl.java   
protected com.lowagie.text.Document getPdfDoc() throws IOException, DocumentException {

        String reportDropFolder = reportsDirectory + "/" + ArConstants.Lockbox.LOCKBOX_REPORT_SUBFOLDER + "/";
        String fileName = ArConstants.Lockbox.BATCH_REPORT_BASENAME + "_" +
        new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(dateTimeService.getCurrentDate()) + ".pdf";

        //  setup the writer
        File reportFile = new File(reportDropFolder + fileName);
        FileOutputStream fileOutStream;
        fileOutStream = new FileOutputStream(reportFile);
        BufferedOutputStream buffOutStream = new BufferedOutputStream(fileOutStream);

        com.lowagie.text.Document pdfdoc = new com.lowagie.text.Document(PageSize.LETTER, 54, 54, 72, 72);
        PdfWriter.getInstance(pdfdoc, buffOutStream);

        pdfdoc.open();

        return pdfdoc;
    }
项目:kfs    文件:CustomerInvoiceWriteoffBatchServiceImpl.java   
protected com.lowagie.text.Document getPdfDoc() throws IOException, DocumentException {

        String reportDropFolder = reportsDirectory + "/" + ArConstants.CustomerInvoiceWriteoff.CUSTOMER_INVOICE_WRITEOFF_REPORT_SUBFOLDER + "/";
        String fileName = ArConstants.CustomerInvoiceWriteoff.BATCH_REPORT_BASENAME + "_" +
            new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(dateTimeService.getCurrentDate()) + ".pdf";

        //  setup the writer
        File reportFile = new File(reportDropFolder + fileName);
        FileOutputStream fileOutStream;
        fileOutStream = new FileOutputStream(reportFile);
        BufferedOutputStream buffOutStream = new BufferedOutputStream(fileOutStream);

        com.lowagie.text.Document pdfdoc = new com.lowagie.text.Document(PageSize.LETTER, 54, 54, 72, 72);
        PdfWriter.getInstance(pdfdoc, buffOutStream);

        pdfdoc.open();

        return pdfdoc;
    }
项目:primefaces-blueprints    文件:InvestmentSummaryController.java   
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document; 
    pdf.setPageSize(PageSize.A3); 
    pdf.open();  

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Investment Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
项目:primefaces-blueprints    文件:AccountSummaryController.java   
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document;  
    pdf.setPageSize(PageSize.A3);
    pdf.open(); 
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Account Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
项目:primefaces-blueprints    文件:TransactionSummaryController.java   
public void preProcessPDF(Object document) throws IOException,
        BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.setPageSize(PageSize.A4);
    pdf.open();

    ServletContext servletContext = (ServletContext) FacesContext
            .getCurrentInstance().getExternalContext().getContext();
    String logo = servletContext.getRealPath("") + File.separator
            + "resources" + File.separator + "images" + File.separator
            + "logo" + File.separator + "logo.png";
    Image image = Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image);
    // add a couple of blank lines
    pdf.add(Chunk.NEWLINE);
    pdf.add(Chunk.NEWLINE);
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);
    ;
    pdf.add(new Paragraph("Transaction Summary", fontbold));
    // add a couple of blank lines
    pdf.add(Chunk.NEWLINE);
    pdf.add(Chunk.NEWLINE);
}
项目:PDFTestForAndroid    文件:EndPage.java   
/**
 * Demonstrates the use of PageEvents.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 70, 70);
    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "endpage.pdf"));
        writer.setPageEvent(new EndPage());
        document.open();
        String text = "Lots of text. ";
        for (int k = 0; k < 10; ++k)
            text += text;
        document.add(new Paragraph(text));
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}
项目:PDFTestForAndroid    文件:PageNumbersWatermark.java   
/**
 * Generates a document with a header containing Page x of y and with a
 * Watermark on every page.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String args[]) {
    try {
        // step 1: creating the document
        Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
        // step 2: creating the writer
        PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "pageNumbersWatermark.pdf"));
        // step 3: initialisations + opening the document
        writer.setPageEvent(new PageNumbersWatermark());
        doc.open();
        // step 4: adding content
        String text = "some padding text ";
        for (int k = 0; k < 10; ++k)
            text += text;
        Paragraph p = new Paragraph(text);
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        doc.add(p);
        // step 5: closing the document
        doc.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:PDFTestForAndroid    文件:FixedFontWidth.java   
/**
 * Changing the width of font glyphs.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Fixed Font Width");
    // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "fixedfontwidth.pdf"));
        // step 3
        document.open();
        // step 4
        BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false, false, null, null);
        int widths[] = bf.getWidths();
        for (int k = 0; k < widths.length; ++k) {
            if (widths[k] != 0)
                widths[k] = 1000;
        }
        bf.setForceWidthsOutput(true);
        document.add(new Paragraph("A big text to show Helvetica with fixed width.", new Font(bf)));
    } catch (Exception de) {
        de.printStackTrace();
    }
    // step 5
    document.close();
}
项目:PDFTestForAndroid    文件:OpenTypeFont.java   
/**
     * Using oth
     * 
     * @param args
     *            no arguments needed
     */
    public static void main(String[] args) {
        // step 1
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            // step 2
            PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "opentypefont.pdf"));
            // step 3
            document.open();
            // step 4
            //Don't use path read ttf into byte[] instead
//          BaseFont bf = BaseFont.createFont("liz.otf", BaseFont.CP1252, true);
            InputStream inputStream = PdfTestRunner.getActivity().getResources().openRawResource(R.raw.liz);
            byte[] buffer = new byte[inputStream.available()];
            inputStream.read(buffer);
            BaseFont bf = BaseFont.createFont("freesans.ttf", BaseFont.CP1252, true, false, buffer, null);
            String text = "Some text with the otf font LIZ.";
            document.add(new Paragraph(text, new Font(bf, 14)));
        } catch (Exception de) {
            de.printStackTrace();
        }
        // step 5
        document.close();
    }
项目:PDFTestForAndroid    文件:SpaceWordRatio.java   
/**
 * Space Word Ratio.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Space Word Ratio");
    // step 1
    Document document = new Document(PageSize.A4, 50, 350, 50, 50);
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "spacewordratio.pdf"));
        // step 3
        document.open();
        // step 4
        String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
        Paragraph p = new Paragraph(text);
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(p);
        document.newPage();
        writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
        document.add(p);
    } catch (Exception de) {
        de.printStackTrace();
    }
    // step 5
    document.close();
}
项目:oscar-old    文件:ConsultationPDFCreator.java   
/**
 * Prints the consultation request.
 * @throws IOException when an error with the output stream occurs
 * @throws DocumentException when an error in document construction occurs
 */
public void printPdf() throws IOException, DocumentException {

    // Create the document we are going to write to
    document = new Document();
    PdfWriter.getInstance(document, os);

    document.setPageSize(PageSize.LETTER);
    document.addTitle(getResource("msgConsReq"));
    document.addCreator("OSCAR");
    document.open();

    // Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
            BaseFont.NOT_EMBEDDED);
    headerFont = new Font(bf, 14, Font.BOLD);
    infoFont = new Font(bf, 12, Font.NORMAL);
    font = new Font(bf, 9, Font.NORMAL);
    boldFont = new Font(bf, 10, Font.BOLD);
    bigBoldFont = new Font(bf, 12, Font.BOLD);

    createConsultationRequest();

    document.close();
}
项目:oscar-old    文件:EFormPDFServlet.java   
private void addDocumentProps(Document document, String title, Properties props) {
    document.addTitle(title);
    document.addSubject("");
    document.addKeywords("pdf, itext");
    document.addCreator("OSCAR");
    document.addAuthor("");
    document.addHeader("Expires", "0");

    // A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA
    // and FLSE
    // the following shows a temp way to get a print page size
    final String PAGESIZE = "printPageSize";
    Rectangle pageSize = PageSize.LETTER;
    if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE)))
        pageSize = PageSize.HALFLETTER;
    if ("PageSize.A6".equals(props.getProperty(PAGESIZE)))
        pageSize = PageSize.A6;
    document.setPageSize(pageSize);
    document.open();
}