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

项目:citizensLoader4a    文件:PDFTextWritter.java   
/**
     * Título del documento.
     * @param document Documento en cuestión
     * @throws DocumentException Excepcion generada por algún problema
     */
    private void addTitlePage(Document document) throws DocumentException {
        Paragraph preface = new Paragraph();
        addEmptyLine(preface, 1);
        preface.add(new Paragraph("CitizensLoader PDF", catFont));

//      addEmptyLine(preface, 1);
//      // Will create: Report generated by: _name, _date
//      preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//              smallBold));
//      addEmptyLine(preface, 3);
//      preface.add(new Paragraph("This document describes something which is very important ", smallBold));
//
//      addEmptyLine(preface, 8);
//
//      preface.add(new Paragraph(
//              "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
//              redFont));
//
//      document.add(preface);
//      // Start a new page
//      document.newPage();
        document.add(preface);
        addEmptyLine(preface, 2);
    }
项目:unitimes    文件:PDFPrinter.java   
@Override
public void close() throws IOException {
    try {
        float width = 0;
        float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0;
        for (int i = 0; i < iMaxWidth.length; i++)
            if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; }
        Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f);
        PdfWriter writer = PdfWriter.getInstance(document, iOutput);
        writer.setPageEvent(new PdfEventHandler());
        document.open();
        iTable.setWidths(w);
        document.add(iTable);
        document.close();
    } catch (DocumentException e) {
        throw new IOException(e.getMessage(), e);
    }
}
项目:citizensLoader4b    文件:WordLetter.java   
@Override
protected void crearCarta(Citizen citizen)
        throws FileNotFoundException, DocumentException, IOException {
    XWPFDocument documento = new XWPFDocument();
    File folder = new File("Letter/WORD");
    folder.mkdir();
    letter = new FileOutputStream(
            "Letter/WORD/" + citizen.getDni() + ".docx");
    XWPFParagraph paragraph = documento.createParagraph();
    XWPFRun run = paragraph.createRun();
    run.setText("Usuario: " + citizen.getDni());
    run.addBreak();
    run.addBreak();
    run.setText("Password: " + citizen.getPassword());
    documento.write(letter);
    documento.close();
}
项目:citizensLoader4a    文件:PDFTextWritter.java   
@Override
public void createDocument(String documentName, String content) throws CitizenException {
    String realPath = FILE_PATH + documentName + ".pdf";
    Document doc = new Document();
    try {
        PdfWriter.getInstance(doc, new FileOutputStream(realPath));
        doc.open();
        addMetaData(doc);
        addTitlePage(doc);
        addContent(doc, content);
    } catch (DocumentException | FileNotFoundException e) {
        throw new CitizenException("Error al generar documento pdf" +
                " ["+ FILE_PATH+documentName+".pdf] | ["+this.getClass().getName()+"]");
    } finally {
        if (doc != null) {
            doc.close();
        }
    }

}
项目:twainBDirect    文件:ImageManager.java   
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
    try {
        //Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
        Image img = Image.getInstance(bufeBufferedImage, null);
        Document document = new Document(img);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
        //--
        document.open();
        img.setAbsolutePosition(0, 0);
        //--
        document.add(img);
        //--
        document.close();
    } catch (DocumentException | IOException e) {
        System.out.println("Intern Log : " + e.getMessage());
    }
}
项目:unitimes    文件:MultipleCourseEnrollmentsAuditReport.java   
@Override
public void printReport() throws DocumentException {
       setHeader(buildHeaderString());
       List results = getAuditResults(getSubjectAreas());
       Vector<String> lines = new Vector<String>();
       Iterator it = results.iterator();
       while(it.hasNext()) {
        MultipleCourseEnrollmentsAuditResult result = new MultipleCourseEnrollmentsAuditResult((Object[]) it.next());
        lines.add(buildLineString(result));
       }
       printHeader();
       for (String str : lines) {
               println(str);
       }
       if (!lines.isEmpty()){
        lastPage();
       }

}
项目:unitimes    文件:EnrollmentsViolatingCourseStructureAuditReport.java   
@Override
public void printReport() throws DocumentException {
       setHeader(buildHeaderString());
       List results = getAuditResults(getSubjectAreas());
       Vector<String> lines = new Vector<String>();
       Iterator it = results.iterator();
       while(it.hasNext()) {
        EnrollmentsViolatingCourseStructureAuditResult result = new EnrollmentsViolatingCourseStructureAuditResult((Object[]) it.next());
        lines.add(buildLineString(result));
       }
       printHeader();
       for (String str : lines) {
               println(str);
       }
       if (!lines.isEmpty()){
        lastPage();
       }
}
项目:unitimes    文件:MissingCourseEnrollmentsAuditReport.java   
@Override
public void printReport() throws DocumentException {
       setHeader(buildHeaderString());
       List results = getAuditResults(getSubjectAreas());
       Vector<String> lines = new Vector<String>();
       Iterator it = results.iterator();
       while(it.hasNext()) {
        MissingCourseEnrollmentsAuditResult result = new MissingCourseEnrollmentsAuditResult((Object[]) it.next());
        lines.add(buildLineString(result));
       }
       printHeader();
       for (String str : lines) {
               println(str);
       }
       if (!lines.isEmpty()){
        lastPage();
       }

}
项目: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;
}
项目:unitimes    文件:PdfWorksheet.java   
public static boolean print(OutputStream out, Collection<SubjectArea> subjectAreas) throws IOException, DocumentException {
    TreeSet courses = new TreeSet(new Comparator() {
        public int compare(Object o1, Object o2) {
            CourseOffering co1 = (CourseOffering)o1;
            CourseOffering co2 = (CourseOffering)o2;
            int cmp = co1.getCourseName().compareTo(co2.getCourseName());
            if (cmp != 0) return cmp;
            return co1.getUniqueId().compareTo(co2.getUniqueId());
        }
    });
    String subjectIds = "";
    for (SubjectArea sa: subjectAreas)
        subjectIds += (subjectIds.isEmpty() ? "" : ",") + sa.getUniqueId();
    courses.addAll(SessionDAO.getInstance().getSession().createQuery(
            "select co from CourseOffering co where  co.subjectArea.uniqueId in (" + subjectIds + ")").list());
    if (courses.isEmpty()) return false;
    PdfWorksheet w = new PdfWorksheet(out, subjectAreas, null);
    for (Iterator i=courses.iterator();i.hasNext();) {
        w.print((CourseOffering)i.next());
    }
    w.lastPage();
    w.close();
    return true;
}
项目: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();
}
项目:itext2    文件:PdfPages.java   
int reorderPages(int order[]) throws DocumentException {
    if (order == null)
        return pages.size();
    if (parents.size() > 1)
        throw new DocumentException("Page reordering requires a single parent in the page tree. Call PdfWriter.setLinearMode() after open.");
    if (order.length != pages.size())
        throw new DocumentException("Page reordering requires an array with the same size as the number of pages.");
    int max = pages.size();
    boolean temp[] = new boolean[max];
    for (int k = 0; k < max; ++k) {
        int p = order[k];
        if (p < 1 || p > max)
            throw new DocumentException("Page reordering requires pages between 1 and " + max + ". Found " + p + ".");
        if (temp[p - 1])
            throw new DocumentException("Page reordering requires no page repetition. Page " + p + " is repeated.");
        temp[p - 1] = true;
    }
    Object copy[] = pages.toArray();
    for (int k = 0; k < max; ++k) {
        pages.set(k, copy[order[k] - 1]);
    }
    return max;
}
项目:itext2    文件:CJKFont.java   
void writeFont(PdfWriter writer, PdfIndirectReference ref, Object params[]) throws DocumentException, IOException {
    IntHashtable cjkTag = (IntHashtable)params[0];
    PdfIndirectReference ind_font = null;
    PdfObject pobj = null;
    PdfIndirectObject obj = null;
    pobj = getFontDescriptor();
    if (pobj != null){
        obj = writer.addToBody(pobj);
        ind_font = obj.getIndirectReference();
    }
    pobj = getCIDFont(ind_font, cjkTag);
    if (pobj != null){
        obj = writer.addToBody(pobj);
        ind_font = obj.getIndirectReference();
    }
    pobj = getFontBaseType(ind_font);
    writer.addToBody(pobj, ref);
}
项目:OSCAR-ConCert    文件:SummaryOfActionsAndCommentsReportGenerator.java   
private PdfPTable createNeedHeader(String name) throws DocumentException {
    Font whiteFont = new Font(Font.HELVETICA,14,Font.BOLD,Color.WHITE);
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.setWidths(new float[]{0.10f,0.20f,0.70f});
    PdfPCell emptyCell = new PdfPCell();
    emptyCell.setBorder(0);
    table.addCell(emptyCell);

    PdfPCell headerCell = new PdfPCell();
    headerCell.setColspan(2);
    headerCell.setPhrase(new Phrase(name,whiteFont));
    headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerCell.setBackgroundColor(Color.LIGHT_GRAY);
    table.addCell(headerCell);
    return table;
}
项目:itext2    文件:PushbuttonField.java   
private float calculateFontSize(float w, float h) throws IOException, DocumentException {
    BaseFont ufont = getRealFont();
    float fsize = fontSize;
    if (fsize == 0) {
        float bw = ufont.getWidthPoint(text, 1);
        if (bw == 0)
            fsize = 12;
        else
            fsize = w / bw;
        float nfsize = h / (1 - ufont.getFontDescriptor(BaseFont.DESCENT, 1));
        fsize = Math.min(fsize, nfsize);
        if (fsize < 4)
            fsize = 4;
    }
    return fsize;
}
项目:jasperreports    文件:JRPdfExporter.java   
/**
 *
 */
protected void exportPage(JRPrintPage page) throws JRException, DocumentException, IOException
{
    tagHelper.startPage();

    Collection<JRPrintElement> elements = page.getElements();
    exportElements(elements);

    tagHelper.endPage();

    JRExportProgressMonitor progressMonitor = getCurrentItemConfiguration().getProgressMonitor();
    if (progressMonitor != null)
    {
        progressMonitor.afterPageExport();
    }
}
项目:OSCAR-ConCert    文件:PDFController.java   
private void setPageNumbers() throws DocumentException, IOException {       

    int pages = getReader().getNumberOfPages();
    int i = 0;  
    PdfContentByte overContent;
    Rectangle pageSize = null;
    BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);

    while (i < pages) {
        i++;
        overContent = getStamper().getOverContent(i);
        pageSize = overContent.getPdfDocument().getPageSize();
        overContent.beginText();
        overContent.setFontAndSize(font, 9);
        overContent.setTextMatrix(pageSize.getWidth() - 50, pageSize.getHeight() - 70);
        overContent.showText("Page " + i + " of " + pages);
        overContent.endText();
    }
}
项目:dhis2-core    文件:DefaultPdfDataEntryFormService.java   
private void addCell_WithDropDownListField( PdfPTable table, Rectangle rect, PdfWriter writer, PdfPCell cell, String strfldName, String[] optionList,
    String[] valueList ) throws IOException, DocumentException
{
    TextField textList = new TextField( writer, rect, strfldName );

    textList.setChoices( optionList );
    textList.setChoiceExports( valueList );

    textList.setBorderWidth( 1 );
    textList.setBorderColor( Color.BLACK );
    textList.setBorderStyle( PdfBorderDictionary.STYLE_SOLID );
    textList.setBackgroundColor( COLOR_BACKGROUDTEXTBOX );

    PdfFormField dropDown = textList.getComboField();

    cell.setCellEvent( new PdfFieldCell( dropDown, rect.getWidth(), rect.getHeight(), writer ) );

    table.addCell( cell );
}
项目:itext2    文件:RtfWriter2.java   
/**
 * Adds an Element to the Document
 *
 * @param element The element to be added
 * @return <code>false</code>
 * @throws DocumentException
 */
public boolean add(Element element) throws DocumentException {
    if (pause) {
        return false;
    }
    RtfBasicElement[] rtfElements = rtfDoc.getMapper().mapElement(element);
    if(rtfElements.length != 0) {
        for(int i = 0; i < rtfElements.length; i++) {
            if(rtfElements[i] != null) {
                rtfDoc.add(rtfElements[i]);
            }
        }
        return true;
    } else {
        return false;
    }
}
项目:itext2    文件:TablePdfTest.java   
@Test
public void testTableSpacingPercentage() throws FileNotFoundException,
        DocumentException {
    Document document = PdfTestBase
            .createPdf("testTableSpacingPercentage.pdf");
    document.setMargins(72, 72, 72, 72);
    document.open();
    PdfPTable table = new PdfPTable(1);
    table.setSpacingBefore(20);
    table.setWidthPercentage(100);
    PdfPCell cell;
    cell = new PdfPCell();
    Phrase phase = new Phrase("John Doe");
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // This has no
                                                        // effect
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // This has no effect
    cell.addElement(phase);
    table.addCell(cell);
    document.add(table);
    document.close();
}
项目: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    文件:PreventionPrintAction.java   
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){

 if(!securityInfoManager.hasPrivilege(LoggedInInfo.getLoggedInInfoFromSession(request), "_prevention", "r", null)) {
  throw new SecurityException("missing required security object (_prevention)");
 }


    try {           
        PreventionPrintPdf pdf = new PreventionPrintPdf();
        pdf.printPdf(request, response);

    }catch(DocumentException de) {            
         logger.error("", de);
         request.setAttribute("printError", new Boolean(true));
         return mapping.findForward("error");
    }
    catch(IOException ioe) {
         logger.error("", ioe);
         request.setAttribute("printError", new Boolean(true));
         return mapping.findForward("error");
    } 

    return null;
}
项目:itext2    文件:WritePdfTest.java   
private void addPageNumbers(File file, String fileName) throws IOException, DocumentException {
        PdfReader reader = new PdfReader(file.getAbsolutePath());
        int n = reader.getNumberOfPages();
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fileName));
        int i = 0;
        PdfContentByte over;
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                BaseFont.EMBEDDED);
        float width = reader.getPageSize(1).getWidth();
        while (i < n) {
            i++;
            over = stamp.getOverContent(i);
            over.beginText();
            over.setFontAndSize(bf, PAGE_NUMBER_FONT_SIZE);
            over.setTextMatrix((width / 2) - (PAGE_NUMBER_WIDTH / 2), PAGE_NUMBER_HEIGHT);
            over.showText(i + "/" + n);
            over.endText();
        }
        stamp.close();

}
项目:citizensLoader4b    文件:TXTLetter.java   
@Override
protected void crearCarta(Citizen citizen)
        throws DocumentException, IOException {
    File letter = new File("Letter/TXT/" + citizen.getDni() + ".txt");
    writer = new FileWriter(letter);
    writer.write("Usuario: " + citizen.getDni() + "\n" + "Password: "
            + citizen.getPassword());
}
项目:unitimes    文件:InstructorExamReport.java   
public void printReport(ExamInstructorInfo instructor) throws DocumentException {
    TreeSet<ExamAssignmentInfo> exams = new TreeSet();
    for (ExamAssignmentInfo exam:getExams()) {
        if (exam.getPeriod()==null) continue;
        if (exam.getInstructors().contains(instructor));
    }
    if (exams.isEmpty()) return;
    printHeader();
    printReport(instructor, exams);
    lastPage();
}
项目:unitimes    文件:StudentExamReport.java   
public void printReport(Long studentId) throws DocumentException {
    TreeSet<ExamSectionInfo> sections = new TreeSet();
    for (ExamAssignmentInfo exam : getExams()) {
        if (exam.getPeriod()==null) continue;
        for (ExamSectionInfo section : exam.getSectionsIncludeCrosslistedDummies())
            if (section.getStudentIds().contains(studentId)) sections.add(section);
    }
    if (sections.isEmpty()) return;
    Student student = new StudentDAO().get(studentId);
    printHeader();
    printReport(student, sections);
    lastPage();
}
项目:unitimes    文件:ConflictsByCourseAndStudentReport.java   
public ConflictsByCourseAndStudentReport(int mode, File file, Session session, ExamType examType, Collection<SubjectArea> subjectAreas, Collection<ExamAssignmentInfo> exams) throws IOException, DocumentException {
    super(mode, file, "CONFLICTS BY COURSE AND STUDENT", session, examType, subjectAreas, exams);
    sLog.debug("  Loading students ...");
    for (Iterator i=new StudentDAO().getSession().createQuery("select s.uniqueId, s.externalUniqueId, s.lastName, s.firstName, s.middleName from Student s where s.session.uniqueId=:sessionId").setLong("sessionId", session.getUniqueId()).iterate();i.hasNext();) {
        Object[] o = (Object[])i.next();
        if (o[2]!=null)
            iStudentNames.put((Long)o[0], (String)o[2]+(o[3]==null?"":" "+(String)o[3])+(o[4]==null?"":" "+(String)o[4]));
        else if (o[1]!=null)
            iStudentNames.put((Long)o[0], (String)o[1]);
        else
            iStudentNames.put((Long)o[0], "N/A");
    }
}
项目:unitimes    文件:PdfLegacyExamReport.java   
public PdfLegacyExamReport(int mode, OutputStream out, String title, Session session, ExamType examType, Collection<SubjectArea> subjectAreas, Collection<ExamAssignmentInfo> exams) throws DocumentException, IOException {
    super(mode, out, title,
            ApplicationProperty.ExaminationPdfReportTitle.value(examType == null ? "all" : examType.getReference(), examType == null ? "EXAMINATIONS" : examType.getLabel().toUpperCase() + " EXAMINATIONS"),
            title + " -- " + session.getLabel(), session.getLabel());
    if (subjectAreas!=null && subjectAreas.size() == 1) setFooter(subjectAreas.iterator().next().getSubjectAreaAbbreviation());
    iExams = exams;
    iSession = session;
    iExamType = examType;
    iSubjectAreas = subjectAreas;
    iDispRooms = "true".equals(System.getProperty("room","true"));
    iDispNote = "true".equals(System.getProperty("note","false"));
    iCompact = "true".equals(System.getProperty("compact", "false"));
    iNoRoom = System.getProperty("noroom", ApplicationProperty.ExaminationsNoRoomText.value());
    iDirect = "true".equals(System.getProperty("direct","true"));
    iM2d = "true".equals(System.getProperty("m2d",(examType == null || examType.getType() == ExamType.sExamTypeFinal?"true":"false")));
    iBtb = "true".equals(System.getProperty("btb","false"));
    iLimit = Integer.parseInt(System.getProperty("limit", "-1"));
    iItype = "true".equals(System.getProperty("itype", ApplicationProperty.ExaminationReportsShowInstructionalType.value()));
    iTotals = "true".equals(System.getProperty("totals","true"));
    iUseClassSuffix = "true".equals(System.getProperty("suffix", ApplicationProperty.ExaminationReportsClassSufix.value()));
    iExternal = ApplicationProperty.ExaminationReportsExternalId.isTrue();
    iDispLimits = "true".equals(System.getProperty("verlimit","true"));
    iClassSchedule = "true".equals(System.getProperty("cschedule", ApplicationProperty.ExaminationPdfReportsIncludeClassSchedule.value()));
    iDispFullTermDates = "true".equals(System.getProperty("fullterm","false"));
    iRoomDisplayNames = "true".equals(System.getProperty("roomDispNames", "true"));
    iFullTermCheckDatePattern = ApplicationProperty.ExaminationPdfReportsFullTermCheckDatePattern.isTrue();
    iMeetingTimeUseEvents = ApplicationProperty.ExaminationPdfReportsUseEventsForMeetingTimes.isTrue();
    if (System.getProperty("since")!=null) {
        try {
            iSince = new SimpleDateFormat(System.getProperty("sinceFormat","MM/dd/yy")).parse(System.getProperty("since"));
        } catch (Exception e) {
            sLog.error("Unable to parse date "+System.getProperty("since")+", reason: "+e.getMessage());
        }
    }
    setRoomCode(System.getProperty("roomcode", ApplicationProperty.ExaminationRoomCode.value()));
}
项目:unitimes    文件:PdfLegacyReport.java   
public PdfLegacyReport(int mode, File file, String title, String title2, String subject, String session) throws IOException, DocumentException{
    iTitle = title;
    iTitle2 = title2;
    iSubject = subject;
    iSession = session;

    if (file!=null) open(new FileOutputStream(file), mode);
}
项目:unitimes    文件:PdfLegacyReport.java   
public PdfLegacyReport(int mode, OutputStream out, String title, String title2, String subject, String session) throws IOException, DocumentException{
    iTitle = title;
    iTitle2 = title2;
    iSubject = subject;
    iSession = session;

    if (out!=null) open(out, mode);
}
项目:unitimes    文件:PdfLegacyReport.java   
public void printHeader() throws DocumentException {
    out(renderEnd(
            renderMiddle("UniTime "+Constants.getVersion(),iTitle),
            iTitle2));
    out(mpad(
            new SimpleDateFormat("EEE MMM dd, yyyy").format(new Date()),
            iSession,' ',iNrChars));
    outln('=');
    iLineNo=0;
    if (iCont!=null && iCont.length()>0)
        println("("+iCont+" Continued)");
    if (iHeader!=null) for (int i=0;i<iHeader.length;i++) println(iHeader[i]);
    headerPrinted();
}
项目:unitimes    文件:PdfLegacyReport.java   
protected void printFooter() throws DocumentException {
    iEmpty=false;
    out("");
    out(renderEnd(renderMiddle((iFooter==null?"":iFooter),"Page "+(iPageNo+1)),(iPageId==null||iPageId.length()==0?"":iPageId)+"  "));
    if (iPrint!=null) {
        iPrint.print(iBuffer);
    } else {
        //FIXME: For some reason when a line starts with space, the line is shifted by one space in the resulting PDF (when using iText 5.0.2)
        Paragraph p = new Paragraph(iBuffer.toString().replace("\n ", "\n  "), PdfFont.getFixedFont());
        p.setLeading(9.5f); //was 13.5f
        iDoc.add(p);
    }
    iBuffer = new StringBuffer();
    iPageNo++;
}
项目:unitimes    文件:PdfLegacyReport.java   
protected void newPage() throws DocumentException {
    while (iLineNo<iNrLines) {
        out(""); iLineNo++;
    }
    printFooter();
    if (iPrint!=null) {
        iPrint.print("\f\n");
    } else {
        iDoc.newPage();
    }
    printHeader();
}
项目:unitimes    文件:PdfLegacyReport.java   
public void close() throws IOException, DocumentException {
    if (isEmpty()) { println("Nothing to report."); lastPage(); }
    if (iPrint!=null) {
        iPrint.flush(); iPrint.close();
    } else {
        iDoc.close();
        iOut.close();
    }
}
项目:unitimes    文件:PdfEventHandler.java   
/**
   * Constructor for PdfEventHandler
   * 
   */
  public PdfEventHandler() throws DocumentException, IOException {

    super();

    Font font = PdfFont.getSmallFont();
setBaseFont(font.getBaseFont());
setFontSize(font.getSize());

      return;
   }
项目:unitimes    文件:PdfEventHandler.java   
/**
   * Initialize Pdf footer
   * @param document
   * @param outputStream
   * @return PdfWriter
   */
  public static PdfWriter initFooter(Document document, OutputStream outputStream) 
        throws DocumentException, IOException {

PdfWriter iWriter = PdfWriter.getInstance(document, outputStream);
iWriter.setPageEvent(new PdfEventHandler());

return iWriter;
  }
项目:unitimes    文件:PdfWorksheet.java   
private PdfWorksheet(OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber) throws IOException, DocumentException  {
    iUseCommitedAssignments = ApplicationProperty.WorksheetPdfUseCommittedAssignments.isTrue();
    iSubjectAreas = new TreeSet<SubjectArea>(new Comparator<SubjectArea>() {
        @Override
        public int compare(SubjectArea s1, SubjectArea s2) {
            return s1.getSubjectAreaAbbreviation().compareTo(s2.getSubjectAreaAbbreviation());
        }
    });
    iSubjectAreas.addAll(subjectAreas);
    iCourseNumber = courseNumber;
    if (iCourseNumber!=null && (iCourseNumber.trim().length()==0 || "*".equals(iCourseNumber.trim().length())))
        iCourseNumber = null;
    iDoc = new Document(PageSize.LETTER.rotate());

    iOut = out;
    PdfWriter.getInstance(iDoc, iOut);

    String session = null;
    String subjects = "";
    for (SubjectArea sa: iSubjectAreas) {
        if (subjects.isEmpty()) subjects += ", ";
        subjects += sa.getSubjectAreaAbbreviation();
        if (session == null) session += sa.getSession().getLabel();
    }
    iDoc.addTitle(subjects + (iCourseNumber==null?"":" "+iCourseNumber) + " Worksheet");
    iDoc.addAuthor(ApplicationProperty.WorksheetPdfAuthor.value().replace("%", Constants.getVersion()));
    iDoc.addSubject(subjects + (session == null ? "" : " -- " + session));
    iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org");
    if (!iSubjectAreas.isEmpty())
        iCurrentSubjectArea = iSubjectAreas.first();

    iDoc.open();

    printHeader();
}
项目:unitimes    文件:PdfWorksheet.java   
public static boolean print(OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber) throws IOException, DocumentException {
     TreeSet courses = new TreeSet(new Comparator() {
         public int compare(Object o1, Object o2) {
             CourseOffering co1 = (CourseOffering)o1;
             CourseOffering co2 = (CourseOffering)o2;
             int cmp = co1.getCourseName().compareTo(co2.getCourseName());
             if (cmp!=0) return cmp;
             return co1.getUniqueId().compareTo(co2.getUniqueId());
         }
     });
     List<Long> subjectIds = new ArrayList<Long>();
     for (SubjectArea sa: subjectAreas)
        subjectIds.add(sa.getUniqueId());
     String query = "select co from CourseOffering co where  co.subjectArea.uniqueId in :subjectIds";
     if (courseNumber != null && !courseNumber.trim().isEmpty()) {
if (courseNumber.indexOf('*') >= 0) {
    query += " and co.courseNbr like :courseNbr ";
} else {
    query += " and co.courseNbr = :courseNbr ";
}
     }
     Query q = new SessionDAO().getSession().createQuery(query);
     q.setParameterList("subjectIds", subjectIds);
     if (courseNumber != null && !courseNumber.trim().isEmpty())
        q.setParameter("courseNbr", ApplicationProperty.CourseOfferingNumberUpperCase.isTrue()? courseNumber.trim().replace('*', '%').toUpperCase() : courseNumber.trim().replace('*', '%'));
     courses.addAll(q.list());
     if (courses.isEmpty()) return false;
     PdfWorksheet w = new PdfWorksheet(out, subjectAreas, courseNumber);
     for (Iterator i=courses.iterator();i.hasNext();) {
         w.print((CourseOffering)i.next());
     }
     w.lastPage();
     w.close();
     return true;
 }
项目:unitimes    文件:PdfWorksheet.java   
protected void printHeader() throws DocumentException {
    out(renderMiddle(
            ApplicationProperty.WorksheetPdfAuthor.value().replace("%", Constants.getVersion()),
            ApplicationProperty.WorksheetPdfTitle.value()
            ));
    out(mpad(
            new SimpleDateFormat("EEE MMM dd, yyyy").format(new Date()),
            iCurrentSubjectArea.getSession().getAcademicInitiative()+" "+
            iCurrentSubjectArea.getSession().getAcademicTerm()+" "+
            iCurrentSubjectArea.getSession().getAcademicYear(),' ',sNrChars));
    outln('=');
    iLineNo=0;
    if (iCourseOffering!=null)
        println("("+iCourseOffering.getCourseName()+" Continued)");
}
项目:unitimes    文件:PdfWorksheet.java   
protected void printFooter() throws DocumentException {
    out("");
    out(renderEnd(renderMiddle("","Page "+(iPageNo+1)),"<"+iCurrentSubjectArea.getSubjectAreaAbbreviation()+(iCourseNumber!=null?" "+iCourseNumber:"")+">  "));
    //FIXME: For some reason when a line starts with space, the line is shifted by one space in the resulting PDF (when using iText 5.0.2)
    Paragraph p = new Paragraph(iBuffer.toString().replace("\n ", "\n  "), PdfFont.getFixedFont());
    p.setLeading(9.5f); //was 13.5f
    iDoc.add(p);
    iBuffer = new StringBuffer();
    iPageNo++;
}