Link to home
Start Free TrialLog in
Avatar of etan08
etan08Flag for United States of America

asked on

How to Print a Report in VFP 7 in PDF Format

Currently the code emulates that of wwpdf created by Rick Strahl.  The problem we're having is that the program works like it is supposed to when using VFP 5 printing to Adobe 5.  But we need it to print in Acrobat 7 when ran in VFP 7.  

Whenever the print report button is pushed it gives an error message "Error accessing printer spooler" I know that we aren't going to be able to use the wwpdf because it uses the pdf writer and we need to use the pdf maker for this version of Acrobat. I think.

I need code or help that will print the report, I'm thinking PDFCreator is looking like the better of the pdf printers from what I can tell.  But it doesn't matter really just need it to work.  I've been messing around with the PostScript driver too.  I can't get that to work either.

Please Help!!!
SOLUTION
Avatar of jrbbldr
jrbbldr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bchesley
bchesley

Assuming that the 'new' printer driver is installed on the target PC that is throwing the error I ask a question.

How are you setting the printer to use?   If in code (i.e., SET PRINTER TO and using data from GETPRINTERS() function) you may want to open the foxpro report format in question in VFP7 and check the printer that is defined with the report (i.e., open the report format file and then use File->Printer Setup to open the setup dialog, then click on Print Setup command button to set the new driver) and save the new printer driver with the report format.  

This error is foxpro error #1957 (An internal call to the GetPrinter( ) function has failed. Visual FoxPro calls this function through either PRTINFO( ) or SET PRINTER TO).  It usually indicates that the SET PRINTER TO command is referencing a non existent (i.e., not installed locally) printer name or that there may be some printer access permission problem.

Hope this helps.

Bob

PS - report format print setup dialog from vfp7 attached FYI.


vf-ee2.gif
Avatar of etan08

ASKER

Here's the code that I'm trying to change in order to change it to print in vfp7 and adobe 7.  It's giving me an error "Object OPDF is not found".  I've tried to change this code in a few different way and am coming up empty.  I think if I get these four lines right then my report will print like it's supposed to.  

The OPDF line is:
 oPDF.PrintReport("j23_ftot",loutfile) && this is 5.0 call to method of object instan up above

It appears 4 times in this code.
It looks like that was the 5.0 way to call the method.

Am I correct in assuming that this line must be changed in order for 7.0 to print to PDFCreator? If so, how do these lines need to be changed.  If not, what should I do to get the desired results?
*j23 main form . cmdPDFoutput button
* get values for a 'final' report and send it to  PDF writer
* rest of code is modeled on j23_finl.prg
*j23_finl.prg called from j23_main.scx 'pre-final report' button and 'final report' button
*
*og 06/12/03 modify the PDF output to work with adobe 5.0 PDFWriter print driver rather
*	then the 4.0 talk2ini method
*   This uses 2 public domain classes writen by Rick Strahl www.west-wind.com
*   wwpdf.prg, wweval.prg and also his compilation header file wconnect.h
 
IF empty(thisform.txtpdfpath.value) or !('\'$thisform.txtpdfpath.value)
  MESSAGEBOX("Please enter a path ending in '\' for PDF output")
  RETURN
ELSE
  x=fcreate(alltrim(thisform.txtpdfpath.value)+'test.txt')
  Y=fclose(x)
  Y=file(alltrim(thisform.txtpdfpath.value)+'test.txt')
  IF not y
    MESSAGEBOX("This doesn't seem to be a valid path.")
    RETURN
  ENDIF
ENDIF
IF mscope=1
  x=messagebox("This will output for over 500 districts in groups of 25. Continue",292,"")
  IF x<>6
    RETURN
  ENDIF
ENDIF
PRE_FLAG = .f.
set step on
****************** pdf set up stuff
*SET proc to talk2ini additive && this and next 2 worked for acrobat 4.0
*lcBeginPDFFilename = READINI('Acrobat PDFWriter','PDFFilename','win.ini')
*lcBeginDocInfo = READINI('Acrobat PDFWriter','bDocInfo')
* next 2 are for acrobat 5.0 using PDFWriter (not PDF Distiller)
*DO wwPDF  && load the libraries wwpdf and wweval
*oPDF=CREATE("wwPDF50")
SET PRINTER TO PDFCreator
* getsystemdir() this not needed for 4.0
* messagebox(lcBeginPDFFilename) this not needed for 4.0
* set acrobat to ignore doc info box
* WRITEINI('Acrobat PDFWriter','bDocInfo',"0") && this for acrobat 4.0
* SET printer to name 'Acrobat PDFWriter' && this for acrobat 4.0
* now only have to give a value to lcoutfile and use WRITEINI() to put it into win.ini
**************************
 
CLOSE tables
WAIT wind "...............opening sql data source.............." nowait
OPEN database j23self
USE rvscmboth
* mscope is option from calling screen 1=alldistricts, 2=a selected district,
*         3= state totals only.
oldtalk=sys(2001,'talk')
SET talk off
syear=year(date())
DO case
CASE mscope=1   && this is doing pre-final calc and report for all districts.
  *og1120
  *!*	    sele distinct district,isd from bus_mast,scm93 ;
  *!*	     where bus_mast.district=scm93.dcode and scm93.bcode='0000' ;
  *!*	     order by 2,1 into cursor dis
  SET safety off
  SELE distinct district,isdcode as isd from rvbusandmast,rvscmboth ;
    where rvbusandmast.district=rvscmboth.districtcode ;
    order by 2,1 into cursor dis
  SET safety on
  max_prn=_tally
  SELE dis
  prn_cnt=0
  SCAN
    mdis=district
    prn_cnt=prn_cnt+1
    IF prn_cnt>0
      syear=year(Date())
      SELE rvscmboth
      SET safety off
      INDEX on districtcode tag dis
      SET safety on
      *endog1120
      SEEK mdis
      *og1120 dis_name=dname
      *og1120 misd=isd
      dis_name=legalname
      misd=isdcode
      WAIT wind nowait 'SELECTING BUSES'
      *og1120
      *!*	select all * from bus_mast,buses where bus_mast.bus_ref_no=buses.bus_ref_no and district=mdis ;
      *!*	and bus_stat # 'D' into TABLE finx_rep
      SET safety off
      *note rvpbusandmast_mdis is a parameterized view and it uses the operator entered value of 'mdis'
      SELECT * ;
        FROM  j23self!rvpbusandmast_mdis Rvpbusandmast_mdis_a LEFT OUTER JOIN j23self!rvamort Rvamort_a ;
        ON  Rvpbusandmast_mdis_a.amort_type = Rvamort_a.amort_type;
        WHERE Rvpbusandmast_mdis_a.bus_stat <> 'D' into table finx_rep
      *og Aug 20,01
      SELECT all count(*) as stat_cnt, sum(bus_depr_a) as amrt_tot,status_cd from finx_rep ;
        group by status_cd into table finx_tot
      *
 
      * get second cursor for second reprot
      SELECT finx_tot.stat_cnt, finx_tot.amrt_tot, Rvstat.*;
        FROM  finx_tot LEFT OUTER JOIN j23self!Rvstat ;
        ON  finx_tot.status_cd = Rvstat.status_cd;
        GROUP BY Rvstat.status_cd;
        ORDER BY Rvstat.disp_ord into table finx_to1
 
      SET safety on
      WAIT wind nowait 'PRINTING REPORT'
      SELE finx_rep
      *og1120  the report 'j23_finl' has been mod to includ lyr_depr_t field
      *set acrobat output filename to date string and district number
      loutfile=alltrim(thisform.txtpdfpath.value)+alltrim(str(syear))+mdis+"A.pdf" 
*      WRITEINI('Acrobat PDFWriter','PDFFileName',m.loutfile,'win.ini') && 4.0
*      REPO form J23_FINL to print noconsol && 4.0
       oPDF.PrintReport("j23_finl",loutfile) && this is 5.0 call to method of object instan up above
	  
      xpageno=_pageno
      USE
      * add second part of a districts final report
      SELE finx_to1
      loutfile=alltrim(thisform.txtpdfpath.value)+alltrim(str(syear))+mdis+"b.pdf"
*      WRITEINI('Acrobat PDFWriter','PDFFileName',m.loutfile,'win.ini') && 4.0
*      REPO form j23_ftot to print noconsol && 4.0
       oPDF.PrintReport("j23_ftot",loutfile) && this is 5.0 call to method of object instan up above
      USE
      *end add second part of a district's final reprot
      SELE rvpbusandmast_mdis
      USE
      WAIT wind nowait 'Output'+loutfile+' for District/ISD '+dis.district+'/'+dis.isd+'  '+str(prn_cnt,4)+' of '+str(max_prn,4)
      xx=seconds()
      DO while seconds()-xx<1
      ENDDO
      *!*	      IF mod(prn_cnt,25)=0
      *!*	        xxx=messagebox('Printed '+str(prn_cnt,4)+' of '+str(max_prn,4)+' Continue with next 25?',292,'')
      *!*	        IF xxx#6
      *!*	          CLOSE tables all
      *!*	          SET talk &oldtalk
      *!*	          RETURN
      *!*	        ENDIF
      *!*	      ENDIF
    ENDIF
    SELE dis
  ENDSCAN
  mdis='     '
CASE mscope=2 and mdis='     '
  WAIT 'Select District First' wind
CASE mscope=2   && this is doing pre-final calc and report for a selected district
 
  SELE rvscmboth
  SET safety off
  INDEX on districtcode tag dis
  SET safety on
  *endog1120
  SEEK mdis
  *og1120 dis_name=dname
  *og1120 misd=isd
  dis_name=legalname
  misd=isdcode
  WAIT wind nowait 'SELECTING BUSES'
  *og1120
  *!*	select all * from bus_mast,buses where bus_mast.bus_ref_no=buses.bus_ref_no and district=mdis ;
  *!*	and bus_stat # 'D' into TABLE finx_rep
  SET safety off
  *note rvpbusandmast_mdis is a parameterized view and it uses the operator entered value of 'mdis'
  SELECT * ;
    FROM  j23self!rvpbusandmast_mdis Rvpbusandmast_mdis_a LEFT OUTER JOIN j23self!rvamort Rvamort_a ;
    ON  Rvpbusandmast_mdis_a.amort_type = Rvamort_a.amort_type;
    WHERE Rvpbusandmast_mdis_a.bus_stat <> 'D' into table finx_rep
  *og Aug 20,01
  SELECT all count(*) as stat_cnt, sum(bus_depr_a) as amrt_tot,status_cd from finx_rep ;
    group by status_cd into table finx_tot
  *
  * get second cursor for second reprot
  SELECT finx_tot.stat_cnt, finx_tot.amrt_tot, Rvstat.*;
    FROM  finx_tot LEFT OUTER JOIN j23self!Rvstat ;
    ON  finx_tot.status_cd = Rvstat.status_cd;
    GROUP BY Rvstat.status_cd;
    ORDER BY Rvstat.disp_ord into table finx_to1
 
  SET safety on
  WAIT wind nowait 'PRINTING REPORT'
  
  SELE finx_rep
  *og1120  the report 'j23_finl' has been mod to includ lyr_depr_t field
  loutfile=alltrim(thisform.txtpdfpath.value)+alltrim(str(syear))+mdis+"a.pdf" 
  *set acrobat4.0 output filename to date string and district number (set print was done above)
  *WRITEINI('Acrobat PDFWriter','PDFFileName',m.loutfile,'win.ini') && for 4.0
  *REPO form J23_FINL to print noconsol && for 4.0
  oPDF.PrintReport("j23_finl",loutfile) && this is call to method of object instan up above
  xpageno=_pageno
  USE
  * add second part of a district's final report
  SELE finx_to1
  loutfile=alltrim(thisform.txtpdfpath.value)+alltrim(str(syear))+mdis+"b.pdf"
  *WRITEINI('Acrobat PDFWriter','PDFFileName',m.loutfile,'win.ini') && for 4.0
  *REPO form j23_ftot to print noconsol && for 4.0
  oPDF.PrintReport("j23_ftot",loutfile) && this is 5.0 call to method of object instan up above
  USE
  *end add second part of a district's final reprot
 
CASE mscope=3   && this is doing pre-final calc and report to get just state totals
  WAIT wind 'State totals report not available for PDF format.'
ENDCASE
CLOSE tables
SET talk &oldtalk
*  reset the acrobat default 4.0
*lcoutfile = lcBeginPDFFilename && for 4.0
*WRITEINI('Acrobat PDFWriter','PDFFileName',m.lcoutfile,'win.ini') && for 4.0
*Release procedure talk2ini && for 4.0
*release procedure wwpdf && 5.0
*release procedure wweval && 5.0
 
Release PRE_FLAG
RETURN
 
********************

Open in new window

The line with *oPDF=CREATE("wwPDF50") is commented out in your code and then you attempt to use this object to call the print function.  

If you are going to use this object you have to instantiate it.

bc
Avatar of etan08

ASKER

That's the problem I need to get rid of this way to print to pdf because it won't work using foxpro7 and adobe 7.

Basically I'm trying to update the code so I am able to print to pdf in 7.0.  This was the old method that worked in 5.0 using the (Rick Strahl www.west-wind.com) program.  Also commented out is the 4.0 way they used this program to print to pdf.

I don't want to use the oPDF lines because they won't work as I have to scrap the wwPDF50 method and figure out how this program will print reports in pdf now that we don't use vfp 5.0.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of etan08

ASKER

I keep trying to make the report print using ps2pdf but every time the code goes through the debugger it give the error message "File does not exist".  The location that I'm trying to send the .ps file to has a file there but it is 0 kb no matter how I change the coding. Any ideas on what I could be doing wrong?

In the program there is a txt box that asks where to put the file and what to name it.  I've tried commenting the validation for this field to try without user intervention as you suggested but that didn't work either.  

Thanks for helping!
Have you checked out my suggestion of using Amyuni? Here is a recent thread where the author decided it was the best choice and explains why.

https://www.experts-exchange.com/questions/23855581/PDF-via-DLL.html?cid=236&anchorAnswerId=22825459#a22825459 
Avatar of etan08

ASKER

We apparently only needed to use VFP 6.0 and not 7.0 so I was able to install just the pdfWriter driver from Adobe 5 and make the program work utilizing the wwPDF.prg from westwind technologies printing to Adobe 7.   I'm giving points though because it is good information and was helpful in trying to help figure out my problem.
Avatar of etan08

ASKER

Thanks!