?? pdfdocument.java
字號(hào):
*/ public void resetPageCount() { if (writer != null && writer.isPaused()) { return; } super.resetPageCount(); } /** * Sets the page number. * * @param pageN the new page number */ public void setPageCount(int pageN) { if (writer != null && writer.isPaused()) { return; } super.setPageCount(pageN); } /** * Sets the <CODE>Watermark</CODE>. * * @param watermark the watermark to add * @return <CODE>true</CODE> if the element was added, <CODE>false</CODE> if not. */ public boolean add(Watermark watermark) { if (writer != null && writer.isPaused()) { return false; } this.watermark = watermark; return true; } /** * Removes the <CODE>Watermark</CODE>. */ public void removeWatermark() { if (writer != null && writer.isPaused()) { return; } this.watermark = null; } /** * Sets the margins. * * @param marginLeft the margin on the left * @param marginRight the margin on the right * @param marginTop the margin on the top * @param marginBottom the margin on the bottom * @return a <CODE>boolean</CODE> */ public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) { if (writer != null && writer.isPaused()) { return false; } nextMarginLeft = marginLeft; nextMarginRight = marginRight; nextMarginTop = marginTop; nextMarginBottom = marginBottom; return true; } protected PdfArray rotateAnnotations() { PdfArray array = new PdfArray(); int rotation = pageSize.getRotation() % 360; int currentPage = writer.getCurrentPageNumber(); for (int k = 0; k < annotations.size(); ++k) { PdfAnnotation dic = (PdfAnnotation)annotations.get(k); int page = dic.getPlaceInPage(); if (page > currentPage) { delayedAnnotations.add(dic); continue; } if (dic.isForm()) { if (!dic.isUsed()) { HashMap templates = dic.getTemplates(); if (templates != null) acroForm.addFieldTemplates(templates); } PdfFormField field = (PdfFormField)dic; if (field.getParent() == null) acroForm.addDocumentField(field.getIndirectReference()); } if (dic.isAnnotation()) { array.add(dic.getIndirectReference()); if (!dic.isUsed()) { PdfRectangle rect = (PdfRectangle)dic.get(PdfName.RECT); switch (rotation) { case 90: dic.put(PdfName.RECT, new PdfRectangle( pageSize.top() - rect.bottom(), rect.left(), pageSize.top() - rect.top(), rect.right())); break; case 180: dic.put(PdfName.RECT, new PdfRectangle( pageSize.right() - rect.left(), pageSize.top() - rect.bottom(), pageSize.right() - rect.right(), pageSize.top() - rect.top())); break; case 270: dic.put(PdfName.RECT, new PdfRectangle( rect.bottom(), pageSize.right() - rect.left(), rect.top(), pageSize.right() - rect.right())); break; } } } if (!dic.isUsed()) { dic.setUsed(); try { writer.addToBody(dic, dic.getIndirectReference()); } catch (IOException e) { throw new ExceptionConverter(e); } } } return array; } protected PdfDictionary codeTransition(PdfTransition transition) { PdfDictionary trans = new PdfDictionary(PdfName.TRANS); switch (transition.getType()) { case PdfTransition.SPLITVOUT: trans.put(PdfName.S,new PdfName("Split")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DM,new PdfName("V")); trans.put(PdfName.M,new PdfName("O")); break; case PdfTransition.SPLITHOUT: trans.put(PdfName.S,new PdfName("Split")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DM,new PdfName("H")); trans.put(PdfName.M,new PdfName("O")); break; case PdfTransition.SPLITVIN: trans.put(PdfName.S,new PdfName("Split")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DM,new PdfName("V")); trans.put(PdfName.M,new PdfName("I")); break; case PdfTransition.SPLITHIN: trans.put(PdfName.S,new PdfName("Split")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DM,new PdfName("H")); trans.put(PdfName.M,new PdfName("I")); break; case PdfTransition.BLINDV: trans.put(PdfName.S,new PdfName("Blinds")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DM,new PdfName("V")); break; case PdfTransition.BLINDH: trans.put(PdfName.S,new PdfName("Blinds")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DM,new PdfName("H")); break; case PdfTransition.INBOX: trans.put(PdfName.S,new PdfName("Box")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.M,new PdfName("I")); break; case PdfTransition.OUTBOX: trans.put(PdfName.S,new PdfName("Box")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.M,new PdfName("O")); break; case PdfTransition.LRWIPE: trans.put(PdfName.S,new PdfName("Wipe")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(0)); break; case PdfTransition.RLWIPE: trans.put(PdfName.S,new PdfName("Wipe")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(180)); break; case PdfTransition.BTWIPE: trans.put(PdfName.S,new PdfName("Wipe")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(90)); break; case PdfTransition.TBWIPE: trans.put(PdfName.S,new PdfName("Wipe")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(270)); break; case PdfTransition.DISSOLVE: trans.put(PdfName.S,new PdfName("Dissolve")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); break; case PdfTransition.LRGLITTER: trans.put(PdfName.S,new PdfName("Glitter")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(0)); break; case PdfTransition.TBGLITTER: trans.put(PdfName.S,new PdfName("Glitter")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(270)); break; case PdfTransition.DGLITTER: trans.put(PdfName.S,new PdfName("Glitter")); trans.put(PdfName.D,new PdfNumber(transition.getDuration())); trans.put(PdfName.DI,new PdfNumber(315)); break; } return trans; } /** * Makes a new page and sends it to the <CODE>PdfWriter</CODE>. * * @return a <CODE>boolean</CODE> * @throws DocumentException on error */ public boolean newPage() throws DocumentException { //add by Jin-Hsia Yang isNewpage = true; //end add by Jin-Hsia Yang if (writer.getDirectContent().size() == 0 && writer.getDirectContentUnder().size() == 0 && (pageEmpty || (writer != null && writer.isPaused()))) { return false; } PdfPageEvent pageEvent = writer.getPageEvent(); if (pageEvent != null) pageEvent.onEndPage(writer, this); //Added to inform any listeners that we are moving to a new page (added by David Freels) super.newPage(); // we flush the arraylist with recently written lines flushLines(); // we assemble the resources of this pages PdfResources resources = new PdfResources(); int procset = PdfProcSet.PDF; if (fontDictionary.containsFont()) { resources.add(fontDictionary); procset |= PdfProcSet.TEXT; } if (xObjectDictionary.containsXObject()) { resources.add(xObjectDictionary); procset |= PdfProcSet.IMAGEC; } resources.add(new PdfProcSet(procset)); if (colorDictionary.containsColorSpace()) resources.add(colorDictionary); if (patternDictionary.containsPattern()) resources.add(patternDictionary); if (shadingDictionary.containsShading()) resources.add(shadingDictionary); // we make a new page and add it to the document PdfPage page; int rotation = pageSize.getRotation(); if (rotation == 0) page = new PdfPage(new PdfRectangle(pageSize, rotation), thisCropSize, resources); else page = new PdfPage(new PdfRectangle(pageSize, rotation), thisCropSize, resources, new PdfNumber(rotation)); // we add the transitions if (this.transition!=null) { page.put(PdfName.TRANS,codeTransition(this.transition)); transition = null; } if (this.duration>0) { page.put(PdfName.DUR,new PdfNumber(this.duration)); duration = 0; } // we add the page object additional actions if (pageAA != null) { try { page.put(PdfName.AA, writer.addToBody(pageAA).getIndirectReference()); } catch (IOException ioe) { throw new ExceptionConverter(ioe); } pageAA = null; } // we add the annotations if (annotations.size() > 0) { PdfArray array = rotateAnnotations(); if (array.size() != 0) page.put(PdfName.ANNOTS, array); } if (!open || close) { throw new PdfException("The document isn't open."); } if (text.size() > textEmptySize) text.endText(); else text = null; PdfIndirectReference pageReference = writer.add(page, new PdfContents(writer.getDirectContentUnder(), graphics, text, writer.getDirectContent(), pageSize)); // we initialize the new page initPage(); //add by Jin-Hsia Yang isNewpage = false; //end add by Jin-Hsia Yang return true; } // methods to open and close a document /** * Opens the document. * <P> * You have to open the document before you can begin to add content * to the body of the document.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -