CD Print And Preview

Share your advanced PureBasic knowledge/code with the community.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

CD Print And Preview

Post by collectordave »

Hi All

After learning a little more about PB and printing decided to recreate the print and preview module.

I needed a couple of things.

1. The ability to print in landscape and\or portrait depending on what I wish to print and whatever the user selects from the print requester on a page by page basis.

2. The ability to print whatever on whatever the user selected.

3. To give the user the ability to choose which pages to print after a preview or not.

This new module is based on the printrequester() and after selection the printer information is stored and is available in the main programme.

New pages are added as required with a flag to indicate the required orientation of the printed page.

Vector drawing commands are used throughout to do the actual printing to maintain quality.

This works by creating a Printjob directory and file, then each command used to print is stored in the file. After all print operations are complete the user is shown a preview of the print if selected when opening the print job. On the preview window is a Print button. Clicking this displays the Print Which pages dialog where All pages can be selected or a range entered or a list of individual pages can be entered. Clicking the Ok button will then print the selected pages.

Opening a print job with no preview does exactly the same but no preview window is displayed and the module runs straight into the print which pages dialog.

The test programme in cluded simply prints three pages. Page 1 a box and a line, Page 2 some text and Page 3 an image. To test run the programme select your printer and print. Whichever orientation you choose on the printer the output will be the same this is deliberate. The chosen orientation is only used for the preview window and shows how the pages will be printed.

All native Purebasic commands used throughout just need a little help getting the printer info for all operating systems, Windows is done.

The code and test programme can be found here:-https://github.com/collectordave/PureBa ... nd-Preview

If anyone can test and suggest improvements at this stage I will be gratefull.

I will be adding more commands as I go along and develop some little test programmes such as printing a text file, grids or photos.

Update: 6 Feb 2017

Courtesy of infratec there is now a single file which holds the module and a simple test programme so rather than visiting github to download it all you can download the single file from dropbox herehttps://www.dropbox.com/s/m42wkcmk0s7o3 ... er.pb?dl=0

Update: 10 Feb 2017

In some circumstances printing images could get a little confused depedant on the calling programme. All image printing routines now updated.

Small PDF manual now part of the download. Also available here :- https://www.dropbox.com/s/b3lbilsp10fd5 ... t.pdf?dl=0 If anyone can offer suggestions for improvement they will be gratefully recieved.

Kind Regards

cd
Last edited by collectordave on Fri Feb 10, 2017 7:16 am, edited 2 times in total.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CD Print And Preview

Post by infratec »

Hi,

why you don't use the posibility to hold the sqlite database in memory :?:

Code: Select all

DB = OpenDatabase(#PB_Any, ":memory:", "", "", #PB_Database_SQLite)
It's faster, you don't have to delete or check for the file ...

After CloseDatabase() everything is released.

Bernd
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CD Print And Preview

Post by collectordave »

Hi infratec

Honestly did not think about holding it in memory, however i am also looking at the possibility of sceheduled printing to allow a document to be printed at one time to be sent to the printer later. However I will add the memory database now.

Could have another switch in place if the user wants to schedule a print operation. Like the idea of memory though easier on the programming skills.

Thanks for the suggestion and code.

Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CD Print And Preview

Post by collectordave »

Hi All

Code updated with infratec's suggestion above same link as above.

Seems to work one heck of a lot faster!

Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CD Print And Preview

Post by infratec »

Hm....

with SQLite you have the chance to write it simply to disk.

http://www.forums.purebasic.com/english ... p?p=368143

But after I look a bit deeper in the code...
why you didn't use 2 lists and/or maps?
Maybe a map with the pagenumber as key and the page data in a structure plus a list inside with the content.
So it's possible to search for the page and then run through the content.

This would reduce the exe size by 250kb.
Ok, a bit old school to try to keep the code small.

I think this would be even more faster then the DB in memory.

But that's only an idea.

Bernd
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CD Print And Preview

Post by infratec »

Hi,

you can comment out line 572-574 in CDPrint.pbi

But .... you'll run into trouble:

You ignored the golden rule: only one eventloop per program.
Sooner or later you'll run into big problems.

Try to use the bind stuff to eliminate the eventloop in ShowPreview.

Bernd
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CD Print And Preview

Post by collectordave »

Hi All

Just a little news.

All infratec's improvements have now been included. Thanks to infratec for just about reprogramming the whole thing. Not in the link yet as I wish to give infratec credit in the code header etc so once infratec approves I will update github and post here.

Thanks for your improvements infratec! 8)

Also added print and preview to the photoDB here http://www.purebasic.fr/english/viewtop ... 27&t=67375 again not updated on github but will do ASAP. This only took about fifteen minutes!

Kind Regards To All

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CD Print And Preview

Post by collectordave »

Lots more improvements courtesy of infratec all included no database now, all in memory printimagefromfile() added and print canvas(). Colour now supported as well.

Both new procedures included in test programme.

The main link in the first post now updated.

Only tested on windows 7 so far, so if anybody does download and test please let us know here.

Thanks to infratec

Kind Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CD Print And Preview

Post by collectordave »

Print functionality added to two apps;

Basic text editor here http://www.purebasic.fr/english/posting ... 22&t=66577

and the photo database available here http://www.purebasic.fr/english/viewtop ... 27&t=67375

Both using the CDPrint module. Should be good examples of usage.

I am still printerless so if anyone can download and test these then please let me know how you get on.

Kind Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: CD Print And Preview

Post by Keya »

collectordave wrote:I am still printerless so if anyone can download and test these then please let me know how you get on.
you can get printer drivers that print to image files like bmp instead of physical printer, but i dont know any offhand so your google is as good as mine
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: CD Print And Preview

Post by collectordave »

Thanks keya.

Had one responce that it works ok to FreePDF on windows 10. So will look further into this and find one until I achieve the ability to print again.

Thanks again

Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: CD Print And Preview

Post by Keya »

let us know if you find a good one! wouldn't mind saving some A4 myself hehe. its just a lot quicker for testing too
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: CD Print And Preview

Post by Fangbeast »

I'm using Foxit PDF reader/printer rather than wasting paper. So far, I have generated 58 documents adjusting the printing for one project. Could not have afforded to waste that much in real paper!
Amateur Radio, D-STAR/VK3HAF
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: CD Print And Preview

Post by Keya »

Fangbeast wrote:Could not have afforded to waste that much in real paper!
ink's a bit of a ripoff too :P
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: CD Print And Preview

Post by TI-994A »

Keya wrote:
Fangbeast wrote:ink's a bit of a ripoff too :P
For the times when we do need hardcopy testing, get a cheap, or even second hand inkjet, and stock up on third-party refills. Big savings. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply