/** Reads the WMF into a template. * @param template the template to read to * @throws IOException on error * @throws DocumentException on error */ public void readWMF(PdfTemplate template) throws IOException, DocumentException { setTemplateData(template); template.setWidth(getWidth()); template.setHeight(getHeight()); InputStream is = null; try { if (rawData == null){ is = url.openStream(); } else{ is = new java.io.ByteArrayInputStream(rawData); } MetaDo meta = new MetaDo(is, template); meta.readAll(); } finally { if (is != null) { is.close(); } } }
/** Reads the WMF into a template. * @param template the template to read to * @throws IOException on error * @throws DocumentException on error */ public void readWMF(PdfTemplate template) throws IOException, DocumentException { setTemplateData(template); template.setWidth(width()); template.setHeight(height()); InputStream is = null; try { if (rawData == null){ is = url.openStream(); } else{ is = new java.io.ByteArrayInputStream(rawData); } MetaDo meta = new MetaDo(is, template); meta.readAll(); } finally { if (is != null) { is.close(); } } }
/** * Extracts the image data from the Image. * * @param image The image for which to extract the content * @return The raw image data, not formated * @throws DocumentException If an error occurs accessing the image content */ private byte[][] getImageData(Image image) throws DocumentException { final int WMF_PLACEABLE_HEADER_SIZE = 22; final RtfByteArrayBuffer bab = new RtfByteArrayBuffer(); try { if(imageType == Image.ORIGINAL_BMP) { bab.append(MetaDo.wrapBMP(image)); } else { final byte[] iod = image.getOriginalData(); if(iod == null) { final InputStream imageIn = image.getUrl().openStream(); if(imageType == Image.ORIGINAL_WMF) { //remove the placeable header first for(int k = 0; k < WMF_PLACEABLE_HEADER_SIZE; k++) { if(imageIn.read() < 0) throw new EOFException("while removing wmf placeable header"); } } bab.write(imageIn); imageIn.close(); } else { if(imageType == Image.ORIGINAL_WMF) { //remove the placeable header bab.write(iod, WMF_PLACEABLE_HEADER_SIZE, iod.length - WMF_PLACEABLE_HEADER_SIZE); } else { bab.append(iod); } } } return bab.toByteArrayArray(); } catch(IOException ioe) { throw new DocumentException(ioe.getMessage()); } }