Method from org.apache.pdfbox.pdmodel.PDPage Detail: |
public BufferedImage convertToImage() throws IOException {
//note we are doing twice as many pixels because
//the default size is not really good resolution,
//so create an image that is twice the size
//and let the client scale it down.
return convertToImage(8, 2 * DEFAULT_USER_SPACE_UNIT_DPI);
}
Convert this page to an output image with 8 bits per pixel and the double
default screen resolution. |
public BufferedImage convertToImage(int imageType,
int resolution) throws IOException {
PDRectangle mBox = findMediaBox();
float widthPt = mBox.getWidth();
float heightPt = mBox.getHeight();
float scaling = resolution / (float)DEFAULT_USER_SPACE_UNIT_DPI;
int widthPx = Math.round(widthPt * scaling);
int heightPx = Math.round(heightPt * scaling);
//TODO The following reduces accuracy. It should really be a Dimension2D.Float.
Dimension pageDimension = new Dimension( (int)widthPt, (int)heightPt );
BufferedImage retval = new BufferedImage( widthPx, heightPx, imageType );
Graphics2D graphics = (Graphics2D)retval.getGraphics();
graphics.setBackground( Color.WHITE );
graphics.clearRect( 0, 0, retval.getWidth(), retval.getHeight() );
graphics.scale( scaling, scaling );
PageDrawer drawer = new PageDrawer();
drawer.drawPage( graphics, this, pageDimension );
//TODO This could be done directly by manipulating the transformation matrix before painting.
//That could result in a better image quality.
try
{
int rotation = findRotation();
if (rotation == 90 || rotation == 270)
{
int w = retval.getWidth();
int h = retval.getHeight();
BufferedImage rotatedImg = new BufferedImage(w, h, retval.getType());
Graphics2D g = rotatedImg.createGraphics();
g.rotate(Math.toRadians(rotation), w/2, h/2);
g.drawImage(retval, null, 0, 0);
}
}
catch (ImagingOpException e)
{
log.warn("Unable to rotate page image", e);
}
return retval;
}
Convert this page to an output image. |
public boolean equals(Object other) {
return other instanceof PDPage && ((PDPage)other).getCOSObject() == this.getCOSObject();
}
|
public PDRectangle findCropBox() {
PDRectangle retval = getCropBox();
PDPageNode parent = getParent();
if( retval == null && parent != null )
{
retval = findParentCropBox( parent );
}
//default value for cropbox is the media box
if( retval == null )
{
retval = findMediaBox();
}
return retval;
}
This will find the CropBox for this page by looking up the hierarchy until
it finds them. |
public PDRectangle findMediaBox() {
PDRectangle retval = getMediaBox();
if( retval == null && getParent() != null )
{
retval = getParent().findMediaBox();
}
return retval;
}
This will find the MediaBox for this page by looking up the hierarchy until
it finds them. |
public PDResources findResources() {
PDResources retval = getResources();
PDPageNode parent = getParent();
if( retval == null && parent != null )
{
retval = parent.findResources();
}
return retval;
}
This will find the resources for this page by looking up the hierarchy until
it finds them. |
public int findRotation() {
int retval = 0;
Integer rotation = getRotation();
if( rotation != null )
{
retval = rotation.intValue();
}
else
{
PDPageNode parent = getParent();
if( parent != null )
{
retval = parent.findRotation();
}
}
return retval;
}
This will find the rotation for this page by looking up the hierarchy until
it finds them. |
public PDPageAdditionalActions getActions() {
COSDictionary addAct = (COSDictionary) page.getDictionaryObject(COSName.AA);
if (addAct == null)
{
addAct = new COSDictionary();
page.setItem(COSName.AA, addAct);
}
return new PDPageAdditionalActions(addAct);
}
|
public List getAnnotations() throws IOException {
COSArrayList retval = null;
COSArray annots = (COSArray)page.getDictionaryObject(COSName.ANNOTS);
if (annots == null)
{
annots = new COSArray();
page.setItem(COSName.ANNOTS, annots);
retval = new COSArrayList(new ArrayList(), annots);
}
else
{
List actuals = new ArrayList();
for (int i=0; i < annots.size(); i++)
{
COSBase item = annots.getObject(i);
actuals.add( PDAnnotation.createAnnotation( item ) );
}
retval = new COSArrayList(actuals, annots);
}
return retval;
}
This will return a list of the Annotations for this page. |
public PDRectangle getArtBox() {
PDRectangle retval = null;
COSArray array = (COSArray)page.getDictionaryObject( COSName.ART_BOX );
if( array != null )
{
retval = new PDRectangle( array );
}
else
{
retval = findCropBox();
}
return retval;
}
A rectangle, expressed in default user space units, defining
the extent of the page's meaningful content (including potential
white space) as intended by the page's creator The default isthe CropBox. |
public PDRectangle getBleedBox() {
PDRectangle retval = null;
COSArray array = (COSArray)page.getDictionaryObject( COSName.BLEED_BOX );
if( array != null )
{
retval = new PDRectangle( array );
}
else
{
retval = findCropBox();
}
return retval;
}
A rectangle, expressed in default user space units, defining
the region to which the contents of the page should be clipped
when output in a production environment. The default is the CropBox. |
public COSDictionary getCOSDictionary() {
return page;
}
This will get the underlying dictionary that this class acts on. |
public COSBase getCOSObject() {
return page;
}
Convert this standard java object to a COS object. |
public PDStream getContents() throws IOException {
return PDStream.createFromCOS( page.getDictionaryObject( COSName.CONTENTS ) );
}
This will get the contents of the PDF Page, in the case that the contents
of the page is an array then then the entire array of streams will be
be wrapped and appear as a single stream. |
public PDRectangle getCropBox() {
PDRectangle retval = null;
COSArray array = (COSArray)page.getDictionaryObject( COSName.CROP_BOX);
if( array != null )
{
retval = new PDRectangle( array );
}
return retval;
}
A rectangle, expressed in default user space units,
defining the visible region of default user space. When the page is displayed
or printed, its contents are to be clipped (cropped) to this rectangle
and then imposed on the output medium in some implementationdefined
manner
This will get the CropBox at this page and not look up the hierarchy.
This attribute is inheritable, and findCropBox() should probably used.
This will return null if no CropBox is available at this level. |
public Calendar getLastModified() throws IOException {
return page.getDate( "LastModified" );
}
This will get the date that the content stream was last modified. This
may return null. |
public PDRectangle getMediaBox() {
if( mediaBox == null){
COSArray array = (COSArray)page.getDictionaryObject( COSName.MEDIA_BOX );
if( array != null )
{
mediaBox = new PDRectangle( array );
}
}
return mediaBox;
}
A rectangle, expressed
in default user space units, defining the boundaries of the physical
medium on which the page is intended to be displayed or printed
This will get the MediaBox at this page and not look up the hierarchy.
This attribute is inheritable, and findMediaBox() should probably used.
This will return null if no MediaBox are available at this level. |
public PDMetadata getMetadata() {
PDMetadata retval = null;
COSStream stream = (COSStream)page.getDictionaryObject( COSName.METADATA );
if( stream != null )
{
retval = new PDMetadata( stream );
}
return retval;
}
Get the metadata that is part of the document catalog. This will
return null if there is no meta data for this object. |
public PDPageNode getParent() {
if( parent == null){
COSDictionary parentDic = (COSDictionary)page.getDictionaryObject( "Parent", "P" );
if( parentDic != null )
{
parent = new PDPageNode( parentDic );
}
}
return parent;
}
This is the parent page node. The parent is a required element of the
page. This will be null until this page is added to the document. |
public PDResources getResources() {
PDResources retval = null;
COSDictionary resources = (COSDictionary)page.getDictionaryObject( COSName.RESOURCES );
if( resources != null )
{
retval = new PDResources( resources );
}
return retval;
}
This will get the resources at this page and not look up the hierarchy.
This attribute is inheritable, and findResources() should probably used.
This will return null if no resources are available at this level. |
public Integer getRotation() {
Integer retval = null;
COSNumber value = (COSNumber)page.getDictionaryObject( COSName.ROTATE );
if( value != null )
{
retval = new Integer( value.intValue() );
}
return retval;
}
A value representing the rotation. This will be null if not set at this level
The number of degrees by which the page should
be rotated clockwise when displayed or printed. The value must be a multiple
of 90.
This will get the rotation at this page and not look up the hierarchy.
This attribute is inheritable, and findRotation() should probably used.
This will return null if no rotation is available at this level. |
public List getThreadBeads() {
COSArray beads = (COSArray)page.getDictionaryObject( COSName.B );
if( beads == null )
{
beads = new COSArray();
}
List pdObjects = new ArrayList();
for( int i=0; i< beads.size(); i++)
{
COSDictionary beadDic = (COSDictionary)beads.getObject( i );
PDThreadBead bead = null;
//in some cases the bead is null
if( beadDic != null )
{
bead = new PDThreadBead( beadDic );
}
pdObjects.add( bead );
}
return new COSArrayList(pdObjects, beads);
}
This will get a list of PDThreadBead objects, which are article threads in the
document. This will return an empty list of there are no thread beads. |
public PDRectangle getTrimBox() {
PDRectangle retval = null;
COSArray array = (COSArray)page.getDictionaryObject( COSName.TRIM_BOX );
if( array != null )
{
retval = new PDRectangle( array );
}
else
{
retval = findCropBox();
}
return retval;
}
A rectangle, expressed in default user space units, defining
the intended dimensions of the finished page after trimming.
The default is the CropBox. |
public int hashCode() {
return this.getCOSDictionary().hashCode();
}
|
public int print(Graphics graphics,
PageFormat pageFormat,
int pageIndex) throws PrinterException {
int retval = Printable.PAGE_EXISTS;
try
{
PageDrawer drawer = new PageDrawer();
PDRectangle cropBox = findCropBox();
drawer.drawPage( graphics, this, cropBox.createDimension() );
}
catch( IOException io )
{
throw new PrinterIOException( io );
}
return retval;
}
|
public void setActions(PDPageAdditionalActions actions) {
page.setItem( COSName.AA, actions );
}
|
public void setAnnotations(List annots) {
page.setItem( COSName.ANNOTS, COSArrayList.converterToCOSArray( annots ) );
}
This will set the list of annotations. |
public void setArtBox(PDRectangle artBox) {
if( artBox == null )
{
page.removeItem( COSName.ART_BOX );
}
else
{
page.setItem( COSName.ART_BOX, artBox.getCOSArray() );
}
}
This will set the ArtBox for this page. |
public void setBleedBox(PDRectangle bleedBox) {
if( bleedBox == null )
{
page.removeItem( COSName.BLEED_BOX );
}
else
{
page.setItem( COSName.BLEED_BOX, bleedBox.getCOSArray() );
}
}
This will set the BleedBox for this page. |
public void setContents(PDStream contents) {
page.setItem( COSName.CONTENTS, contents );
}
This will set the contents of this page. |
public void setCropBox(PDRectangle cropBox) {
if( cropBox == null )
{
page.removeItem( COSName.CROP_BOX );
}
else
{
page.setItem( COSName.CROP_BOX, cropBox.getCOSArray() );
}
}
This will set the CropBox for this page. |
public void setMediaBox(PDRectangle mediaBox) {
this.mediaBox = mediaBox;
if( mediaBox == null )
{
page.removeItem( COSName.MEDIA_BOX );
}
else
{
page.setItem( COSName.MEDIA_BOX, mediaBox.getCOSArray() );
}
}
This will set the mediaBox for this page. |
public void setMetadata(PDMetadata meta) {
page.setItem( COSName.METADATA, meta );
}
Set the metadata for this object. This can be null. |
public void setParent(PDPageNode parent) {
this.parent = parent;
page.setItem( COSName.PARENT, parent.getDictionary() );
}
This will set the parent of this page. |
public void setResources(PDResources resources) {
page.setItem( COSName.RESOURCES, resources );
}
This will set the resources for this page. |
public void setRotation(int rotation) {
page.setInt( COSName.ROTATE, rotation );
}
This will set the rotation for this page. |
public void setThreadBeads(List beads) {
page.setItem( COSName.B, COSArrayList.converterToCOSArray( beads ) );
}
This will set the list of thread beads. |
public void setTrimBox(PDRectangle trimBox) {
if( trimBox == null )
{
page.removeItem( COSName.TRIM_BOX );
}
else
{
page.setItem( COSName.TRIM_BOX, trimBox.getCOSArray() );
}
}
This will set the TrimBox for this page. |
public void updateLastModified() {
page.setDate( "LastModified", new GregorianCalendar() );
}
This will update the last modified time for the page object. |