Scroll into a Adobe Reader using buttons c#

2019-09-17 14:30发布

问题:

I Have Created a Simple form in which i have added Adobe Reader from toolbox using steps

  1. right click in toolbox - Choose Items
  2. choose COM Components tab and there "Adobe PDF Reader"
  3. Now Drag&Drop the Adobe PDF Reader Control into an UserControl

I have successfully added this, opened up a pdf file also. Now it automatically provides with vertical scrollbars for scrolling through the pdf document.

What i want to achieve is instead of using the given scrollbars or mouse to scroll, i want to use a button to scroll scroll the pdf, So there will be two buttons, One for Scroll Up And the other for scroll down.

I have gone through many forums, pages, etc. Havnt found anythn that i could use.

I have Tried Simulating key presses with

SendKeys.Send("{DOWN}");

But as i press the button, the focus is lost on the adobe reader so it doesnt work

Pls help me... I have spent almost half a day searchin for a solution

回答1:

given that you have provided only a simple piece of code you have tried, i am going to try offer you a generic solution - where you will need to replace the specified variables:

  • button names
  • your web app name

as for first of the focus you need to specify where it will be, something along the lines of:

var pFocus = webapplication.formname.pdf_document.focus();
// or webapplication.focus(pdf_document);

again i am just writing this as an ideal layout as i have said you will need to replace the listed variables for this to work and possibly tweak the focus code as i haven't tested that - the buttons however provided you insert your variable names will work as i have tested these:

var buttonAction = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 5)");
var buttonAction_2 = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight 0)");
//button action will scroll to x co-ordinate 0(far left), y co-ordinate( 5px from bottom)
//buttonAction_2 will return you to the very top left of page, you can edit these values to mess around and try different settings.

so altogether it should look somewhat similar to (if you are using a method for the click just insert the code under there:

var pFocus = webapplication.formname.pdf_document.focus();

if (button.click = true)
webapplication = pFocus;

var buttonAction = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 5)");

pFocus.execute(buttonAction);

then for button 2

var pFocus = webapplication.formname.pdf_document.focus();

if (button_2.click = true)
webapplication = pFocus;

 var buttonAction_2 = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight 0)");

pFocus.execute(buttonAction_2);

hope this helps to some extent.