Tags: copying, create, creating, customize, database, file, foxpro, howcan, microsoft, mysql, oracle, output, pdf, prevent, programmatically, sql, thru, vfp, vfp8

Creating PDF thru VFP

On Database » Microsoft FoxPro

13,320 words with 5 Comments; publish: Wed, 30 Apr 2008 18:34:00 GMT; (250171.88, « »)

Hi to all,

I want to create a PDF file using VFP8 programmatically. My question is how

can I customize the output PDF, say prevent the copying and printing of the

contents (like setting the security using Adobe Acrobat) using VFP8.

Any help would be much appreciated...

Allan

All Comments

Leave a comment...

  • 5 Comments
    • There are many tools out there. Check the download section of universal

      thread. Two of the most popular are XFRX and FRX2ANY. I use XFRX and find it

      works quite well.

      Regards,

      Jeff

      "Allan" <Allan.ms-foxpro.questionfor.info.discussions.microsoft.com> wrote in message

      news:A77104D0-5463-48A3-A11B-AA93E82DA301.ms-foxpro.questionfor.info.microsoft.com...

      > Hi to all,

      > I want to create a PDF file using VFP8 programmatically. My question is

      > how

      > can I customize the output PDF, say prevent the copying and printing of

      > the

      > contents (like setting the security using Adobe Acrobat) using VFP8.

      > Any help would be much appreciated...

      > Allan

      #1; Wed, 30 Apr 2008 18:35:00 GMT
    • Hi Allan:

      Here is some code that shows how to create a PDF file from VFP using

      PDF995, a third party tool. However, I have no information on how to

      customize the output PDF file.

      1. Get the PDF995 driver form http://site4.pdf995.com/download.html.

      2. Make sure Windows Scripting Host is installed

      3. Run code below.

      Note: The PDF995 driver displays a web site advertisement when you complete

      printing. You can turn this off by buying a key from the maker of PDF995.

      *--

      *

      * ABSTRACT: Demo showing how to print a Fox report to a PDF

      * via the PDF995 driver (http://site4.pdf995.com/download.html).

      * You need to download and install the Pdf995 Printer Driver and the

      * "Free Converter" from the site above in order to run this code.

      * Once that is done, save this to a .PRG and run it. It will create

      * it's own table, report, etc. for demo purposes.

      *

      * When finished, you will get a messagebox saying "COMPLETE!" and

      * there will be a file named "MYPDF.PDF" in the same DIR as this .PRG.

      *--

      DECLARE INTEGER Sleep IN Win32API INTEGER

      DECLARE INTEGER FindWindow IN WIN32API STRING, STRING

      DECLARE SetWindowPos IN WIN32API ;

      LONG HWND, ;

      LONG hwndafter, ;

      LONG x, ;

      LONG Y, ;

      LONG cx, ;

      LONG cy, ;

      LONG flags

      CLOSE DATA ALL

      LOCAL i AS INTEGER, ;

      lcThisDir AS STRING, ;

      lcPDFFileName AS STRING

      i = 0

      lcThisDir = ADDBS(JUSTPATH(SYS(16)))

      lcPDFFileName = lcThisDir + [MYPDF.PDF]

      CD (lcThisDir)

      ERASE *.PDF

      *-- Create a temp table to report off of.

      CREATE CURSOR TEST (cID c(10), FNAME c(30), LNAME c(30))

      FOR i = 1 TO 10

      INSERT INTO TEST VALUES ;

      (SYS(2015), [F] + TRANS(i), [L] + TRANS(i))

      ENDFOR

      *-- Create a dummy report

      CREATE REPORT MyReport FROM TEST

      *-- Run the report after setting the printer to

      *-- PDF driver.

      SET PRINTER TO NAME PDF995

      REPORT FORM MyReport TO PRINTER NOCONSOLE

      *-- Call the help procedure that

      *-- processes the saving via the PDF995 dialog.

      SetPDF_FileName(lcPDFFileName)

      *-- Clean up and bail

      CLOSE DATA ALL

      ERASE MyReport.*

      CLEAR DLLS

      RELEASE ALL

      MESSAGEBOX([Complete!])

      *~~~~~~~~~~~

      FUNCTION SetPDF_FileName(lpFileName AS STRING)

      #DEFINE HWND_TOPMOST -1

      #DEFINE SWP_HIDEWINDOW 80

      LOCAL lnPDFWinHand AS LONG, ;

      loWSH AS wscript.SHELL

      lnPDFWinHand = 0

      *-- Create an instance of the wscript.shell

      *-- object. We use this to fill in the file name

      *-- on the PDF995 "Save As" dialog via the SendKeys()

      *-- method of the object. Poor-mans automation. <g>

      loWSH = NEWO([wscript.shell])

      *-- Get a handle to the PDF995 "Save As" dialog

      DO WHILE lnPDFWinHand = 0

      lnPDFWinHand = FindWindow(0, [PdF995 Save As])

      DOEVENTS

      ENDDO

      *-- Once we have a handle, move it off screen

      *-- and hide it ASAP via the SetWindowPos API.

      *-- Not necessary, but looks cleaner. You DO need to set

      *-- that dialog to the foreground window. That's taken

      *-- care of by passing the hwnd_topmost param to

      *-- SetWindowPos.

      *-- NOTE: You need error trapping here to prevent this next call

      *-- if we DIDN'T get a handle to the "Save As" dialog

      *-- for some reason.

      SetWindowPos(lnPDFWinHand, HWND_TOPMOST, ;

      -500, -500, 0, 0, SWP_HIDEWINDOW)

      *-- The textbox on the "Save As" dialog that accepts the

      *-- file name has focus when this dialog opens, so we just

      *-- fill it with the file name via SendKeys().

      loWSH.SendKeys(lpFileName)

      *-- Sleep for 1/2 a second to make sure it went in fine.

      Sleep(500)

      *-- Click the "Save" button on the "Save As" dialog

      *-- via SendKeys()

      loWSH.SendKeys([%s])

      *-- Release our scripting object and bail

      RELEASE loWSH

      RETURN

      I hope this helps.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      Sincerely,

      Microsoft FoxPro Technical Support

      Lee Mitchell

      *-- VFP9 HAS ARRIVED!! --*

      Read about all the new features of VFP9 here:

      http://msdn.microsoft.com/vfoxpro/

      *--Purchase VFP 9.0 here:

      http://www.microsoft.com/PRODUCTS/i...cid=54787e64-52

      69-4500-8bf2-3f06689f4ab3&type=ovr

      Keep an eye on the product lifecycle for Visual FoxPro here:

      http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv

      - VFP5 Mainstream Support retired June 30th, 2003

      - VFP6 Mainstream Support retired Sept. 30th, 2003

      >There are many tools out there. Check the download section of universal

      >thread. Two of the most popular are XFRX and FRX2ANY. I use XFRX and find

      it

      >works quite well.

      >Regards,

      >Jeff

      >"Allan" <Allan.ms-foxpro.questionfor.info.discussions.microsoft.com> wrote in message

      >news:A77104D0-5463-48A3-A11B-AA93E82DA301.ms-foxpro.questionfor.info.microsoft.com...

      > Hi to all,

      > I want to create a PDF file using VFP8 programmatically. My question is

      > how

      > can I customize the output PDF, say prevent the copying and printing of

      > the

      > contents (like setting the security using Adobe Acrobat) using VFP8.

      > Any help would be much appreciated...

      > Allan

      #2; Wed, 30 Apr 2008 18:36:00 GMT
    • Thanks a lot... I will try your suggestions...

      Allan

      "Lee Mitchell" wrote:

      > Hi Allan:

      > Here is some code that shows how to create a PDF file from VFP using

      > PDF995, a third party tool. However, I have no information on how to

      > customize the output PDF file.

      > 1. Get the PDF995 driver form http://site4.pdf995.com/download.html.

      > 2. Make sure Windows Scripting Host is installed

      > 3. Run code below.

      > Note: The PDF995 driver displays a web site advertisement when you complet

      e

      > printing. You can turn this off by buying a key from the maker of PDF995.

      >

      > *--

      > *

      > * ABSTRACT: Demo showing how to print a Fox report to a PDF

      > * via the PDF995 driver (http://site4.pdf995.com/download.html).

      > * You need to download and install the Pdf995 Printer Driver and the

      > * "Free Converter" from the site above in order to run this code.

      > * Once that is done, save this to a .PRG and run it. It will create

      > * it's own table, report, etc. for demo purposes.

      > *

      > * When finished, you will get a messagebox saying "COMPLETE!" and

      > * there will be a file named "MYPDF.PDF" in the same DIR as this .PRG.

      > *--

      > DECLARE INTEGER Sleep IN Win32API INTEGER

      > DECLARE INTEGER FindWindow IN WIN32API STRING, STRING

      > DECLARE SetWindowPos IN WIN32API ;

      > LONG HWND, ;

      > LONG hwndafter, ;

      > LONG x, ;

      > LONG Y, ;

      > LONG cx, ;

      > LONG cy, ;

      > LONG flags

      > CLOSE DATA ALL

      > LOCAL i AS INTEGER, ;

      > lcThisDir AS STRING, ;

      > lcPDFFileName AS STRING

      > i = 0

      > lcThisDir = ADDBS(JUSTPATH(SYS(16)))

      > lcPDFFileName = lcThisDir + [MYPDF.PDF]

      > CD (lcThisDir)

      > ERASE *.PDF

      > *-- Create a temp table to report off of.

      > CREATE CURSOR TEST (cID c(10), FNAME c(30), LNAME c(30))

      > FOR i = 1 TO 10

      > INSERT INTO TEST VALUES ;

      > (SYS(2015), [F] + TRANS(i), [L] + TRANS(i))

      > ENDFOR

      > *-- Create a dummy report

      > CREATE REPORT MyReport FROM TEST

      > *-- Run the report after setting the printer to

      > *-- PDF driver.

      > SET PRINTER TO NAME PDF995

      > REPORT FORM MyReport TO PRINTER NOCONSOLE

      > *-- Call the help procedure that

      > *-- processes the saving via the PDF995 dialog.

      > SetPDF_FileName(lcPDFFileName)

      > *-- Clean up and bail

      > CLOSE DATA ALL

      > ERASE MyReport.*

      > CLEAR DLLS

      > RELEASE ALL

      > MESSAGEBOX([Complete!])

      >

      > *~~~~~~~~~~~

      > FUNCTION SetPDF_FileName(lpFileName AS STRING)

      > #DEFINE HWND_TOPMOST -1

      > #DEFINE SWP_HIDEWINDOW 80

      > LOCAL lnPDFWinHand AS LONG, ;

      > loWSH AS wscript.SHELL

      > lnPDFWinHand = 0

      > *-- Create an instance of the wscript.shell

      > *-- object. We use this to fill in the file name

      > *-- on the PDF995 "Save As" dialog via the SendKeys()

      > *-- method of the object. Poor-mans automation. <g>

      > loWSH = NEWO([wscript.shell])

      > *-- Get a handle to the PDF995 "Save As" dialog

      > DO WHILE lnPDFWinHand = 0

      > lnPDFWinHand = FindWindow(0, [PdF995 Save As])

      > DOEVENTS

      > ENDDO

      > *-- Once we have a handle, move it off screen

      > *-- and hide it ASAP via the SetWindowPos API.

      > *-- Not necessary, but looks cleaner. You DO need to set

      > *-- that dialog to the foreground window. That's taken

      > *-- care of by passing the hwnd_topmost param to

      > *-- SetWindowPos.

      > *-- NOTE: You need error trapping here to prevent this next call

      > *-- if we DIDN'T get a handle to the "Save As" dialog

      > *-- for some reason.

      > SetWindowPos(lnPDFWinHand, HWND_TOPMOST, ;

      > -500, -500, 0, 0, SWP_HIDEWINDOW)

      > *-- The textbox on the "Save As" dialog that accepts the

      > *-- file name has focus when this dialog opens, so we just

      > *-- fill it with the file name via SendKeys().

      > loWSH.SendKeys(lpFileName)

      > *-- Sleep for 1/2 a second to make sure it went in fine.

      > Sleep(500)

      > *-- Click the "Save" button on the "Save As" dialog

      > *-- via SendKeys()

      > loWSH.SendKeys([%s])

      > *-- Release our scripting object and bail

      > RELEASE loWSH

      > RETURN

      >

      > I hope this helps.

      > This posting is provided "AS IS" with no warranties, and confers no rights

      .

      > Sincerely,

      > Microsoft FoxPro Technical Support

      > Lee Mitchell

      > *-- VFP9 HAS ARRIVED!! --*

      > Read about all the new features of VFP9 here:

      > http://msdn.microsoft.com/vfoxpro/

      > *--Purchase VFP 9.0 here:

      > http://www.microsoft.com/PRODUCTS/i...ult.aspx?id=fh;[ln];lifeprodv

      > - VFP5 Mainstream Support retired June 30th, 2003

      > - VFP6 Mainstream Support retired Sept. 30th, 2003

      >

      > it

      >

      >

      >

      #3; Wed, 30 Apr 2008 18:37:00 GMT
    • Also have a look at pdfcreator:

      sector7g.wurzel6.de/pdfcreator/index_en.htm

      This has (some of) the security features requested and is open source:

      sourceforge.net/projects/pdfcreator

      Steve

      #4; Wed, 30 Apr 2008 18:38:00 GMT
    • You could use a Free tool called vfp2pdf

      http://www.1amsoftware.com/Downloads.htm

      Basically it uses ghostscript to convert you vfp reports into pdf documents.

      Simple, installs itself, and about 1 line of code to modify in your prg's

      Bob Lee

      quote:
      === Original Words ===

      Allan

      Hi to all,

      I want to create a PDF file using VFP8 programmatically. My question is how

      can I customize the output PDF, say prevent the copying and printing of the

      contents (like setting the security using Adobe Acrobat) using VFP8.

      Any help would be much appreciated...

      Allan


      #5; Wed, 30 Apr 2008 18:39:00 GMT