Now I got the solution.
It was very close to what Thomas suggested, but I had to build a byte array :

            // Create the identifier
            UUID id = UUID.randomUUID();
            String stringId = id.toString();
            stringId = stringId.replace("-","");
            // Create the byte array based on the hexadecimal key
            byte[] byteKey = new byte[16];
            int byteindex = 0;
            for(int c = 0 ; c < 31 ;){
                int fim = c + 2;
                int myB = Integer.parseInt( stringId.substring(c,fim), 16);
                byteKey[byteindex] = (byte) myB;
                ++byteindex;
                c = c + 2;
            }
            // Create the COSString IDs based on the byte array
            COSString ID1 = new COSString(byteKey);
            COSString ID2 = new COSString(byteKey);
            // Create the array with both keys ( in my case the same for both )
            COSArray myAL = new COSArray();
            myAL.add(ID1);
            myAL.add(ID2);
            // Set the new IDs in the document
            myPdf.getDocument().setDocumentID(myAL);




----- original message --------

Subject: Re: Problem trying to oerwriting ID
Sent: Fri, 23 Jul 2010
From: Thomas Chojecki<[email protected]>

> Am 23.07.2010 20:35, schrieb Robson Bortoleto:
> > 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 ?
> 
> There are to kinds of Strings. "Literal Strings" wrote with ( ) and 
> "Hexadezimal Strings" wrote with < >.
> 
> The problem is, that pdfbox don't give you the chance to force write 
> hexadezimal Strings as you wish in this situation.
> 
> Way 1:
> I don't test it, but if you convert each byte-pair (2 bytes) in a char, 
> then convert the char[] in a String and then convert it in a new 
> COSString, maybe you will then get a hexadezimal String.
> 
> Way 2:
> Wait for a patch or patch it yourself.
> 
> I append a patch to that mail, that will add a new method "public void 
> setForceHexForm(boolean v)"
> 
> 
> > Thanks
> >
> > Rob
> 
> Regards
> Thomas
> 

--- original message end ----

Reply via email to