Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2006, 09:49 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Acrobat Reader Automation?

Im trying to automat Acrobat Reader. I want to print pdf-files.

I added a reference to AcroPDFLib and typed the following:

      Dim a As AcroPDFLib.AcroPDFClass
      a = CreateObject("AcroPDF.PDF.1")
      a.LoadFile("atmel_instruction_set.pdf")

Now, the object creates itself ok (i think) at least when i check the windows task manager the AcroRd32.exe is running.

But when the last line executes i get "Object reference not set to an instance of an object"

What am i doing wrong?

Thanks in advance



 
Old June 14th, 2006, 10:23 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am doing the same stuff and it is giving me AccessViolationException in C# .Net 2.0 Windows Application. I have hereby pasted my code below. If someone knows the reply please let me know my e-mail address is raviking001 @ yahoo.com. I would be really happy to know the answer and I would dance in Joy.
================================================== ===========

private void button1_Click(object sender, EventArgs e)
{
         AcroPDFLib.AcroPDFClass Acro = new AcroPDFClass();
         Acro.LoadFile("D:\\Doc1.pdf"); //Error happens here
         Acro.Print();
}


 
Old September 29th, 2006, 02:38 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to little.witch
Default

this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();
//
            // axAcroPDF1
            //
            this.axAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.axAcroPDF1.Enabled = true;
            this.axAcroPDF1.Location = new System.Drawing.Point(0, 0);
            this.axAcroPDF1.Name = "axAcroPDF1";
            this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("axAcroPDF1.OcxState")));
            //if you want to visualize the document before print
            this.axAcroPDF1.Size = new System.Drawing.Size(292, 266);
            this.axAcroPDF1.TabIndex = 0;
            this.axAcroPDF1.TabStop = false;
            //If you do not want to visualize the document
            this.axAcroPDF1.Visible = false;
//wherever you load the document you put this:
this.axAcroPDF1.LoadFile(@"C:\Inetpub\wwwroot\cycr nl2quvtg0rjadcrht23k_0.pdf");


//wherever you want to print the document:
  this.axAcroPDF1.printAll();//N.B. if you do not set in advance the
                             // print options of the document iit will
                             //be printed by default to the Windows
                             //MDI document printer, which is not very
                             // convenient, so take care to set any
                             //necessary printing parameter

//Comments on code:
AxInterop.AcroPDFLib.dll

AxAcroPDFLib is automatically loaded if you use the Acrobat Reader component -> generally there should not be any worry because of the component use, because if you are using Acrobat(and not any other PDF-hadling component), you are starting the whole Acrobat(Reader) application in deamon mode, whenever you create print job.
You could also manually add the reference to the dll and use the omponent absolutely programatically.

Greetings,
Eli




 
Old May 3rd, 2007, 03:39 PM
Registered User
 
Join Date: May 2007
Location: Huntingdon Valley, PA, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've done all that you suggested to create an instance of the Acrobat Reader, and it works just great.

As long as I only print one document at a time.

But if I try to print multiple documents in a loop, only the last one gets printed.

Something like this:

//After setting up the printer
foreach (string myFile in myFileCollection)
{
   myAxAcroPDF1.LoadFile(myFile);
   myAxAcroPDF1.PrintAll();
}

This code works as long as I print only one file at a time, or if I step through it slowly in debug mode. I guess that Adobe is returning control to my program before the file gets completely loaded and spooled. So my loop immediately loads and (tries to) print the next file.

Does anyone know how I cab guarantee that each file will actually print? Is there a way to know how long to wait, or an event that can be thrown, or some other indicator to let me know when file 1 is complete and it's okay to move on to file 2?

TIA
 
Old November 12th, 2007, 09:15 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are using AdobePDFClass, you haven't setup the ActiveX control properly.

DO NOT add the AdobePDF.dll file through the "Add reference" Pane,

Right click on the toolbox (for the form designer) and click on 'customize' or 'add more' (depending on version).

Add the Adobe Reader ActiveX Control

Then just add an Adobe PDF Reader component to your form, and a private adobe reference to an object will be created automatically.

You can turn it to invisible if you want.

I'm not sure if this does what you want, but I'm going to start from here.

 
Old January 17th, 2008, 04:03 PM
Registered User
 
Join Date: Jan 2008
Location: Mississauga, ON, Canada.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is great

After so much searching on google, Only this solution worked. But as it was mentioned, only able to print one printout. How to do a batch print out? I mean, anybody found out a fix to print files in a loop?
 
Old February 22nd, 2008, 06:15 AM
Registered User
 
Join Date: Feb 2008
Location: , , France.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

I'm trying to do the same as U skcsknathan001 but without success !
It works only when imake it step by step but the last file is missing !
And when I run my prog its does't works !
Did you find any solution to print files in a loop ?

Thanks you for answering

Have a good day


 
Old July 11th, 2008, 11:06 PM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In case of print multiple PDF file with one click you have to manage the object like below (Start with BeginInit() and end with EndInit()) before Loadfile and printWithDialog() method.


for(int i=0;i<collection;i++)
{
string sRefDoc = filenamePath;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typ eof(MainForm));

                                AxAcroPDFLib.AxAcroPDF axAcroPDF2 = new AxAcroPDFLib.AxAcroPDF();

                                ((System.ComponentModel.ISupportInitialize)(axAcro PDF2)).BeginInit();

                                axAcroPDF2.Enabled = true;

                                axAcroPDF2.Location = new System.Drawing.Point(227, 46);

                                axAcroPDF2.Name = "axAcroPDF_" + i.ToString();

                                axAcroPDF2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("axAcroPDF2.OcxState")));

                                axAcroPDF2.Size = new System.Drawing.Size(666, 517);

                                axAcroPDF2.TabIndex = 1;

                                axAcroPDF2.Visible = false;

                                panel.Controls.Add(axAcroPDF2);

                                ((System.ComponentModel.ISupportInitialize)(axAcro PDF2)).EndInit();

                                axAcroPDF2.LoadFile(sRefDoc);

                                axAcroPDF2.printWithDialog();

}


 
Old October 15th, 2008, 03:50 AM
Authorized User
 
Join Date: Jan 2004
Location: Cluj-Napoca, Cluj, Romania.
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to adyrotaru
Default

Quote:
quote:Originally posted by little.witch
//wherever you want to print the document:
this.axAcroPDF1.printAll();//N.B. if you do not set in advance the
                             // print options of the document iit will
                             //be printed by default to the Windows
                             //MDI document printer, which is not very
                             // convenient, so take care to set any
                             //necessary printing parameter
How to set printer's settings in advance?
I want to print the PDF as landscape on a network printer, but I can't figure it out.

If anyone can answer, please do, as it is urgent for me.
Thanks.


smile... tomorrow will be better
 
Old February 11th, 2009, 10:06 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile close prog error

I use the Acrobat Reader Automation, it can read the pdf file, but when i close the prog, error come out : the 0xxxxx memory can't read....why? can somebody help me,thanks!




Similar Threads
Thread Thread Starter Forum Replies Last Post
crystal report asp.net & acrobat reader hamzah Crystal Reports 0 February 28th, 2007 07:06 AM
bookmark a PDF file with Acrobat Reader/OpenOffice crmpicco Need help with your homework? 0 February 27th, 2006 01:13 PM
AcroPDF.PDF.1 object for detecting Acrobat Reader crmpicco Javascript How-To 0 December 1st, 2005 08:26 AM
detect if Adobe Acrobat Reader is installed crmpicco Classic ASP Basics 1 March 10th, 2005 10:47 AM
Acrobat document with Parameters jhom BOOK: Professional Crystal Reports for VS.NET 0 June 29th, 2004 03:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.