I'm trying to update a database of PDF files and use a newly generated ID to 
identify them (I had problems with ID duplicity caused by an older program). 
The problem is that the result is wrong. The correct ID on the PDF file should 
look like :

/ID [<c8039fd24c97d00fbd27edd68af8e0ef><6b63a249e40a472e9e597aff2c9d8863>]

And the result of my code is :

/ID[ (c8039fd24c97d00fbd27edd68af8e0ef) (6b63a249e40a472e9e597aff2c9d8863)]

I tried two different approachs and both gave the same result (see them below)

Does anyone know what I'm doing wrong ?

Thanks

Rob


METHOD 1
            // Create the identifier
            UUID id1 = UUID.randomUUID();
            // Get the ID String
            String stringId1 = id1.toString();
            // Remove the "-"
            stringId1 = stringId1.replace("-","");
            // Create the COSString with the ID
            COSString myID = new COSString(stringId1.getBytes());
            // Pass it to a COSObject (IMPORTANTE :  I tried to pass the string 
directly to )
            COSObject objID = null;
            try {
                objID = new COSObject(myID);
            } catch (IOException ex) {
                
Logger.getLogger(LimpaMetadata.class.getName()).log(Level.SEVERE, null, ex);
            }
            // Create the COSArray with both IDs
            COSArray theID = new COSArray();
            theID.add(objID);
            theID.add(objID);
            // Set the ID
            myPdf.getDocument().setDocumentID(theID);


METHOD 2 ( Based in the COSArray Structure given by the ID colected from the 
trailer; lines starting with #)
#To collect the ID
#COSArray myCO = new COSArray();
#myCO.add(myPdf.getDocument().getTrailer().getItem(COSName.getPDFName("ID")));
#myCO.add(myPdf.getDocument().getTrailer().getItem(COSName.ID));

            // Create the identifier
            UUID id = UUID.randomUUID();
            String stringId = id.toString();
            stringId = stringId.replace("-","");
            String id_1 = stringId.substring(1,16);
            String id_2 = stringId.substring(16, 32);

            COSString ID1 = new COSString(id_1);
            COSString ID2 = new COSString(id_2);

            COSArray myAL = new COSArray();
            myAL.add(ID1);
            myAL.add(ID2);

            try {
                COSObject obj1 = new COSObject(myAL);
            } catch (IOException ex) {
                
Logger.getLogger(LimpaMetadata.class.getName()).log(Level.SEVERE, null, ex);
            }

            COSArray finalID = new COSArray();
            finalID.add(myAL);
            finalID.add(myAL);

            myPdf.getDocument().


Reply via email to