/** * Adds the given font to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param font the font to add * @return the name of the resource in the resources dictionary */ public COSName add(PDFont font) { return add(COSName.FONT, "F", font); }
/** * Adds the given color space to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param colorSpace the color space to add * @return the name of the resource in the resources dictionary */ public COSName add(PDColorSpace colorSpace) { return add(COSName.COLORSPACE, "cs", colorSpace); }
/** * Adds the given form to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param form the form to add * @return the name of the resource in the resources dictionary */ public COSName add(PDFormXObject form) { return add(COSName.XOBJECT, "Form", form); }
/** * Adds the given shading to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param shading the shading to add * @return the name of the resource in the resources dictionary */ public COSName add(PDShading shading) { return add(COSName.SHADING, "sh", shading); }
/** * Adds the given pattern to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param pattern the pattern to add * @return the name of the resource in the resources dictionary */ public COSName add(PDAbstractPattern pattern) { return add(COSName.PATTERN, "p", pattern); }
/** * Adds the given extended graphics state to the resources of the current page and returns the * name for the new resources. Returns the existing resource name if the given item already exists. * * @param extGState the extended graphics state to add * @return the name of the resource in the resources dictionary */ public COSName add(PDExtendedGraphicsState extGState) { return add(COSName.EXT_G_STATE, "gs", extGState); }
/** * Adds the given image to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param image the image to add * @return the name of the resource in the resources dictionary */ public COSName add(PDImageXObject image) { return add(COSName.XOBJECT, "Im", image); }
/** * Adds the given XObject to the resources of the current page and returns the name for the * new resources. Returns the existing resource name if the given item already exists. * * @param xobject the XObject to add * @param prefix the prefix to be used when creating the resource name * @return the name of the resource in the resources dictionary */ public COSName add(PDXObject xobject, String prefix) { return add(COSName.XOBJECT, prefix, xobject); }
/** * Adds the given property list to the resources of the current page and returns the name for * the new resources. Returns the existing resource name if the given item already exists. * * @param properties the property list to add * @return the name of the resource in the resources dictionary */ public COSName add(PDPropertyList properties) { if (properties instanceof PDOptionalContentGroup) { return add(COSName.PROPERTIES, "oc", properties); } else { return add(COSName.PROPERTIES, "Prop", properties); } }
/** * Fills the clipping area with the given shading. * * @param shading Shading resource * @throws IOException If the content stream could not be written * @throws IllegalStateException If the method was called within a text block. */ public void shadingFill(PDShading shading) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: shadingFill is not allowed within a text block."); } writeOperand(resources.add(shading)); writeOperator("sh"); }
/** * Set an extended graphics state. * * @param state The extended graphics state. * @throws IOException If the content stream could not be written. */ public void setGraphicsStateParameters(PDExtendedGraphicsState state) throws IOException { writeOperand(resources.add(state)); writeOperator("gs"); }
/** * Draws the given Form XObject at the current location. * * @param form Form XObject * @throws IOException if the content stream could not be written * @throws IllegalStateException If the method was called within a text block. */ public void drawForm(PDFormXObject form) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawForm is not allowed within a text block."); } writeOperand(resources.add(form)); writeOperator("Do"); }
protected COSName getName(PDColorSpace colorSpace) { if (colorSpace instanceof PDDeviceGray || colorSpace instanceof PDDeviceRGB || colorSpace instanceof PDDeviceCMYK) { return COSName.getPDFName(colorSpace.getName()); } else { return resources.add(colorSpace); } }
/** * Begin a marked content sequence with a reference to an entry in the page resources' * Properties dictionary. * * @param tag the tag * @param propertyList property list * @throws IOException If the content stream could not be written */ public void beginMarkedContent(COSName tag, PDPropertyList propertyList) throws IOException { writeOperand(tag); writeOperand(resources.add(propertyList)); writeOperator("BDC"); }
/** * Draw an image at the x,y coordinates, with the given size. * * @param image The image to draw. * @param x The x-coordinate to draw the image. * @param y The y-coordinate to draw the image. * @param width The width to draw the image. * @param height The height to draw the image. * * @throws IOException If there is an error writing to the stream. * @throws IllegalStateException If the method was called within a text block. */ public void drawImage(PDImageXObject image, float x, float y, float width, float height) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawImage is not allowed within a text block."); } saveGraphicsState(); AffineTransform transform = new AffineTransform(width, 0, 0, height, x, y); transform(new Matrix(transform)); writeOperand(resources.add(image)); writeOperator("Do"); restoreGraphicsState(); }
private COSName createOverlayXObject(PDPage page, LayoutPage layoutPage, COSStream contentStream) { PDFormXObject xobjForm = new PDFormXObject(contentStream); xobjForm.setResources(new PDResources(layoutPage.overlayResources)); xobjForm.setFormType(1); xobjForm.setBBox( layoutPage.overlayMediaBox.createRetranslatedRectangle()); xobjForm.setMatrix(new AffineTransform()); PDResources resources = page.getResources(); return resources.add(xobjForm, "OL"); }
COSName objMapping = resources.add(xobject, xObjectPrefix);
/** * Draw an image at the origin with the given transformation matrix. * * @param image The image to draw. * @param matrix The transformation matrix to apply to the image. * * @throws IOException If there is an error writing to the stream. * @throws IllegalStateException If the method was called within a text block. */ public void drawImage(PDImageXObject image, Matrix matrix) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawImage is not allowed within a text block."); } saveGraphicsState(); AffineTransform transform = matrix.createAffineTransform(); transform(new Matrix(transform)); writeOperand(resources.add(image)); writeOperator("Do"); restoreGraphicsState(); }
private void drawXObject( PDImageXObject xobject, PDResources resources, OutputStream os, float x, float y, float width, float height ) throws IOException { // This is similar to PDPageContentStream.drawXObject() COSName xObjectId = resources.add(xobject); appendRawCommands( os, SAVE_GRAPHICS_STATE ); appendRawCommands( os, formatDecimal.format( width ) ); appendRawCommands( os, SPACE ); appendRawCommands( os, formatDecimal.format( 0 ) ); appendRawCommands( os, SPACE ); appendRawCommands( os, formatDecimal.format( 0 ) ); appendRawCommands( os, SPACE ); appendRawCommands( os, formatDecimal.format( height ) ); appendRawCommands( os, SPACE ); appendRawCommands( os, formatDecimal.format( x ) ); appendRawCommands( os, SPACE ); appendRawCommands( os, formatDecimal.format( y ) ); appendRawCommands( os, SPACE ); appendRawCommands( os, CONCATENATE_MATRIX ); appendRawCommands( os, SPACE ); appendRawCommands( os, "/" ); appendRawCommands( os, xObjectId.getName() ); appendRawCommands( os, SPACE ); appendRawCommands( os, XOBJECT_DO ); appendRawCommands( os, SPACE ); appendRawCommands( os, RESTORE_GRAPHICS_STATE ); }
@Override public void createImageForm(PDResources imageFormResources, PDResources innerFormResource, PDStream imageFormStream, PDRectangle bbox, AffineTransform at, PDImageXObject img) throws IOException { PDFormXObject imageForm = new PDFormXObject(imageFormStream); imageForm.setBBox(bbox); imageForm.setMatrix(at); imageForm.setResources(imageFormResources); imageForm.setFormType(1); imageFormResources.getCOSObject().setDirect(true); COSName imageFormName = COSName.getPDFName("n2"); innerFormResource.put(imageFormName, imageForm); COSName imageName = imageFormResources.add(img, "img"); pdfStructure.setImageForm(imageForm); pdfStructure.setImageFormName(imageFormName); pdfStructure.setImageName(imageName); LOG.info("Created image form"); }