Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDF Printing in visual foxpro 1

Status
Not open for further replies.

rvfoxpro

Programmer
Aug 28, 2019
2
IN
Hello all

I am developing an application in visual FoxPro where I have to open a PDF file and print specific page numbers from it and close the file. System will loop thru a list of PDF files and perform the above actions. I have searched online for such a solution but not able to find any. Could someone please help me on this?

Thanks in Advance
 
You can use ShellExecute() to print the entire PDF (pass "print" as the second parameter), but unfortunately that won't let you print a specific page.

No doubt somebody else will have the answer.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Dan, you linked to XFRX. I don't think that will solve the problem. XFRX can convert a VFP report to a PDF, but as far as I know it has no ability to print an arbitrary PDF. You would need some other software for that. Mark's suggestion for Bullzip might be more appropriate.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Another suggestion:

Run your standard PDF viewer from the command line. How you do that would depend on which utility you use to view and print PDFs. Here is some code that would work for the (free) SumatraPDF utility:

First, declare ShellExecute(). You only need to do this once.

Code:
DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin

Then, to print specified pages from a given file:

Code:
cAction = "open"
cFileName = "C:\Program Files\SumatraPDF\SumatraPDF.exe" && substitute correct path
cParams = '-print-to-default -print-settings "1-2" c:\work\test.pdf'
              && this says: print pages 1 -2 of file test.pdf to the default printer
ShellExecute(0, cAction, cFileName, cParams, "", 1)

You can use similar code to print to a printer other than the default, to print odd or even pages, to print duplex or single-side, to scale the printing, and several other options.

The disadvantage of this technique is that it depends on Sumatra being installed. Other command-line options might be available with other utilities.

Here's a link:
Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello,

I remember that there is a portable version of sumatra
which you could add to your program folder without installing.
Then use Mike's tips.

Regards
tom
 
Thanks so much Mike. Works like a charm

Just a query. If I need a different printer, can I just replace the -print-to-default with -print-to-<printer name>? or is there some other consideration?

Thanks in advance

Ravi
 
Glad it worked, Ravi.

If I need a different printer, can I just replace the -print-to-default with -print-to-<printer name>?

That should be fine. For exammple:

[tt]-print-to "HP LaserJet 400"[/tt]

Be sure to use double-quotes for the printer name.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top