Hello everyone,

I have created a new DocumentType. That document will contain pdf files as 
content. When I create this document and select the pdf file at its creation 
view, a watermark with a date (which is one field of that creation view) is 
added to the pdf file. At this point, everything works fine. The pdf file is 
attached as content, and if you open it, the correct watermark was added. The 
problem comes when I try to modifiy it. 

If I change that date in the modification tab, I want the watermark updates, 
but I don't get it. I have tried doing it in a java bean associated to xhtml 
view, and also in a listener, capturing "documentModifed" event, but it always 
remains old watermark. Any error is displayed, and everything seems to work 
fine.

To add watermark to the pdf file, I use a temporal file, and I have checked 
that that temporal file is created in my filesystem.

Has anyone any idea why this is not working?

This is relevant code:

private String addWaterMark(InputStream content, String fecha, String numReg){
                String res = "";
                try
            {
              PdfReader reader = new PdfReader(content);
              int n = reader.getNumberOfPages();
              // Create a stamper that will copy the document to a new file
              File file = File.createTempFile("temp", ".pdf");
              PdfStamper stamp = new PdfStamper(reader, 
                new FileOutputStream(file));
              int i = 1;
              PdfContentByte under;
              PdfContentByte over;
        
              
drawRectangle(stamp,reader.getPageSize(1).getWidth()-142,reader.getPageSize(1).getHeight()-
 62,140,60);
        
              addWaterMark(stamp, reader.getPageSize(1).getWidth()-140, 
reader.getPageSize(1).getHeight() - 19, 15, fecha, numReg);
              stamp.close();
              res = file.getPath();
              return res;
            }catch (Exception de) {
                
            }
            return "";
        }
...........

}else if(event.getName().equals("documentModified") && 
doc.getType().equalsIgnoreCase("Correspondencia")){
                                         
                                                Calendar fecha = 
(Calendar)doc.getProperty("correspondencia", "fecha");
                                        
                                                String fechaString = 
fecha.get(fecha.DAY_OF_MONTH) + "/" + (fecha.get(fecha.MONTH)+1) + "/" + 
fecha.get(fecha.YEAR);
                                        
                                                Blob blob = 
(Blob)doc.getProperty("file", "content");
                                                if(blob!= null){
                                        
String filePath = this.addWaterMark(blob.getStream(), fechaString, numeroReg);
                                                                        File 
file = new File(filePath);
                                                                        
if(file.exists()){
                                                                                
FileBlob fb = new FileBlob(file);
                                                                                
fb.setMimeType(blob.getMimeType());
                                                                                
fb.setEncoding(blob.getEncoding());
                                                                                
doc.setProperty("file", "content", fb);
                                                                        }
                                                                }
                                                                
//                                                              
documentManager.saveDocument(doc);   ---> this line provokes bucle
                                                                
documentManager.save();
                                         }
--
Posted by "franciscogonzalez" at Nuxeo Discussions 
<http://nuxeo.org/discussions>
View the complete thread: 
<http://www.nuxeo.org/discussions/thread.jspa?threadID=3941#12052>
_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm

Reply via email to