Silent Printing with TideSDK - printing

UPDATE: I've decided to use appjs for my project, rather than TideSDK. With AppJS, you are able to easily make node modules, in which you can add C++ modules for easy use of silent printing. I'd recommend anyone interested in the topic to check it out. Best of luck to you all!
I'm developing an application with TideSDK - It's a really awesome framework, if you haven't tried it, set some time aside!
Anyway, I'm attempting to print using Javascript, but a Print Settings dialog comes up each time, as it would with other browsers. I'm trying to eliminate that box as well as pass along the printer I would like it to print with.
I'm aware that there are settings in FireFox for silent printing, that is was I used previously, but there aren't any similar options for TideSDK (That I have found).
After a ton of research, I think the only viable options consist of a python script, a C++ module or editing the TideSDK source and recompiling. All three sound like loosers to me. Modifying the TideSDK source and removing the dialog box from webkit_ui_delegate.cpp will most likely result in some issues when updating this program down the road - in addition to not being able to pass the printer name easily. The python script would require third party modules and would have to process the contents of the page, I doubt I would be able to write something that could do a quality job in that respect. Finally, I think the C++ solution is the most feasible since it has access to win32api, but again, it would have to process HTML to a print language, something i'm not familiar with. I guess i'm looking for more of a webkit solution that handles the rendering for me.
What should I do to implement silent printing on TideSDK? Please include code examples.
I'm looking for a windows solution primarily, I've already figured out
the other platforms.
Thank you for your time and I appreciate the feedback!

NOTE: this is a rewrite of an earlier question.
The way Windows/GDI+ printing works is that it uses a PrintDialog to obtain a printer identifier (and to also let the user know what printer they are printing to). So in order to have silent printing, you need to obtain a printer identifier without showing a dialog.
So REMOVE this code:
// Open a printing dialog to fetch the HDC of the desired printer.
PRINTDLG dialog;
ZeroMemory(&dialog, sizeof(PRINTDLG));
dialog.lStructSize = sizeof(PRINTDLG);
dialog.Flags = PD_PRINTSETUP | PD_RETURNDC;
BOOL dialogResult = ::PrintDlg(&dialog);
if (!dialogResult) // Error or cancel.
{
DWORD reason = CommDlgExtendedError();
if (!reason) // User cancelled.
return S_OK;
logger->Error("Could not print page, dialog error code: %i",
reason);
return E_FAIL;
}
HDC hdc = dialog.hDC;
And then replace the last line (HDC hdc = ...) with some other way of getting a printer HDC. You could use GetDefaultPrinter() to get the name of the default printer, and then get a HDC using CreateDC().
Optionally, you could select a printer or create a custom print dialog using the EnumPrinters() function.

Sad to see this question didn't get any quality answers, this is something I wanted to implement myself.
I think it would be quite a venture to invest the time required to get this feature working with TideSDK. Because of that, I'm going to stray away from the core competencies of the question and recommend that you try a framework other than TideSDK to accomplish this. I think that is the most realistic solution to this problem, and it will be the one that I take.
I'll update this answer once I find the framework I'll be sticking with.

Related

How to create a fake printer driver to pass print file to real printer

I want to know how to make an application that will emulate a printer with a specific name ("SLP Pro" in my case), and with only ony type of paper ("SLP-SRL Shipping(54x101mm)" in my case).
My goal is to receive print files (I have no idea what type they are, they are from a very old program), and redirect them to a label printer. The problem is that I want my application to only redirect the first page, and nothing else, from the original print file.
My question is following this one: Limit to 1 page all document sent to printer
(It's the same problem as described there, only I have tried all possibilities I had with my current driver for my label printer)
I know there is http://www.colorpilot.com/emfprinterpilot.html and www.printerplusplus.com, but I really don't know how to use them. Can those solutions handle print files that are not from known application like Word ? (The first one seem to take the file with the extention and redirect it, I really want to take the print file and crop it to only one page)
If my question is too vague, can you please tell me where I can find the good information ? I've found many things that to things a bit like I want to do, but they where not applicable to my situation, and I really don't know where to search now...

Programming screen recorder - output issues

I want record screen (by capturing 15 screenshots per second). This part I know how to do. But I don't know how to write this to some popular video format. Best option which I found is write frames to separated PNG files and use commandline Mencoder which can convert them to many output formats. But maybe someone have another idea?
Requirements:
Must be multi-platform solutions (I'm using Free Pascal / Lazarus). Windows, Linux, MacOS
Exists some librarys for that?
Could be complex commandline application which record screen for me too, but I must have possibility to edit frames before converting whole raw data to popular video format
All materials which could give me some idea are appreciated. API, librarys, anything even in other languages than FPC (I would try rewrite it or find some equivalent)
I considered also writting frames to video RAW format and then use Mencoder (he can handle it) or other solution, but can't find any API/doc for video RAW data
Regards
Argalatyr mentioned ffmpeg already.
There are two ways that you can get that to work:
By spawning an new process. All you have to do is prepare the right input (could be a series of jpeg images for example), and the right commandline parameters. After that you just call ffmpeg.exe and wait for it to finish.
ffmpeg makes use of some dll's that do the actual work. You can use those dll's directly from within your Delphi application. It's a bit more work, because it's more low-level, but in the end it'll give you a finer control over what happens, and what you show the user while you're processing.
Here are some solutions to check out:
FFVCL Commercial. Actually looks quite good, but I was too greedy to spend money on this.
Open Source Delphi headers for FFMpeg. I've tried it, but I never managed to get it to work.
I ended up pulling the DLL wrappers from an open source karaoke program (UltraStar Deluxe). I had to remove some dependencies, but in the end it worked like a charm. The relevant (pascal) code can be found here:
http://ultrastardx.svn.sourceforge.net/viewvc/ultrastardx/trunk/src/lib/ffmpeg-0.10/
There was some earlier discussion with a Delphi component here. It's a very simple component that sometimes generates some weird movies. Maybe a start.

Typing code using a BlackBerry?

Is a BlackBerry feasible for writing code with?
Additionally: Are there some programming languages which are specially easy or hard to type on it's keyboard?
I don't know BB well, but I'm trying to evaluate it for writing code while commuting. AFAIK, it doesn't have a "full-featured" keybard, and there are other phones with a more complete one. But I'd also like to be able to write text single-handedly, and I believe it's possible on a BB (?).
Note: that's not a question about writing code for a BlackBerry, but rather on one.
(If that's not a good site for such a question, please let me know where could I pose it. I've let myself put it here based on the "matters that are unique to the programming profession" entry in the FAQ.)
No. Consider a netbook if you need something cheap you can write code with on-the-go. I've tried too, but mobile phones (no matter how smart they are) can't be used for writing code (unless you're willing to spend 1 hour to write a "Hello, World!" app).

Printing from web pages (reports especially) with greater precision

I am re-engineering a windows application to be ported to web. One area that has been worrying is 'printing'.
The application is data intensive and complex reports need to be generated. The erstwhile windows application takes advantage of printer APIs and extends sophisticated control to the users. It supports functions like page break, avoiding printing on printed parts of the sheet (like letterhead), choice of layouts and orientation, etc. Please note that these setting are not done only while printing, they are part of report definition sometimes.
From what I know, we cannot have this kind of control while printing web pages. I am in a process of identifying options at my disposal. While I prefer to first look into something that will help me print from raw web pages, following are other thoughts:
Since reports can also be exported to .xls & .pdf versions, let user download one and print directly. This however limits my solution to the area of application that have export feature.
Use Silverlight (4.0) for report layout definition and print. I think Silverlight 4.0 (in beta right now) provides adequate control over the printer. I have so far been avoiding the need of any RIA plugin.
Meticulously generate reports on web with fixed dimensions. I am not sure how far this will go.
Please share practices that can be applied easily in my scenario.
For reporting in the past on the web, using .NET, I like to generate PDF, Excel, Word or CSV files. I really like iTextSharp which allows for creating of PDF's.
Word can accept HTML, so that is usually quote easy. For more control you can get into the Word interops http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/, but they left me frustrated. Not for implementation, but I felt the clean up was poor.
CSV are great for raw data dumps and that is it.
For HTML, you can get nice control using a style sheet targeted to print media. There are just certain things you cannot control, like browser header and footer.
Flash also has better print controls than plain HTML, though you might not know it since these features are rarely used by flash developers. Almost everyone should have Flash installed these days, so it's not like Silverlight where there's a good chance of someone needing to install a plugin (doubly so for a beta version). I am not sure how the Flash printer APIs compare to Silverlight's printer APIs and if they give you the level of control you need, but their documentation is public so you can look into it.
Also I think exporting to PDF is a good idea. I don't see why you can't extend this to cover all places that would need to print a report. Basically instead of printing directly from the windows app running on their desktop, the same exact code runs on your server and generates a PDF that they can then print themselves.
I don't think you're going to have much luck trying to do it with raw HTML unfortunately. For one of our clients, we went with the "generate PDF" route and it worked out quite well. PDFs have the additional advantage that you don't have to print them out: you can just email them to the boss/accountant/whatever saving a bit of paper.
PDF is the way to go, if you want absolute control over printed output. As bonus, you can also provide the option to download PDFs in your application.
With HTML, you are at the mercy of user's browser settings for page size, margin and how page breaks will be handled.

Delphi printing primer

I need to add printing capabilities to an app and I have been looking around for information about printing. Logical/physical sizes, dpi, font scaling, etc, lots to digest since I never programmed printing into any app before.
Are there any sites that would offer a primer on the topics of page sizes, margins and all the other elements required to understand printing on Windows? I've been looking around for a while but what I find is either cryptic or years old...
I've been playing around with TPrinter, but I would like to build solid printing functionalities and understand what I'm doing better.
Using a report solution is not an option, even though I'm sure it would provide better results much sooner.
Two links to get you started:
Printing with TPrinter
Printing via the TPrinter Canvas
I think that you are looking too lowlevel.
Try looking at the build reporting tools (Rave or whatever is in your product).
Personally i am using a product called Report Builder from Digital Metaphors.
But if you want to do the lowlevel stuff lot og good information can be found at efg's computer lab - printing
Well, I have done things a variety of ways in the past, including the "hard way" with TPrinter. In fact, I recently had to do that again to run a special inventory label printer.
On the other hand, sometimes you are better off taking work others have done and using it for your benefit. I agree that ReportSmith isn't so great, and also it's Delphi (and Windows) specific. Using Excel or Word has those limitations, plus the fact that the user has to actually have them installed.
One thing I have done to make printing easy for some simple applications is just to generate an HTML file and call the user's web browser, then they can print it. HTML tables can be created relatively easily for numerical data, and you can include photos, etc. as well. This works well for some applications, and works on every platform where a web browser is installed. The downside, of course, is that HTML isn't the most precise layout language.
The version of Delphi you´re using is important. A number of Delphis came with print engines like ReportSmith (ugh). Another option thinking laterally is to use MS Word as a print engine. I´ve hooked into instances of Word & Excel before & utilised their functionality. As to raw printing using TPrinter or the print method of TForm you´d have to be pretty desperate. I seem to recall the Pacheo / Texeira Delphi books coming with a pretty good overview so you might want to see if you can find a copy of that somewhere.

Resources