Document generation - design approach needed

Started by John Montenigro, February 07, 2014, 03:20:08 PM

Previous topic - Next topic

John Montenigro

OK Petrus,
Here's what I know so far:

From the VPE website http://www.idealsoftware.com/en/pdf-library/report-engine.html
I downloaded the Enhanced version (code letter = X), and installed it to its own folder.

I'm using the X version, so filenames are: vpeX...


The .INC is by Antonello Ventullo. I got it from message 1 of the PB Third Party Forum:
http://www.powerbasic.com/support/pbforums/showthread.php?t=43337



1. To avoid conflict with variable "rect", I added one compiler test to the .INC:

#IF NOT %DEF(%USE_JOSE_INCLUDES)    'jhm added this line (we KNOW this is defined by FF; refer to CODEGEN files)
   #IF NOT %DEF(%WINAPI)
      ' Private Window Messages Start Here:
      %WM_USER = &H400

      TYPE RECT
         nLeft AS LONG
         nTop AS LONG
         nRight AS LONG
         nBottom AS LONG
      END TYPE

      TYPE POINTAPI
         x AS LONG
         y AS LONG
      END TYPE
   #ENDIF
#ENDIF                                ' jhm: added


2. In the file "vpeX3260.INC", I changed all uses of "vpeX3260.dll" to "vpex3261.dll",
then saved it as "vpeX3261.INC"


3. In FF_AppStart, I added:
#INCLUDE "VpeX3261.inc"       ' VPE - Virtual Print Engine


4. In the FF form's CREATE code, I added:
   Local lRet As Long
   lRet = MakeVPEDoc(hWndForm)


5. And then I modified the VPE example (from the Programmer's Reference Manual) for PB/FF:

Function MakeVPEDoc(ByVal hWndParent As Dword) As Long

   Local hDoc As Dword
   
   hDoc = VpeOpenDoc(hWndParent, "Test", 0)
   VpeWriteBox(hDoc, 1, 1, 5, 1.5, "Hello World!")
   VpeLine(hDoc, 1.5, 3, 5, 6.5)
   VpeWriteDoc(hDoc, "hello world.pdf")
   VpePreviewDoc(hDoc, "", %VPE_SHOW_NORMAL)
   
   SetFocus hDoc     
   Function = 1       'someday, a real return value...

End Function


6. I put a copy of the vpex3261.DLL into my FF project's "\release" folder.

7. I found the ".CHM" help files and created desktop shortcuts, then also
  added them to the FF Help Tools menu.

8. Compiled and ran. When the VPE window is displayed, it is minimized and in the upper-left corner
of the screen. Easy to open and view, and in a few clicks to print and email! 

I think that should get you going.

Next, I'm going to read up on all the other commands, and how to place text, etc. Very exciting!

I have not attempted to do any other coding yet; I'm heading home now and will experiment some more tonight. I'll let you know if I have any major breakthroughs or insights.

-John



John Montenigro

Correction!!!

I mistakenly converted the "NULL" in their sample code to ""

Actually, that parameter refers to a RECT, so...

   Local r As Rect
   r.nLeft     = 5
   r.nTop      = 5
   r.nRight    = 800
   r.nBottom   = 600
       
   ...

   VpePreviewDoc(hDoc, r, %VPE_SHOW_NORMAL)
 


...more later...

-John

Petrus Vorster

Hey John

Good to see you are making progress.
Tell me, in this case does the receiver pc also need VPE to be installed?

Jose had a sample here somewhere where he creates documents on the fly with HTML and then creates a PDF.
Post us a few pics of documents you made with this please.

In the meantime i will try to get some samples of creating nice documents with HTML from FF/pb. Perhaps Jose can help out here.
(darn i dont have time. Work at day, study at night!)
-Regards
Peter

Knuth Konrad

Quote
Tell me, in this case does the receiver pc also need VPE to be installed?

If you create documents (files) in a standard format (i.e. PDF, HTML) through VPE, of course not. If you're developing an application which uses VPE: yes. Standard Win32 API DLLs.

John Montenigro

With regard to needing VPE on the "receiver" PC... I believe they provide a free, distributable viewer for their .VPE files.

Status update: I'm on a business project that has me very busy: work at day, AND work at night! So I'm only doing the VPE coding "when I can". My earlier attempt using Paul's suggestion of a GRAPHIC control with XPRINT is working satisfactorily for my immediate need, so my work with VPE is going to advance as is convenient to my schedule. Don't worry, I promise to return with code. In fact, here's some code that shows how I've been testing and experimenting.

   Local hDoc As Dword, r As Rect
   'Local VPE As otype

   'try setting a different opening position/size; remember them as "LTRB"
   r.nLeft     = 5       ' x1
   r.nTop      = 5       ' y1
   r.nRight    = 850     ' x2
   r.nBottom   = 500     ' y2
                     
   '!!!!!  from the sample program  !!!!!
   'VpeHandle hDoc = VpeOpenDoc(hWndParent, "Test", 0)
   hDoc = VpeOpenDoc(hWndParent, "CoC Creator - Preview, eMail, Print", 0)   'ok during development   
'hDoc = VpeOpenDoc(hWndParent, "CoC Creator - Preview, eMail, Print", %VPE_NO_RULERS)  ' rulers off , or on with 0

'set theme to Whidbey

   VPESetUnitTransformation (hDoc, %VUNIT_FACTOR_INCH)   'not originally in sample code; but I need to work in inches
   VpeSetRulersMeasure(hDoc, 1) ' sets rulers to INCHES with 1; to CM with 0
   
   VpeSetPenSize(hDoc, 0)      ' no frame drawn around the picture
   'place the logo
   VpePicture(hDoc, 1, 0.2, %VFREE, %VFREE, "D:\ProjFF\CoC_Creator\images\letterhead and logo.bmp") 'it's got a lot of space around it.   
'
'   'now try to center the logo
'   VpeRenderPicture(hDoc, %VFREE, %VFREE, MClogo & Chr$(0))
'   'VpeNoPen(hDoc)
''   VpePicture(hDoc, (VpeGetPageWidth(hDoc) - %VRenderWidth) / 2, (VpeGetPageHeight(hDoc) - %VRenderHeight) / 2, %VFREE, %VFREE, MClogo & Chr$(0))
'   VpePicture(hDoc, (VpeGetPageWidth(hDoc) - %VRenderWidth) / 2, %VFREE, %VFREE, %VFREE, MClogo & Chr$(0))
'this kinda works, but puts the logo way the heck out to the right, beyond the pages! zoom WAY out to see it!
                       
   'save the relative positions
   VpeStorePos(hDoc)
   
'SetFontControl()   
'SetFontSubstitution()
   VpeSetFontName(hDoc, "Times") ' & Chr$(0))
   VpeSetFontSize(hDoc, 18)
   VpeSetFontAttr(hDoc, %ALIGN_JUSTIFIED, %TRUE, %TRUE, %FALSE, %FALSE)

   'VpeWriteBox(hDoc, 4, 5, -10, -12, "Certificate of Conformance")
   'in line below, I tried using %VBOTTOM + 1 instead of absolute 5, but it displayed above the logo... (as if VBOTTOM was = 0)
   '  needed to StorePos() first!
   '
   'now to center the text...                                                                   
   VpeRenderWriteBox(hDoc, %VLEFTMARGIN, %VTOPMARGIN, %VRIGHTMARGIN, %VFREE, "Certificate of Conformance" )  '& Chr$(0))
   VpeNoPen(hDoc)
   'VpeWriteBox(hDoc, 5.5, %VBOTTOM, -20, -4, "Certificate of Conformance")      'still not aligning the way I want; use absolute values for now
   'VpeWriteBox(hDoc, 5.5, 5, -20, -4, "C e r t i f i c a t e   o f   C o n f o r m a n c e")  ' interesting effect, but not quite what I want...
   'VpeWriteBox(hDoc, 3, 5, -20, -4, "C e r t i f i c a t e   o f   C o n f o r m a n c e")
   VpeWriteBox(hDoc, 2, 1.8, -20, -4, "CERTIFICATE  OF  CONFORMANCE")
     
   'change to normal font:
   VpeSetFontAttr(hDoc, %ALIGN_LEFT, %False, %False, %False, %False)   
   VpeSetFontName(hDoc, "Arial" & Chr$(0))   'not sure if the zero termination is needed
   VpeSetFontSize(hDoc, 11)
   
   'set date         
   VpeWriteBox(hDoc, 6, 2.2, -2, -0.5, "Date: " & Date$)
   
   VpeWriteBox(hDoc, 2, 2.4, -4, -4, Repeat$(30, "whatever comes next "))
   
   VpeLine(hDoc, 1, 6, 7.5, 6)      ' horizontal line at 6" down...           
   
   'VpeWriteDoc(hDoc, "hello world.pdf")            ' VpePrintDoc() to printer
   'gCOC_SaveName = Exe.path$ & "CoC_" & Trim$(gCOC_values.OurInvoiceNumber) & ".pdf" ' change from exe.path to Std folder...PDFCreator uses MyDocuments
   gCOC_SaveName = "CoC_" & Trim$(gCOC_values.OurInvoiceNumber) & ".pdf" ' change from exe.path to Std folder...PDFCreator uses MyDocuments
   'VpeWriteDoc(hDoc, gCOC_SaveName)
   If Isfile(gCOC_SaveName) Then Kill gCOC_SaveName
   VpeWriteDoc(hDoc, "CoC_" & Trim$(gCOC_values.OurInvoiceNumber) & ".pdf")
   If Isfile(gCOC_SaveName) Then
'      ? gCOC_SaveName,,"Saved as PDF file"
   End If
   
   'VpePreviewDoc(hDoc, Null, %VPE_SHOW_NORMAL)
   'VpePreviewDoc(hDoc, $Nul, %VPE_SHOW_NORMAL)
'   VpePreviewDoc(hDoc, "", %VPE_SHOW_NORMAL)
   VpePreviewDoc(hDoc, r, %VPE_SHOW_NORMAL)
   '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

   'added by me for PB/FF functions
   SetFocus hDoc     
   Function = 1



I'm finding the VPE command set very powerful and easy to use, but I'm having some trouble understanding how to make all the relative positioning commands do what I want... So although I hate to use them, I'm testing with literal numbers. What I really want to do is create a system of variables that will make it easier to manage and maintain. I have a lot of thinking and design work to do...

BUT, back to my "real" work now.

-John

Knuth Konrad

Quote from: John Montenigro on February 25, 2014, 11:05:26 PM
[...] but I'm having some trouble understanding how to make all the relative positioning commands do what I want... So although I hate to use them, I'm testing with literal numbers. What I really want to do is create a system of variables that will make it easier to manage and maintain.

Make use of the functions return values (i.e. VpePicture returns the bottom right of the box) and or use VpeGet/VpeSet to keep track where the current "cursor position" is.

John Montenigro

Thanks, Knuth! I'll try that out in my next VPE coding session, probably over the weekend.
-John