Solved

Printing PDF documents with Delphi

Posted on 2004-03-25
2
873 Views
Last Modified: 2008-11-25
Hi, everybody.

I need a snippet that will open an existing PDF document, and print an arbitrary page from it.
If it takes any library or component to do it, it must be available free of charge (or must ship with Delphi 7).

It would be most desirable if it was also possible to print several separate pages as one single print job.

In pseudocode, it would look like this:

PDF_File.Open('C:\MyDoc.pdf');
PDF_File.StartPrintJob('SomePrinter'); // Default printer is just fine. I don't care
PDF_File.PrintPage(34);
PDF_File.PrintPage(122);
PDF_File.PrintPage(345);
PDF_File.ClosePrintJobAndDamnPrintIt; // :-)

To print pages 34, 122, and 345 without giving the chance of other users sending anything to the printer between one of my pages and another.

I also don't care if it is done directly with Delphi, or if it uses Automation to have Acrobat Reader do it.

Thanks very much for your help:

Jack
0
Comment
Question by:JackNaif
2 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 125 total points
Comment Utility
You can use the ActiveX control of Adobe Acrobat

from Component menu > Import ActiveX control then choose
Acrobat Control for ActiveX, then press Install

the Pdf Activex control for Adobe acrobat will be added to ActiveX Tab of Delphi then
 drop pdf control to the form and try this code

procedure TForm1.Button1Click(Sender: TObject);
begin
  Pdf1.Visible := False;
  Pdf1.LoadFile('c:\test.pdf');
  pdf1.printPages(1,1);
end;

if you want to print the entire file Call pdf1.Print

Shane
0
 
LVL 15

Expert Comment

by:simonet
Comment Utility

Just to add to Shane's comment:

everyone that has Acrobat Pro or Acrobat Viewer installed has the ActiveX control installed on their computer (nowadays that means basically everyone), so there is no need for you to redistribute the activeX control along with your app.

Alex
0

Featured Post

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.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

8 Experts available now in Live!

Get 1:1 Help Now