pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: pdfbox-app-2.0.0-SNAPSHOT.jar: Missing root object specification in trailer
Date Wed, 29 Jul 2015 05:55:52 GMT
Am 29.07.2015 um 01:05 schrieb Roberto Nibali:
> This one works well and does not show the Error (14). Also, the JavaScript
> function works. Now, I only have to figure out how to put all the JS stream
> entries that match a certain criteria (you have sent me some code already
> for JS extraction) and put them into OpenActions.
>
>
>> >
>> >But you should be able to to insert that OpenAction by using
>> >PDDocumentCatalog.setOpenAction(). Or do it with catalog.getCOSObject() and
>> >insert it in the dictionary that you get.

There is a simple example in AddJavascript.java:


public class AddJavascript
{
     private AddJavascript()
     {
         //static class, should not be instantiated.
     }

     /**
      * This will print the documents data.
      *
      * @param args The command line arguments.
      *
      * @throws Exception If there is an error parsing the document.
      */
     public static void main( String[] args ) throws Exception
     {
         if( args.length != 2 )
         {
             usage();
         }
         else
         {
             PDDocument document = null;
             try
             {
                 document = PDDocument.load( new File(args[0]) );
                 PDActionJavaScript javascript = new PDActionJavaScript(
                     "app.alert( {cMsg: 'PDFBox rocks!', nIcon: 3, 
nType: 0, cTitle: 'PDFBox Javascript example' } );");
                 document.getDocumentCatalog().setOpenAction( javascript );
                 if( document.isEncrypted() )
                 {
                     throw new IOException( "Encrypted documents are not 
supported for this example" );
                 }
                 document.save( args[1] );
             }
             finally
             {
                 if( document != null )
                 {
                     document.close();
                 }
             }
         }
     }

     /**
      * This will print the usage for this document.
      */
     private static void usage()
     {
         System.err.println( "Usage: java 
org.apache.pdfbox.examples.pdmodel.AddJavascript <input-pdf> 
<output-pdf>" );
     }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message