Solved

How do I print a multipage pdf document in C#

Posted on 2008-06-13
7
1,308 Views
Last Modified: 2012-06-21
I am opening up a pdf document, filling the fields with data and want to print the document. I am having troubles with the print part. I was thinking of perhaps counting the number of pages in the document and storing that value in printpagessilent method (the second 0 is the nLastPage), but I am unsure on how that is accomplished.

Dave
The following code worked great, but unfortunately it brings up a print dialog screen and you would always have to click the ok button. I need to print the pages silent.
 

acroApp.MenuItemExecute("Print")
 

The following code works fine if you have a set number of pages. 

avDoc.PrintPagesSilent(0, 0, 0, 0, 1)

Open in new window

0
Comment
Question by:kalittaair
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:Raisor
ID: 21785122
Hi,

how about trying:

int pagenum = (avDoc.GetNumPages() - 1);
avDoc.PrintPagesSilent(0, pagenum, 1, 0, 1);


Best regards,
Raisor
0
 

Author Comment

by:kalittaair
ID: 21792481
Hi Raisor,

Well I am on the right path because I saw the use of GetNumPages in the SDK Summary of OLE objects and methods section that I downloaded from Adobe but whenever I tried to use it, it is not available with the intellisense. I tried the suggestion you sent anyway and an error, (like I thought it would do) states "Acrobate.CAcroAVDoc does not contain a definition for 'GetNumPages' and no extension method 'GetNumPages' accepting..."

Perhaps I am missing an Adobe library file? I am using Adobe 8 Professional.

Best Regards,
Dave

0
 
LVL 15

Expert Comment

by:Raisor
ID: 21793469
Hi,

I'm not sure if you've added the correct references!

You may have a look at this thread: http://groups.google.com/group/adobe.acrobat.sdk/browse_thread/thread/3d2da62344fc5097

... it should give you an idea about the correct references.


Best regards,
Raisor
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:kalittaair
ID: 21797393
Hello
In C# I had to use the following code to get access to the pDDoc methods.
           CAcroPDDoc pdDoc = new AcroPDDocClass();
To get the PDDoc, (whic contains the method GetNumPages) associated with a particular AVDoc object, your supposed to use the GetPDDoc method. Have any ideas on how to join the two together?
I got as far as:
int pageNum = (avDoc.GetPDDoc(pdDoc.GetNumPages()-1)); but it's wrong because there is no overload for method 'GetPDDoc' takes '1' arguments.

Best Regards,
Dave
0
 
LVL 15

Expert Comment

by:Raisor
ID: 21797729
Hi,

I'll have a closer look at it and get back with detailed information soon!


Best regards,
Raisor
0
 
LVL 15

Accepted Solution

by:
Raisor earned 250 total points
ID: 21811129
Hi,

Let's try it this way:

CAcroPDDoc pdDoc = (Acrobat.CAcroPDDoc)new Acrobat.AcroPDDocClass();
pdDoc.Open("C:\\YourPath\\YourPDF.pdf");
int pageNum = pdDoc.GetNumPages()


Best regards,
Raisor
0
 

Author Closing Comment

by:kalittaair
ID: 31468302
Hi,
Thank you, thank you, thank you! I didn't realize you had to open up the pdDoc after creating it since I thought creating a new instance of the PDDoc Class was a way to just join to the AVDoc class, (which had already opened the file). Anyway, the final code below works great and I appreciate all your patience and perseverance ! Give yourself a big pat on the back for this one.

            CAcroPDDoc pdDoc = new AcroPDDocClass();
            pdDoc.Open(FORM_NAME); //FORM_NAME is the const string of the file name used with avDoc
            int pageNum = (pdDoc.GetNumPages()-1);

            avDoc.PrintPagesSilent(0, pageNum, 0, 0, 1);
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now