How to open PDF at specific page using VB script?

Question: I have an application that manages multiple magazine PDFs on the hard drive. I need to open the PDF files into a specific page. I am able to call vb script from my own software so I am looking for some vbscript snippet to open a PDF with a specific page loaded. From the Adobe docs, I checked that using system calls to open a URL like:

http://myserver/mypdf#page=3

works fine but trying to use similar URL with the dummy file protocol like:file://path/to/mypdf#page=2  does not work. After figuring that, I decided that I should try some vbscript call to some COM or ActiveX or whatever they use these days on windows but I don't know how to do it. I hope I can find a solution on VeryPDF?

Answer: According to your needs, maybe you can have  a free trial of this software:VeryPDF Advanced PDF Tools, by which you can set start page number, the the PDF file will be opened at specific page. And there is also Advanced PDF Tools SDK, by which you can call this software from Visual C++ and Visual Basic and other application. Please check more detail information of this software on homepage, in the following part, let us check how to use this software.

Step 1. Free download Advanced PDF Tools SDK

  • When downloading finishes, there will be an zip file. Please extract it to some folder then you can find code templates and related elements.
  • This SDK is Window application, it can work under all the Window system both of 32-bit and 64-bit.

Step 2. Open PDF at specific page using VB script.

  • When you use this software, please refer to the usage and examples.
  • Here are some parameters of opening PDF at specific page, please have a check.
  • Set start page number –w The option -w is to set the current page when opening the PDF file.
    pdftools -i "C:\input.pdf" -o "C:\output.pdf"
    -w number where "number" is the open page number, e.g.
    pdftools -i "C:\input.pdf" -o "C:\output.pdf" -w 2    
    to set page 2 the start page when opening
  • Here are some code of calling this software from VB script, please have a check.

VERSION 5.00

Begin VB.Form Form1
Caption         =   "Form1"
ClientHeight    =   3090
ClientLeft      =   6o
ClientTop       =   450
ClientWidth     =   4680
LinkTopic       =   "Form1"
ScaleHeight     =   3090
ScaleWidth      =   4680
StartUpPosition =   3  'Windows Default
Begin VB.CommandButton Command1
   Caption         =   "Command1"
   Height          =   615
   Left            =   1200
   TabIndex        =   0
   Top             =   1200
   Width           =   205
   End
  End

Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function VeryPDF_PDFTools Lib
"pdftoolsdk.dll" (ByVal strCommandLine As String) As Long
Private Sub Command1_Click()
Dim nRet As Long
Dim strCmd As String
'-J "firstpage=[widthscale,heightscale,
           iscenter,xoffset,yoffset,margin,rotate],
'  evenpages=[widthscale,heightscale,
         iscenter,xoffset,yoffset,margin,rotate],
'  oddpages=[widthscale,heightscale,
         iscenter,xoffset,yoffset,margin,rotate]"
'-J "firstpage=[0.75,0.75,0,160,0,0,0],
'    evenpages=[0.84,0.84,0,-10,0,0,0],
'    oddpages=[0.84,0.84,0,90,0,0,0]"
strCmd = "pdftools.exe" & " -J ""firstpage=[0.75,0.75,0,160,0,0,0],
evenpages=[0.84,0.84,0,-10,0,0,0],oddpages=[0.84,0.84,0,90,0,0,0]""
     strCmd = strCmd & " -$ XXXXXXXXXXXXXX"
     strCmd = strCmd & " -i C:\test.pdf"
     strCmd = strCmd & " -o C:\_test.pdf
    nRet = VeryPDF_PDFTools(strCmd)
    MsgBox (Str(nRet))
End Sub

During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!