PDF in Embedded, using Named Destinations or Page commands

I am loading a PDF document using Vaadin Embedded component (currently through a FileResource). I would like to pass parameters to the acrobat plugin when I open the file to jump to a named destination, or a given page number.

Acrobat supports this through Open Parameters such as :

nameddest=name
page=pagenum

Either through the command line like this:

“Acrobat.exe /A “page=5=OpenActions” “C:\example.pdf””

Or by appending the parameters to the URL:

http://example.org/doc.pdf#nameddest=Chapter6

I’ve tried (without success) to do this with embedded’s setParameter(“page”, “5”); for example:



   public void loadPDFHelpFile(String pageNum){

       String basedir = app.getContext().getBaseDirectory().getAbsolutePath();

       FileResource fr = null;
       File f = null;
       String filePath = basedir + "/" + "MyHelpDoc.pdf";

       f = new File(filePath);
       fr = new FileResource(f, app);


       Embedded emb = new Embedded("", fr);
       emb.setType(Embedded.TYPE_BROWSER);
       emb.setMimeType("application/pdf");
       emb.setHeight(860, UNITS_PIXELS);
      // TODO: How to pass parameters to the acrobat plugin to jump to page or named destination
       emb.setParameter("page", pageNum);
       this.addComponent(emb);
   }

Is this possible with Embedded or some other mechanism - using setParameters with name and value contents other than what I am using ? If not is it possible to build URLs to an ExternalResource with VAADIN and append the appropriate #page= or #nameddest= commands to the URL ?

Hi!

I’m mostly guessing here before actually testing this stuff… ExternalResource you can use parameters as they are plain URLs. On the other hand, the URLs for other ApplicationResources are generated automatically. However, you might be able to override the default behavior.

Try the following in your code (replace the line 12 in your sample):

FileResource fr = new FileResource(f, app) {

    private static final long serialVersionUID = 1L;

    @Override
    public String getFilename() {
        return super.getFilename()+"#nameddest=Chapter6";
    }

};

… and let me know, if it works. :slight_smile: