cancel
Showing results for 
Search instead for 
Did you mean: 

copy pdf content

francix
Champ in-the-making
Champ in-the-making
Hello, I'm newbie in Alfresco and I'm trying to code a simple script to make a content versioned into an alternate space.

I use the code of the examples
http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook#Create_Backup_of_a_Document_And_Log_Doc_Proper...
and
http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook#Create_Document.2C_Make_it_Versionable.2C_Modi...

And it works fine, but with pdf files mi versioned nodes are blank pages. I think I'm doing something wrong in the copy content process, but I don't know what could it be.

I'm using Alfresco community 3.2 and this is my script:


if (document.isDocument){

   var targetNode = space.childByNamePath("targetNode");
   if (targetNode == null && space.hasPermission("CreateChildren")){
      targetNode = space.createFolder("targetNode");
   }
   
   if (targetNode != null && targetNode.hasPermission("CreateChildren")){
      var docObsoleto = targetNode.childByNamePath(document.name);

      if (docObsoleto == null){
         docObsoleto = document.copy(targetNode);
         docObsoleto.addAspect("cm:versionable");
      }
      if (docObsoleto != null){
         if (docObsoleto.isVersioned)         {
            var workingCopy = docObsoleto.checkout();
            workingCopy.content = document.content;
            docObsoleto = workingCopy.checkin('Old version');
         }         
      }
   }
}

Thaks in advance
2 REPLIES 2

invictus9
Champ in-the-making
Champ in-the-making
I have a note somewhere that says that using the .content assignment really works reliably only for text files. You need to use the writer method to copy the content from one file to another if the content is other than strict text.

francix
Champ in-the-making
Champ in-the-making
I still don't find a write method example, but I'm on it.

Anyway when the versioned document is copied by first time (without using content propertie)



      if (docObsoleto == null){
         docObsoleto = document.copy(targetNode);
         docObsoleto.addAspect("cm:versionable");
      }


it's a black pages document too. 😞