Page 1 of 1

VecVi - Create and output documents using VectorDrawing lib

Posted: Tue Dec 19, 2017 8:13 pm
by Andesdaf
Hi,

I've written this for another project where I needed a print preview and some advances features for creating documents (and later print them or save them to pdf) like automatic page breaks, headers, footers etc.

Main features:
  • creating a document once and later output it to CanvasGadet, Window, Image, printer, pdf or svg
  • text and image cells with custom border, filling, text alignment, font etc.
  • horizontal, vertical and free lines
  • rectangles, curves, ellipses and ellipse segments
  • auto-invoked headers and footers, for the whole document or for a single page
  • auto page breaks
  • avoiding page breaks within connected element blocks
  • auto page numbers with free start value, excluding of pages from numbering, total number of pages etc.
  • possibility to display the document as single pages or as a list of pages (for print preview, see example code)
code: https://raw.githubusercontent.com/hgzh/ ... r/VecVi.pb
example: https://raw.githubusercontent.com/hgzh/ ... preview.pb

Image

Re: VecVi - Create and output documents using VectorDrawing

Posted: Wed Dec 20, 2017 4:36 am
by collectordave
Nice work.

Did you try

http://www.purebasic.fr/english/viewtop ... 12&t=67703

The purePDF module on the forum can also be used to create PDF documents on windows systems.

Regards

CD

Re: VecVi - Create and output documents using VectorDrawing

Posted: Thu Dec 21, 2017 6:05 pm
by Kwai chang caine
Thanks a lot for sharing this great code 8)
Works fine here W7 x86 / V5.61 x86

Re: VecVi - Create and output documents using VectorDrawing

Posted: Sat Dec 23, 2017 12:02 am
by Andre
Very interesting! Runs fine here on Win10, thank you :D

Re: VecVi - Create and output documents using VectorDrawing

Posted: Fri Feb 01, 2019 6:22 pm
by Andesdaf
After a long time, I uploaded a new version with some smaller bug fixes and
a new output channel (image on canvas) to improve performance.

I've also written a fork of VecVi that uses PurePDF to create pdf files on windows,
if someone is interested in this, I can publish it, too.

Re: VecVi - Create and output documents using VectorDrawing

Posted: Fri Feb 01, 2019 7:20 pm
by skywalk
This has potential as a Report Generator. 8)
Not sure why pdf would not work on Windows?
This version does not have a save to pdf option?
v.1.06 (2019-01-31)

Re: VecVi - Create and output documents using VectorDrawing

Posted: Sat Feb 02, 2019 7:41 pm
by CELTIC88
very good project, thank you for sharing :D
 

Re: VecVi - Create and output documents using VectorDrawing

Posted: Sat Feb 02, 2019 8:21 pm
by Andesdaf
skywalk wrote:Not sure why pdf would not work on Windows?
I use PB's PdfVectorOutput() which is not supported on Windows. On Linux and MacOS,
you can use VecVi::OutputPDF(). For PDF output on Windows, there is the fork with
PurePDF usage mentioned in my previous post.

Re: VecVi - Create and output documents using VectorDrawing

Posted: Fri Jul 24, 2020 5:21 pm
by Andesdaf
Updated to v.1.10, mainly for improving the performance of the print preview with larger data.
Now only the elements that need to be displayed will be calculated before. In addition some
minor improvements, clarifications and bugfixes.

Code: Select all

;   v.1.10 (2020-07-24)
;    - completely reworked processing and drawing engine
;    - added Process()
;    - added GetBackColor() / SetBackColor()
;    - added reset possibility to SetFillColor(), SetTextColor(),
;      SetLineColor(), SetLineStyle()
;    - renamed *Page*() commands to *Section*() for clarification
;    - renamed GetRealPageCount() to GetPageCount()
;    - renamed GetRealPageStartOffset() to GetPageStartOffset()
;    - renamed *SinglePageOutput() commands to *MultiPageOutput()
;    - fixed bug in GetLineStyle()
;    - fixed various bugs in processing and drawing engine
;    - drawing of bigger documents is now much faster
Versions with PurePDF and pbPDF implementation (on Windows without PDF support) also available
https://raw.githubusercontent.com/hgzh/ ... PurePDF.pb
https://raw.githubusercontent.com/hgzh/ ... i_pbPDF.pb

Re: VecVi - Create and output documents using VectorDrawing lib

Posted: Tue Apr 02, 2024 5:40 pm
by Andesdaf
Thanks to PB 6.10, there is, beginning with v.1.13, direct pdf and svg output support for Windows, too. The PurePDF and pbPDF versions of VecVi won't get updated anymore.

Code: Select all

;   v.1.11 (2022-10-11)
;    - fixed bug with pagebreak and x position reset
;   v.1.12 (2023-10-10)
;    - fixed bug causing crash when section is empty
;   v.1.13 (2024-04-02)
;    - added DuplicateSection(), DuplicateBlock()
;    - added OutputPDF()/OutputSVG() support for all OS
;    - changed OutputSVG() to require a page for output
;    - changed BeginSection() and BeginBlock() to return a handle
;      of the created section or block
;    - fixed bugs with OutputPDF() and OutputSVG()
;    - fixed another bug causing crash if section is empty
;    - removed CanvasImage output

Re: VecVi - Create and output documents using VectorDrawing lib

Posted: Wed Apr 03, 2024 7:39 am
by infratec
Btw.:

The pattern for your OpenFileRequesters are wrong. It should look like "PDF|*.pdf"

And If I cancel the PDF output requester it results in an IMA.
You should check the return values and also check if the output file was created before using RunProgram().

Example:

Code: Select all

Procedure pdfDocument()
  Protected.s zFile
    
  zFile = OpenFileRequester("PDF-Ausgabe", GetTemporaryDirectory(), "PDF|*.pdf", 0)
  If zFile
    VecVi::OutputPDF(*VecVi, zFile + ".pdf")
    If FileSize(zFile + ".pdf") > 0
      RunProgram(zFile + ".pdf")
    EndIf
  EndIf
  
EndProcedure
You can simplify this when your own procedures uses also return values.

Re: VecVi - Create and output documents using VectorDrawing lib

Posted: Wed Apr 03, 2024 10:52 am
by Andesdaf
Yes, the example linked is also my quick&dirty test code so it could use a rework.

Regarding the return values I'm not sure in which cases StartVectorDrawing() returns zero and if it is reliable enough to assume that the file really exists. But I could at least pass trough its return value to have kind of an indication.

// EDIT: now done, also updated and extended the example

Code: Select all

;   v.1.14 (2024-04-04)
;    - changed the output functions to have a return value
;      indicating output success
;    - fixed bugs with DuplicateBlock() and DuplicateSection()