Search code examples
c#pdfcommand-line-argumentsacrobat

Re-open pdf with Acrobat Reader on different pages in c#


I would like to subsequently open the same pdf document multiple times on different pages using c# and Adobe Acrobat Reader. The OS is windows.

From this answer I have learned how to evoke a process to start the reader and open a pdf at a desired page or destination. This works fine. However, the only possibility to re-open a pdf document seems to be the option /n which creates a new Acrobat Reader window. Without this option, Acrobat seems to ignore any request to open an already opened file.

Is there any possibility to re-open an already opened pdf at a different page without creating a new tab or window in the reader?


Solution

  • I think the other options you have are using DDE or FDF. DDE has the disadvantage that Adobe startet some versions ago to change the service name from version to version (actual: "AcroViewR17"). A little bit more work is to use a FDF (special structured text file) with js-code. Not so elegant but reliable since version 4.

    Attached you will find the FDF file you need. You have to write and execute it from C#. Change only the filename and js-code stream. The Filename must be OS-independent: Instead of D:\Test.pdf write /D/test.pdf. For testing you can simply save it as test.fdf and execute it via double click.

    Good luck, Reinhard

    %FDF-1.2 %%---DEMO EXECUTE JAVASCRIPT VIA FDF---%%
    1 0 obj << /FDF << /F (/D/Test.pdf)  /JavaScript << /Before 2 0 R  >> >> >> endobj
    2 0 obj << >> stream
    
    //my js-code
    app.alert(this.numPages); //view total pages
    this.pageNum=1;           //goto page number 2 (zero-based)
    
    endstream
    endobj
    trailer << /Root 1 0 R >> %%EOF