• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

C#: Display a pdf in WindowForm

New Here ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Hello!

I am reading the documentation and this forum for a few days, but my problem isn't really solved.
I want to display a pdf document in a WindowForm in C#.

CAcroPDDoc pdDoc = new AcroPDDocClass();
pdDoc.Open("C:\\test.pdf");

CAcroPDPage pdPage;
pdPage = (CAcroPDPage)pdDoc.AcquirePage(0);
AcroRect rect = new AcroRect();
rect.Left = 0;
rect.Top = 0;
rect.right = 1000;
rect.bottom = 1000;
pdPage.DrawEx(0, 0, rect, 0, 0, 100);

With this, I am able to display or render the first page of a document. It's just rendered, nothing more. I read, that I can implement a piece of the acrobat reader, so that I don't have to implement everything on my own.

I think this is something like this:

CAcroAVDoc avDoc = new AcroAVDocClass();
avDoc.Open("C:\\test.pdf", "Test");

But I don't know how to display this pdf in my application. What I want to do is to open a new window and display a pdf + some extra functions, that i want to code on my own. I thought about the BrowserComponent of VisualStudio, but there I am only having control of which page to display, but no chance to get the actual displayed page, right?
I want to get the actual page and set the page when the document is opening.

It would be very great if you could help me. I really don't know a good solution for this and my trials all didn't work.

Thank you very much for your reply,
Manuel
TOPICS
Acrobat SDK and JavaScript

Views

29.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Have you downloaded the Acrobat SDK? have you looked at the samples provided? There are both staticView and activeView samples - as well as demonstrating how to use Reader as well.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Thank you for your reply!

Yes, I have downloaded the SDK and I found the C++ example for a staticView. But I am not sure how to use this in C# and if this is a solution for my problem. I couldn't compile/test it, so that I don't know if what i described is possible in an "easy" way with the SDK.

Thank you,
Manuel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

There are ActiveView and StaticView examples in VB.NET as well. Should give you an idea of how to proceed in C#, since they are both .NET languages.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Okay, then I am right to use these examples and have the control to set a page, read the actual pagenumber and don't have to write a complete Acrobat Reader on my own, right? Then i will see if these examples can help me. Thank you for your help so far!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

> and don't have to write a complete Acrobat Reader on my own

Heh, yes, that is correct.

However, the user will require Acrobat or Reader to be installed on their machine to use your application. The control is not redistributable on its own. And many of the advanced functions will only work with Acrobat, not Reader, so you will want to be careful if your intended audience may only have Reader installed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Okay thank you. I compiled the VB example and that's just what I want! But I never used VB, so it's very hard to understand for me. Some functions aren't available in C# and now I am, where I was at the beginning:

CAcroAVDoc avDoc = new AcroAVDocClass();
avDoc.OpenInWindowEx("C:\\test.pdf", this.Handle.ToInt32(), AV_DOC_VIEW, 1, 0, PDUseBookmarks, AVZoomFitWidth, 0, 0, 0);

I defined the constants and try to read the pdf-File, but I really don't know how to say: Use this form and place the pdf in this form at... or use this panel for displaying the selected pdf.

Where can I find this in the example? I am searching in ActiveViewVB => FileOpen.vb. Or am I at the wrong place for loading the pdf? I am really sorry :-/

But to read the pdf and set a pagenumber/read the actual pagenumber is possible if the client has an installed Acrobat Reader? Is there a method to test if the reader is installed?

Many thanks to you!!!
Manuel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

> I defined the constants

What constants? The ones used in the example should be imported when you include the Acrobat namespace.

> this.Handle.ToInt32()

This is the window handle of the component you are placing the PDF into. You should read over the entire project, and the documentation included with the SDK tells you what the parameters for the functions are.

> CAcroAVDoc avDoc = new AcroAVDocClass();

This class is not available if you only have Reader. Again I suggest you read the documentation carefully so that you know what is available to Reader-only users. The only class available to people with only Reader installed is AxAcroPDFLib.AxAcroPDF.

> But to read the pdf and set a pagenumber/read the actual pagenumber is possible if the client has an installed Acrobat Reader?

With Reader only, you can open a PDF and set the current page. However there is no method to get the current page number.

> Is there a method to test if the reader is installed?

You can check any number of ways, best is probably to check for the correct keys existing in the registry.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Okay thank you, that helps.
There is no possibility to get the current pagenumber? If not, I can use the BrowserComponent, because that's what I want. The user should be able to save some own information to a page of the pdf and therefor i wanted to save the actual pagenumber + the comment of the user in a local database. Then the user can click on this comment and the page with this comment is shown.
But this isn't possible in this or any other way?

Thank you so much. I really read the documentation and I really try to understand, but I am programming since about 2 months, so it's hard to understand what the handle is doing and which parameter must be set to which value.

But with the code in my last post, no pdf is displayed. I am opening a new WindowForm and doing this code in the constructor.

And the AxAcroPDFLib is also a dll which I can refer to? I always read, that I have to include the Acrobat Type Library. Perhaps I am reading the wrong documents of the docu. ;)

Many thanks,
Manuel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

> The user should be able to save some own information to a page of the pdf and therefor i wanted to save the actual pagenumber + the comment of the user in a local database. Then the user can click on this comment and the page with this comment is shown.

This functionality already exists in Acrobat, and Reader as well if the PDF is Reader Enabled.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

Okay, I am giving it up. I read every document of the documentation and I didn't find how to use the "AxAcroPDFLib". I don't find any information how to integrate this in Visual Studio. I found another post, that this should be in the COM-Tab of the toolbox, but there it isn't.

The only thing I want to do now: Display a pdf in a WindowForm but without the savebutton of the reader. Am I able to disable this button or to hide it? Or can I hide the complete navbar and write my own with only using the Acrobat Reader, not the fullversion, because I can't ensure, that every client has this version.

Thank you very much for your help. I really begin to desperate... :-/
Manuel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

>Okay, I am giving it up. I read every document of the documentation and I didn't find how to use the "AxAcroPDFLib".

Did you read the Interapplication Communication documents?

> I don't find any information how to integrate this in Visual Studio.

Why would you do that? That doesn't sound correct.

There is a code example in the documents which shows how to associate
the control with an existing control. Do you need help finding it? Or
does it just not help?


Aandi Inston

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

In Visual Studio 2005 you need to add the control to the toolbox.

Tool->Choose Toolbox Items.

This will display a dialog, select the COM Components tab.
Then select - > Adobe PDF Reader

Then just drag and drop it like any other control.

HTH

Malky

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

Thanks for your answers!
My problem is, what malkyt explains. I want to add the Reader to my Toolbox Items. But in my COM Components tab, there are only 2 Items, but no Adobe PDF Reader.

Now I copied the AxInterop.AcroPDFLib.dll and the Interop.AcroPDFLib.dll from an example in the SDK. I found some code to display a pdf (http://www.sciencecode.com/text.htm#30):

try
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PdfForm));
AxAcroPDFLib.AxAcroPDF axAcroPdf = new AxAcroPDFLib.AxAcroPDF();

((System.ComponentModel.ISupportInitialize)(axAcroPdf)).BeginInit();

axAcroPdf.Location = new Point(50, 50);
axAcroPdf.Size = new Size(500, 500);
axAcroPdf.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPdf.OcxState")));

this.Controls.Add(axAcroPdf);
((System.ComponentModel.ISupportInitialize)(axAcroPdf)).EndInit();

axAcroPdf.LoadFile("C:\\test.pdf");
axAcroPdf.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

But if I do this, I get something like this:
"Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"

What am I doing wrong? How can I get this COM-Component or can I just use these 2 libs from the examples?

Many many thanks!!!

EDIT: Okay, on my Laptop (WinXP) this works. Vista64Bit doesn't show these components. Now the pdf is displayed and I am very happy. But how am I able to hide or deactivate the "save"-button? I don't want, that the user can save this document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

> But how am I able to hide or deactivate the "save"-button? I don't want, that the user can save this document

If the user only has Reader installed, they can't save anyways. With Acrobat, this can't be disabled.

Please note that Acrobat 8.1 was the first version compatible with Windows Vista. If you have a version prior to 8.1 (including 8.0), it will not work in Vista.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

I made a screenshot of the reader, so that you know which button I mean:
http://www.der-webdesigner.net/pdf-navi.jpg

This button is also available for users who have only installed the reader. Can I deactivate this button? Or is there another way? If this button is deactivated, I am happy with the solution :)

Nice greetings,
Manuel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2008 Sep 16, 2008

Copy link to clipboard

Copied

I'm having this problem where the focus is on my ListView control but as soon as the pdf is loaded in code my ListView loses focus to the PDF Browser Controls. I've tried to look for something like an onLoadCompleted event in AxAcroPDF but without luck in order to set the focus back to my ListView. Has anyone experienced this problem? Please help!!

axAcroPDF1.LoadFile(C:\\test.pdf);
// if i set the focus like this in code it only works in debugging mode
listView1.Focus();
listView1.Items[index].Focused = true;
listView1.Select();

Thank you,
Bernard

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 08, 2009 Jun 08, 2009

Copy link to clipboard

Copied

(bnguyen) wrote:

I'm having this problem where the focus is on my ListView control but as soon as the pdf is loaded in code my ListView loses focus to the PDF Browser Controls. I've tried to look for something like an onLoadCompleted event in AxAcroPDF but without luck in order to set the focus back to my ListView. Has anyone experienced this problem? Please help!!

axAcroPDF1.LoadFile(C:\\test.pdf);
// if i set the focus like this in code it only works in debugging mode
listView1.Focus();
listView1.Items[index].Focused = true;
listView1.Select();

Thank you,
Bernard

Bernard,

I have this same issue - have you been able to find a solution?  Or can anyone recommend a solution? I would appreciate some help, thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2009 Jun 29, 2009

Copy link to clipboard

Copied

ekb0211 wrote:

(bnguyen) wrote:

I'm having this problem where the focus is on my ListView control but as soon as the pdf is loaded in code my ListView loses focus to the PDF Browser Controls. I've tried to look for something like an onLoadCompleted event in AxAcroPDF but without luck in order to set the focus back to my ListView. Has anyone experienced this problem? Please help!!

axAcroPDF1.LoadFile(C:\\test.pdf);
// if i set the focus like this in code it only works in debugging mode
listView1.Focus();
listView1.Items[index].Focused = true;
listView1.Select();

Thank you,
Bernard

Bernard,

I have this same issue - have you been able to find a solution?  Or can anyone recommend a solution? I would appreciate some help, thanks!

I also have this issue. Anyone managed to figure this out yet?

Thanks, Nate

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2009 Nov 30, 2009

Copy link to clipboard

Copied

LATEST

Right now the only way I get it to work is by setting the Activate and Focus of the non-Acrobat controls with a timer event; but this isn't reliable depending on changes in performance.

Let me know if you figure this problem out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 23, 2008 Oct 23, 2008

Copy link to clipboard

Copied

I have added the Adobe PDF Reader to my VS2005 toolbox, I have dragged the icon onto my windows form, when I compile the program I get no errors, but when I activate the form with the reader on it, I get the following: Class not recognised (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
I am developing on windows XP 64bit, is the message because I'm using a 64 bit OS, or have I missed something?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 23, 2008 Oct 23, 2008

Copy link to clipboard

Copied

I'll check to verify, but I believe this is currently not supported for 64-bit. Try compiling as a 32-bit application.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 24, 2008 Oct 24, 2008

Copy link to clipboard

Copied

I thought I'd already set this to x86, but checking showed any cpu.
I haven't done anything with the control but it doesn't crash, so it's looking hpopeful.
Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines