CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Sep 2021
    Posts
    7

    Control PDF from c ++

    I wanted to put the PDF file on one page. When opening with "# page = 123" or "/ A page = 123" in the path or as a parameter in ShellExecute does not work.
    How could you do that when PDF is already open?
    I couldn't find the list of parameters. It would be nice to know how to ship them too.
    Thanks for the answers

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

  3. #3
    Join Date
    Sep 2021
    Posts
    7

    Re: Control PDF from c ++

    Thanks ViktorN for the parameter list.
    I had the idea that it could be done from c / ++ for example. with ShellExecute (NULL / GetDesktopWindow (), "open", "Path \ File", p1, NULL, SW_NORMAL)
    Open works when p1 = NULL.
    With p1 = "# page = 3" or "/ A page = 3" does not work.
    Is there a way to design the parameter p1 so that ShellExecute (or CreateProcess) opens the file and places it on a page?
    And it remains to put open PDF on one page. Is it possible without a PDF library with Send / PostMessages?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: Control PDF from c ++

    Quote Originally Posted by danekbb View Post
    ...
    With p1 = "# page = 3" or "/ A page = 3" does not work.
    ...
    did you try to pass parameters without paces? Like
    /A "page=3"
    Last edited by VictorN; September 10th, 2021 at 02:22 AM.
    Victor Nijegorodov

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: Control PDF from c ++

    Quote Originally Posted by danekbb View Post
    I wanted to put the PDF file on one page. When opening with "# page = 123" or "/ A page = 123" in the path or as a parameter in ShellExecute does not work.
    How could you do that when PDF is already open?
    ...
    I guess you would need some kind of PDF SDK to proper implement it.
    See https://www.pdftron.com/documentatio...ation/windows/
    and/or some other suggestions of Google:
    https://www.google.com/search?q=pdf+...4dUDCA4&uact=5
    Victor Nijegorodov

  6. #6
    Join Date
    Sep 2021
    Posts
    7

    Re: Control PDF from c ++

    If man
    ShellExecute (NULL / GetDesktopWindow (), "open", "Path \ File", p1, NULL, SW_NORMAL)
    calls, where p1 = "#page=3", "/A page=3", "/ A "page=3""
    PDF file be opened, but not set on page (3).
    The previous examples did not provide a solution

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: Control PDF from c ++

    Quote Originally Posted by danekbb View Post
    ShellExecute (NULL / GetDesktopWindow (), "open", "Path \ File", p1, NULL, SW_NORMAL)
    This line does not compile!

    Quote Originally Posted by danekbb View Post
    ... where p1 = "#page=3", "/A page=3", "/ A "page=3""
    PDF file be opened, but not set on page (3).
    Try
    Code:
    p1 = "/A page=3"
    Victor Nijegorodov

  8. #8
    Join Date
    Sep 2021
    Posts
    7

    Re: Control PDF from c ++

    I have already tried this parameter without success.
    I don't like integrating a library: it's nice that others know how to do it, but I want to know myself.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: Control PDF from c ++

    This code works for me opening the page 2:
    Code:
    	HINSTANCE result = ::ShellExecute(nullptr, _T("open"), _T("AcroRd32.exe"), _T("/A page=2 D:\\Development\\myPath\\myFile.pdf"), nullptr, SW_SHOWNORMAL);
    Victor Nijegorodov

  10. #10
    Join Date
    Sep 2021
    Posts
    7

    Re: Control PDF from c ++

    Wow. Open the PDF file with
    HINSTANCE result = :: ShellExecute (nullptr, _T ("open"), _T ("AcroRd32.exe"), _T ("/ A page = 2 D: \\ Development \\ myPath \\ myFile.pdf"), nullptr , SW_SHOWNORMAL);
    functions.
    Thanks VictorN.

    The thing would really be complete if you could navigate to a page of an open PDF.

    Does anyone know ?

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: Control PDF from c ++

    Quote Originally Posted by danekbb View Post
    ...
    The thing would really be complete if you could navigate to a page of an open PDF.

    Does anyone know ?
    I still guess you would have to use some kind on PDF SDK to accomplish it.
    Just the same way as to work with opened MS Word or MS Excel file one have to use the corresponding Word or Excel Automation.
    Victor Nijegorodov

  12. #12
    Join Date
    Sep 2021
    Posts
    7

    Re: Control PDF from c ++

    It is possible that it is difficult to navigate to a page in an open PDF without a PDF SDK. However, the solution to navigate to the page when it is opened is not bad.
    Unfortunately, that only takes care of part of the problem.
    Because if the PDF file is in the directory "c: \ program files \ doc", AcroRd32.exe can not find it. Error message: it is the directory syntax, and it affects every directory whose name contains a space.
    Occasionally I had problems with it that could be fixed with quotation marks.
    In that case it is not so.

    Does anyone know the correct syntax for AcroRd32.exe with the space in the name of a directory ?

  13. #13
    Join Date
    Sep 2021
    Posts
    7

    Re: Control PDF from c ++

    I looked for something, tried it and solved the problem.
    The correct syntax is:
    ShellExecute (NULL, _T ("open"), _T ("AcroRd32.exe"), _T ("/ A \ page = 2 \ Pathfile.pdf \ "), NULL, SW_SHOW);
    I.e. parameters and PathFile.PDF must have quotation marks

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: Control PDF from c ++

    Quote Originally Posted by danekbb View Post
    I looked for something, tried it and solved the problem.
    The correct syntax is:
    ShellExecute (NULL, _T ("open"), _T ("AcroRd32.exe"), _T ("/ A \ page = 2 \ Pathfile.pdf \ "), NULL, SW_SHOW);
    I.e. parameters and PathFile.PDF must have quotation marks
    Yes! Any parameter containing the space must be within the quotation marks.
    And it is valid not only for AcroRd32.exe.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured