/** * Set the font to draw text with. * * @param font The font to use. * @param fontSize The font size to draw the text. * @throws IOException If there is an error writing the font information. */ public void setFont(PDFont font, float fontSize) throws IOException { String fontMapping = (String) fontMappings.get(font); if (fontMapping == null) { fontMapping = MapUtil.getNextUniqueKey(fonts, "F"); fontMappings.put(font, fontMapping); fonts.put(fontMapping, font); } appendRawCommands("/"); appendRawCommands(fontMapping); appendRawCommands(SPACE); appendRawCommands(formatDecimal.format(fontSize)); appendRawCommands(SPACE); appendRawCommands(SET_FONT); }
/** * Draw an xobject(form or image) at the x,y coordinates and a certain width and height. * * @param xobject The xobject to draw. * @param x The x-coordinate to draw the image. * @param y The y-coordinate to draw the image. * @param width The width of the image to draw. * @param height The height of the image to draw. * @throws IOException If there is an error writing to the stream. */ public void drawXObject(PDXObject xobject, float x, float y, float width, float height) throws IOException { String xObjectPrefix = null; if (xobject instanceof PDXObjectImage) { xObjectPrefix = "Im"; } else { xObjectPrefix = "Form"; } String objMapping = (String) xobjectMappings.get(xobject); if (objMapping == null) { objMapping = MapUtil.getNextUniqueKey(xobjects, xObjectPrefix); xobjectMappings.put(xobject, objMapping); xobjects.put(objMapping, xobject); } appendRawCommands(SAVE_GRAPHICS_STATE); appendRawCommands(formatDecimal.format(width)); appendRawCommands(SPACE); appendRawCommands(formatDecimal.format(0)); appendRawCommands(SPACE); appendRawCommands(formatDecimal.format(0)); appendRawCommands(SPACE); appendRawCommands(formatDecimal.format(height)); appendRawCommands(SPACE); appendRawCommands(formatDecimal.format(x)); appendRawCommands(SPACE); appendRawCommands(formatDecimal.format(y)); appendRawCommands(SPACE); appendRawCommands(CONCATENATE_MATRIX); appendRawCommands(SPACE); appendRawCommands("/"); appendRawCommands(objMapping); appendRawCommands(SPACE); appendRawCommands(XOBJECT_DO); appendRawCommands(SPACE); appendRawCommands(RESTORE_GRAPHICS_STATE); }