|
Hello iText users!
I tried to use a WMF as watermark which gave
problems.
Below you will a find modified version of the
PdfContentByte.addImage() method which now allows to have a WMF as watermark
(but I'm not satisfied with that bug fix since it would always create a new
instance of an image and not reusing it):
/**
* Adds an <CODE>Image</CODE> to the page. The positioning of the <CODE>Image</CODE> * is done with the transformation matrix. To position an <CODE>image</CODE> at (x,y) * use addImage(image, image_width, 0, 0, image_height, x, y). * @param image the <CODE>Image</CODE> object * @param a an element of the transformation matrix * @param b an element of the transformation matrix * @param c an element of the transformation matrix * @param d an element of the transformation matrix * @param e an element of the transformation matrix * @param f an element of the transformation matrix * @throws DocumentException on error */ public void addImage(Image image, float a, float b, float c, float d, float e, float f) throws DocumentException { try { if (image.isImgTemplate()) { if( image instanceof com.lowagie.text.Watermark ) { image = new com.lowagie.text.ImgWMF(image.url()); } writer.addDirectImageSimple(image); PdfTemplate template = image.templateData(); float w = template.getWidth(); float h = template.getHeight(); addTemplate(template, a / w, b / w, c / h, d / h, e, f); } else { PdfName name; PageResources prs = getPageResources(); Image maskImage = image.getImageMask(); if (maskImage != null) { name = writer.addDirectImageSimple(maskImage); prs.addXObject(name, writer.getImageReference(name)); } name = writer.addDirectImageSimple(image); name = prs.addXObject(name, writer.getImageReference(name)); content.append("q "); content.append(a).append(' '); content.append(b).append(' '); content.append(c).append(' '); content.append(d).append(' '); content.append(e).append(' '); content.append(f).append(" cm "); content.append(name.toPdf(null)).append(" Do Q").append_i(separator); } } catch (Exception ee) { throw new DocumentException(ee.getMessage()); } } Kind regards,
Gerald.
|
- RE: [iText-questions] bug fix WMF as watermark ? Gerald Fehringer
- RE: [iText-questions] bug fix WMF as watermark ? Paulo Soares
