They will be public in the next version together with some others. If you
don't want to mess with the library put your code in the package
com.lowagie.text.pdf.

Best Regards,
Paulo Soares

> -----Original Message-----
> From: Matt Benson [SMTP:[EMAIL PROTECTED]
> Sent: Thursday, March 13, 2003 15:36
> To:   Paulo Soares; itext-questions
> Subject:      Re: [iText-questions] modifying metadata
> 
> Except that when I tried your solution, I found that
> PdfIndirectReference and PdfWriter.addToBody() are
> both package-private so I can't get to them without
> modifying the library... :(
> 
> -Matt
> 
> --- Matt Benson <[EMAIL PROTECTED]> wrote:
> > Oops.  :)  Okay, thanks for the solution, Paulo!
> > 
> > -Matt
> > 
> > 
> > --- Paulo Soares <[EMAIL PROTECTED]> wrote:
> > > And now you have a stream as a direct object,
> > which
> > > is illegal.
> > > 
> > > Best Regards,
> > > Paulo Soares
> > > 
> > > ----- Original Message -----
> > > From: "Matt Benson" <[EMAIL PROTECTED]>
> > > To: "Paulo Soares" <[EMAIL PROTECTED]>;
> > > "itext-questions"
> > > <[EMAIL PROTECTED]>
> > > Sent: Wednesday, March 12, 2003 23:11
> > > Subject: RE: [iText-questions] modifying metadata
> > > 
> > > 
> > > > Okay, I think I found it.  Of course using
> > > PRStream
> > > > wouldn't be any better than PdfStream because
> > > PRStream
> > > > extends PdfStream and doesn't override toPdf().
> > > > PdfStream.toPdf() is implemented as always
> > > returning
> > > > null.  I didn't know why that should be, so I
> > > changed
> > > > it.  It was:
> > > >
> > > >     public byte[] toPdf(PdfWriter writer) {
> > > >         dicBytes = super.toPdf(writer);
> > > >         return null;
> > > >     }
> > > >
> > > > but I changed it to:
> > > >
> > > >     public byte[] toPdf(PdfWriter writer) {
> > > >         dicBytes = super.toPdf(writer);
> > > >         return dicBytes;
> > > >     }
> > > >
> > > > and it seems to work now.
> > > >
> > > >
> > > > -Matt
> > > >
> > > > --- Matt Benson <[EMAIL PROTECTED]> wrote:
> > > > > One obvious problem is that this example was
> > > using
> > > > > PdfStream, which always returns null from
> > toPdf.
> > > > > However, I had already been using PRStream
> > > before
> > > > > that
> > > > > with the same results.  I am going back to
> > > PRStream
> > > > > in
> > > > > the debugging to which I have been forced to
> > > turn,
> > > > > due
> > > > > to the terrible problem of time zones!  :)
> > > > >
> > > > >
> > > > >
> > > > > --- Matt Benson <[EMAIL PROTECTED]> wrote:
> > > > > > Okay, I am STUCK.  I can play with XMP/RDF,
> > > that's
> > > > > > fine, and I've been doing it.  But I am
> > > finding
> > > > > > myself
> > > > > > unable to actually change the metadata of a
> > > given
> > > > > > PDF.
> > > > > >  I have culled together a fairly short
> > > example;
> > > > > can
> > > > > > anyone see any obvious problems?
> > > > > >
> > > > > >
> > > > > > import java.io.FileOutputStream;
> > > > > > import java.io.BufferedOutputStream;
> > > > > > import java.io.ByteArrayOutputStream;
> > > > > >
> > > > > > import com.lowagie.text.pdf.PdfName;
> > > > > > import com.lowagie.text.pdf.PRStream;
> > > > > > import com.lowagie.text.pdf.PdfObject;
> > > > > > import com.lowagie.text.pdf.PdfReader;
> > > > > > import com.lowagie.text.pdf.PdfStream;
> > > > > > import com.lowagie.text.pdf.PdfStamper;
> > > > > > import com.lowagie.text.pdf.PdfDictionary;
> > > > > >
> > > > > >
> > > > > > public class MinimalModifyPdfMetadata
> > > > > > {
> > > > > >
> > > > > >   public byte[] modifyMetadata(String pdf)
> > > > > >    throws Exception
> > > > > >   {
> > > > > >     ByteArrayOutputStream baos = new
> > > > > > ByteArrayOutputStream();
> > > > > >
> > > > > >     PdfReader pdfReader = new
> > PdfReader(pdf);
> > > > > >     byte[] b =
> > > > > >
> > > > >
> > > >
> > >
> >
> PdfReader.getStreamBytes((PRStream)(PdfReader.getPdfObject(
> > > > > >      pdfReader.getCatalog().get(new
> > > > > > PdfName("Metadata")))),
> > > pdfReader.getSafeFile());
> > > > > >
> > > > > >     System.out.println("original metadata");
> > > > > >     System.out.println(new String(b));
> > > > > >
> > > > > >     PdfStamper stamp = new
> > > PdfStamper(pdfReader,
> > > > > > baos);
> > > > > >
> > > > > >     //set the metadata
> > > > > >     pdfReader.getCatalog().put(new
> > > > > > PdfName("Metadata"), new PdfStream(b));
> > > > > >
> > > > > >     try
> > > > > >     {
> > > > > >       stamp.close();
> > > > > >     }//end try
> > > > > >     catch (Exception ex)
> > > > > >     {
> > > > > >       ex.printStackTrace(System.err);
> > > > > >     }//end catch Exception
> > > > > >
> > > > > >     return baos.toByteArray();
> > > > > >   }//end modifyMetadata
> > > > > >
> > > > > >
> > > > > >   public static void main(String[] args)
> > > > > >    throws Exception
> > > > > >   {
> > > > > >     int code = 0;
> > > > > >
> > > > > >     if (args.length > 1)
> > > > > >     {
> > > > > >       BufferedOutputStream bos
> > > > > >        = new BufferedOutputStream(new
> > > > > > FileOutputStream(args[1]));
> > > > > >
> > > > > >       bos.write(new
> > > > > >
> > > > >
> > >
> > MinimalModifyPdfMetadata().modifyMetadata(args[0]));
> > > > > >       bos.close();
> > > > > >     }//end if at least 2 args
> > > > > >     else
> > > > > >     {
> > > > > >       System.err.println(
> > > > > >        "Usage:  MinimalModifyPdfMetadata
> > > > > input-file
> > > > > > output-file");
> > > > > >     }//end else, wrong # of args
> > > > > >
> > > > > >     System.exit(code);
> > > > > >   }//end main
> > > > > >
> > > > > > }//end class MinimalModifyPdfMetadata
> > > > > >
> > > > > >
> > > > > > I get the following stack trace when I run
> > the
> > > > > above
> > > > > > code:
> > > > > >
> > > > > > java.lang.NullPointerException
> > > > > >         at
> > > > > >
> > > java.io.OutputStream.write(OutputStream.java:65)
> > > > > >         at
> > > > > >
> > > > >
> > > >
> > >
> >
> com.lowagie.text.pdf.PdfDictionary.toPdf(PdfDictionary.java:152)
> > > > > >         at
> > > > > >
> > > > >
> > > >
> > >
> >
> com.lowagie.text.pdf.PdfIndirectObject.<init>(PdfIndirectObject.java:
> > > > > > 138)
> > > > > >         at
> > > > > >
> > > > >
> > > >
> > >
> >
> com.lowagie.text.pdf.PdfIndirectObject.<init>(PdfIndirectObject.java:
> > 
> === message truncated ===
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Web Hosting - establish your business online
> http://webhosting.yahoo.com


-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to