GLBasic forum

Main forum => GLBasic - en => Topic started by: TI-994A on 2011-Jun-08

Title: Printing Support
Post by: TI-994A on 2011-Jun-08
Hello everyone. I would like to post a GLB-newbie question, if I may. The issue has been raised in this forum over the past few years, but with no definitive answer. So, my question is, does GLBasic support printer output at all? Or, are there any plans to implement this feature?

It seems that this one single feature is the only hindrance to making GLBasic an all-round programming tool; not just for games.

Your feedback will be really appreciated.

Thank you.
Title: Re: Printing Support
Post by: Moru on 2011-Jun-08
If I want to print something, I load up open office or some other tool made for printing. I don't expect a coding-tool to do any sort of (useful) printing... :-)
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-08
Quote from: Moru on 2011-Jun-08
If I want to print something, I load up open office or some other tool made for printing. I don't expect a coding-tool to do any sort of (useful) printing... :-)
Thanks for the quick reply; but please let me clarify.

I'm not referring to the IDE, but rather the programmability of printing functions, such as commercial applications printing out invoices, accounts, etc. GLBasic already has very powerful graphics output capabilities to the screen display. All that would be required is to transfer this same output, if not directly to the printer, at least to the OS Print Spooler/Manager.

Even if this may not be viable for the handheld platforms, it should be included for the desktop versions.
Title: Re: Printing Support
Post by: Moru on 2011-Jun-08
Oh yes, this I would like too. One thing I can see against it is that GLBasic is supposed to be multi-platform, what works on one platform we as users expect to work on all platforms.
Title: Re: Printing Support
Post by: matchy on 2011-Jun-08
I suppose printing support can extend to EPS or PDF files which can then be spooled on any platform, so there are probably libraries available to import/wrap.
Title: Re: Printing Support
Post by: spicypixel on 2011-Jun-08
Quote from: matchy on 2011-Jun-08
I suppose printing support can extend to EPS or PDF files which can then be spooled on any platform, so there are probably libraries available to import/wrap.

And how indeed would you access the saved pdf on an iPhone for example?
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-08
Quote from: Moru on 2011-Jun-08
Oh yes, this I would like too. One thing I can see against it is that GLBasic is supposed to be multi-platform, what works on one platform we as users expect to work on all platforms.
Cross-platform support is great, I don't deny that, but considering the hardware disparity between these platforms, an implementation of some platform-dependent commands should be acceptable. True cross-platform portability need not entail 100% line for line duplication; the differences in screen sizes between desktop and handhelds already require quite a bit of modification to the code, but the core structure is still portable.

As for printing, PureBasic supports Win32/64 and iOS, as well as Linux, with a set of versatile true cross-platform functions.

Why not GLBasic.
Title: Re: Printing Support
Post by: MrTAToad on 2011-Jun-08
Would depend on who really needs it - would it actually be worth Gernot spending time on ?
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-08
Quote from: MrTAToad on 2011-Jun-08
Would depend on who really needs it - would it actually be worth Gernot spending time on ?
There are a considerable number of VB coders out there getting fed-up with the dot-net luggage. Couple this with the demand for iPhone/iPad/iPod apps, GLBasic has got a niche in this market. But if it is seen only as a gaming platform, these defectors will shop around for the likes of PureBasic and NSBasic to fill their needs.

Currently PureBasic only supports desktop platforms, and NSBasic/AppStudio is standalone and doesn't compile to an iPhone native app using XCode, but rather only to a web app using the third party tool PhoneGap. They may all be BASIC in syntax, but the differences in the program structure and logic can be dauntingly different.

GLBasic, with its cross-platform portability, has the potential to corner this niche developer market. Pretty worthwhile.
Title: Re: Printing Support
Post by: MrTAToad on 2011-Jun-08
But only if printing commands are used - especially as it would be extremely tricky for mobile applications.  I believe only Windows CE has native support for that.
Title: Re: Printing Support
Post by: Kitty Hello on 2011-Jun-08
There's 2 very easy ways to do it.

1st: Write a temp HTML file with optional PNG images and call a webbrowser to print it (OK, you must make that platform specific, but only 3 platforms, right?)

2nd: Write an RTF file (a bit harder but gives very accurate control of everything. It's a WORD doc in ASCII so to say. Use Wordpad to get started with the format.
Title: Re: Printing Support
Post by: Slydog on 2011-Jun-08
Or, if you don't like easy, I have a hard way to do it!
Wrap GLB functions around the Win32 printing API calls.
Here's two links from a Google search:

How To Send Raw Data to a Printer Using the Win32 API from Visual Basic
http://support.microsoft.com/kb/154078 (http://support.microsoft.com/kb/154078)

Win32 API and Printers: Print Directly to a Printer
http://www.thedbcommunity.com/index.php?option=com_content&task=view&id=226&Itemid=44 (http://www.thedbcommunity.com/index.php?option=com_content&task=view&id=226&Itemid=44)

You'd have to convert the examples to GLB and/or INLINE C.
But, this would give you full printing control (Windows only of course) without any limitations.
Title: Re: Printing Support
Post by: matchy on 2011-Jun-09
Generally, I really get annoyed when the first post is an impression on a "how to" but turns in to a marketing and political argument about the pros and cons of GLB because suggestions are not satisfactory or trigger cause for debate.  :rant:

Quote from: spicypixel on 2011-Jun-08
And how indeed would you access the saved pdf on an iPhone for example?
Is that a trick question?  O_O Just load any file from where it was saved, i.e. the documents folder which has read/write access.
Title: Re: Printing Support
Post by: spicypixel on 2011-Jun-09
Quote from: matchy on 2011-Jun-09
Quote from: spicypixel on 2011-Jun-08
And how indeed would you access the saved pdf on an iPhone for example?
Is that a trick question?  O_O Just load any file from where it was saved, i.e. the documents folder which has read/write access.

No I meant you can indeed access the Documents folder to the PDF file within GLB for read/write access but you can't access the PDF to transfer it to a PC for printing without 3rd party software can you? Ideally to work on all devices/PC's it would be best to save as a HTML file which can easily be output with formatting control from GLB and if it's a desktop machine simply save it, and if it's a mobile device send it wirelessly to a connected desktop PC. This allows printing effectively from any device so long as it has connectivity.
Title: Re: Printing Support
Post by: Kitty Hello on 2011-Jun-09
You can enable document sharing for your app in XCode. When you plug into iTunes then, you can drag/drop documents from/to the app's documents directory. I have not done that myself, but I'm quite sure it works.
Title: Re: Printing Support
Post by: spicypixel on 2011-Jun-09
Interesting =)
Title: Re: Printing Support
Post by: matchy on 2011-Jun-09
Good! HTML to OS browser would be my first quick and easy choice. Problem solved! Tea and scones anyone?
Title: Re: Printing Support
Post by: ampos on 2011-Jun-09
On my TPV proam done in Blitz3D, I use this system to print (pseudo-code):

Code (glbasic) Select
OPENOUT 1,"ticket.txt"
PRINT #1,texts$
CLOSEFILE 1
EXEC "print.bat"


and the print.bat file has:

Code (glbasic) Select
type ticket.txt >lpt1
Title: Re: Printing Support
Post by: Kitty Hello on 2011-Jun-09
Nah. Just call InternetExplorer with an HTML file and "/P" in the parameter list.
Or Wordpad (write.exe) on any windows.
Title: Re: Printing Support
Post by: ampos on 2011-Jun-09
It would be nice to know... 5 years ago :)

I have been using this since I did my first TPV program looooong ago in TurboBasic.
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-10
Quote from: Kitty Hello on 2011-Jun-08
There's 2 very easy ways to do it.

1st: Write a temp HTML file with optional PNG images and call a webbrowser to print it (OK, you must make that platform specific, but only 3 platforms, right?)

2nd: Write an RTF file (a bit harder but gives very accurate control of everything. It's a WORD doc in ASCII so to say. Use Wordpad to get started with the format.
Not very preferable workarounds, ruling out WYSIWYG formatting. The API option would seem to be the only solution, but is there an equivalent call for OSX?
Title: Re: Printing Support
Post by: Slydog on 2011-Jun-10
You could write the equivalent code for OSX using GLB wrappers probably.
Here's some OSX printing info:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Printing/Printing.html

Or, this may be more difficult and not what you want, but you can create PDFs from code using Adobe SDK.
This will give you pixel perfect control of the final document, but wont print it for you.
I don't know how this is done or how hard it would be to do through GLB but nothing is impossible.
http://www.adobe.com/devnet/pdf/library.html
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-10
Quote from: Slydog on 2011-Jun-10
You could write the equivalent code for OSX using GLB wrappers probably.
Here's some OSX printing info:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Printing/Printing.html

Or, this may be more difficult and not what you want, but you can create PDFs from code using Adobe SDK.
This will give you pixel perfect control of the final document, but wont print it for you.
I don't know how this is done or how hard it would be to do through GLB but nothing is impossible.
http://www.adobe.com/devnet/pdf/library.html
Thanks for the info; will give it a try.
Title: Re: Printing Support
Post by: Moru on 2011-Jun-10
But what do you want to print with bitmap fonts? :-)
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-11
Quote from: Moru on 2011-Jun-10
But what do you want to print with bitmap fonts? :-)
My font of preference would be TrueType, not bitmap. In VB, these fonts can be placed in a LOGFONT structure and drawn with precise positioning and scalability using the CREATEFONT and DRAWTEXT functions. Even images can be positioned and scaled with similar precision using functions like CREATEBMP and BITBLT / STRETCHBLT.

When printing functions are relegated to HTML or RTF output, format control is lost.
Title: Re: Printing Support
Post by: Moru on 2011-Jun-11
But GLBasic only has bitmap fonts what I know of.
Title: Re: Printing Support
Post by: Moebius on 2011-Jun-11
Save as png, print that.  Full control using GLB's commands.   :enc:

GLB is designed really for games, and VB is intended for applications.  Unfortunately, you can't expect to find all the features of one programming language in another.  That said, compare how complex it is to have 3D - or even 2D - graphics in VB as opposed to GLB...
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-11
Quote from: Serpent on 2011-Jun-11
Save as png, print that.  Full control using GLB's commands.   :enc:

GLB is designed really for games, and VB is intended for applications.  Unfortunately, you can't expect to find all the features of one programming language in another.  That said, compare how complex it is to have 3D - or even 2D - graphics in VB as opposed to GLB...
Can GLB print PNG files?

The functions indicated in the previous post (CREATEFONT / DRAWTEXT / BITBLT / etc) are not native VB commands, but rather a subset of the Win32 API. GLBasic can also call and use these functions; the only difference is, with VB these routines can be done in BASIC, while in GLBasic they have to be coded through inline C/C++.

And it's true that VB isn't well suited for extensive graphics programming, which is yet another reason why VB isn't a tool of choice. However, to say that such a powerful cross-compiler like GLBasic should be considered specifically for game development, is selling it short. PureBasic also handles 2D/3D graphics with similar ease, and it is pretty much an all-round development tool. But with the mobile platform support (WinCE / iPhone / etc), GLBasic has a clear advantage.

Considering all these points, expecting native printing support within GLBasic shouldn't be too much to ask.
Title: Re: Printing Support
Post by: Kitty Hello on 2011-Jun-20
RTF is a file format pretty close to wysiwyg. Also, I found out that PDF files are pretty simple text files as well. Pasting a PNG file within a pdf might not be too complicated. That would be worth a try.
Title: Re: Printing Support
Post by: TI-994A on 2011-Jun-21
Quote from: Kitty Hello on 2011-Jun-20
RTF is a file format pretty close to wysiwyg. Also, I found out that PDF files are pretty simple text files as well. Pasting a PNG file within a pdf might not be too complicated. That would be worth a try.
Thank you, and you're right; the RTF format does produce close to WYSIWYG output, so this is worth looking into. However, the actual printing is still delegated to an external application, assumedly through their command line switches.

Once again, thank you, and to all who have enthusiastically given their suggestions.
Title: Re: Printing Support
Post by: mrplant on 2013-Aug-17
Is there a quick and dirty way - say a function I could write - that when called at anytime would save off everything on the current screen to say a .png file for later printing?
Title: Re: Printing Support
Post by: Schranz0r on 2013-Aug-17
A screenshot function ?!
Title: Re: Printing Support
Post by: kanonet on 2013-Aug-17
Does SAVEBMP do the job?