Creating a virtual printer as an interface for a document management system - delphi

I would like to know if the following idea is possible/makes sense?
Create a virtual printer (like "PDF Printer" that any application with printing capabilities can see in the printers list) that doesn't print to paper or file, but simply inserts the document "being printed" in the document management system (DMS) I developed. Imagine from MSWord i choose "MyPrinter" and on "print" my custom forms appear and let the user choose where to save the doc file inside my DMS, letting the user set some parameters (related to my DMS).
So after these "forms" I have all the data needed to insert the file in the DMS.
I am aware this is somehow "in the tricks domain" but it is the only choice to integrate my app with some legacy software (with printing capability) that cannot be repalced.
I'd like to have a comment on this.

Creating a virtual printer is a very technical task. You will have to write a device driver, which is not directly possible with Delphi (even if there are some code in the Net).
There are several components able to do this: they consist in an already developed printer driver, with some general API to be called from other languages, including Delphi.
I found out that EMFPrinterPilot from ColorPilot could be a good start. Your Delphi application may be able to retrieve the Text (for indexing), PDF (for archiving) and even EMF (for display / reprint).

Related

Zebra 105SL (Plus) 2-way communications

I have written a printing application that works well. I can write files, update settings and do most all functionality from one console. But one aspect of the program has eluded me for quite a while: the ability to read the Zebra register/configuration values.
It would be good to periodically be able to read the values on the Zebra and compare them to default known good standards and to be able to reset them if necessary.
Currently, in order to see these values, I need to either use the built-in web page (networked printers only), print a report, or scroll through the printer interface. What I really need to is a method to be able to read these registers values and create a known good setup file.
Has anyone been able to find any SDK or trick to read these values using .NET (C# or vb.Net)?
The application is a windows desktop utility used on my shop floor and I communicate with the printers using either LPT and ethernet interfaces (as applicable).
I would recommend checking out the Zebra Link-OS SDK which has a lot of functionality when it comes to what you can do with Zebra printers. Specifically they have a section titled "Getting all printer settings and their configuration". However the code example they provide will not work unless your printer is a Link-OS enabled printer. If that happens to be the case then great! If not you can use the SGD class within the Zebra.SDK.Printer namespace to use Set-Get-Do commands to retrieve and change information. More information on SGD can be found in this ZPL manual under the SGD Printer Commands section.

How to get the property list and values of a control within a third-party Delphi application?

I'd like to get information about a third party application's controls such as a list of its properties and their values: something like RTTI information but for a third-party Delphi application.
I see that this is possible. For example TestComplete has the ObjectSpy window which can give many useful information about the control, including RTTI information. How can this be done ?
Edit: To explain why I'm investigating this issue... I'm a registered user of TestComplete/TestExecute and I do like... most of it. I can get over the minor things but the one major problem for me is their license verification system which requires me to have a physical computer (not a virtual machine) always on just for the sake of running a license server so that TestExecute can run at night. As I have basic testing needs (compare screenshots and check basic Delphi component's properties) I wondered how hard it would be to make my own private very simple "TestExecute-like" application.
To go further, I suggest you these relevant resources found here on SO
Writing a very basic debugger (The accepted answer along with its comment thread are all valuable).
Is it possible to access memory from an application to another ? How? (Excerpt from the accepted answer: It is possible. Just use the Windows API functions WriteProcessMemory/ReadProcessMemory. Pass in the handle of the process and the pointer to the data).
Search the memory of another process (The excellent accepted answer also forwards to another valuable resource delphi-code-coverage by Christer Fahlgren and Nick Ring).
StackWalk of other process in delphi? (Check Barry Kelly's answer !!!, the same for the one from the AsmProfiler author !!!).
I strongly suggest you to port to Delphi this c++ project entitled Get Process Info with NtQueryInformationProcess: A hands on experience on using ReadProcessMemory to access the CommandLine used to launch another process.
Last Edit:
NtQuerySystemInformation Delphi Example.
RRUZ's answer to Delphi - get what files are opened by an application as suggested by LU RD.
When we want to take another application which is compiled with debug information and get stuff out of it at runtime, what we are dealing with is the problem of "how to write my own custom debugger/profiler/automated-test kernel".
TestComplete and other AutomatedQA programs contain a Debugger and Profiler Kernel which can start up, run and remotely control apps, and parse their Debug information in several formats, including the TurboDebugger TD32 information attached to these executables. Their profiling kernel also can see each object as it is created, and can iterate the RTTI-like debug information to determine that an object that was created is of a particular class type, and then see what properties exist in that object.
Now, TestComplete adds on top of the AQTime-level of stuff, the ability to introspect Window handles, and intuit from Window Handles, the Delphi class Names that are behind it. However, it's much easier for you (or me) to write a program which can tell you that the mouse is over a window handle that belongs to a TPanel, than to know which version of Delphi created that particular executable, what version of TPanel that is, then, and what properties it would contain, and to read those values back from a running program, which requires that you implement your own "debugger engine". I am not aware of any open source applications that you could even use to get a start writing your own debugger, and you certainly can't use the ones that are inside AQTime/TestComplete, or the one inside Delphi itself, in your own apps.
I could not write you a sample program to do this, but even if I could, it would require a lot of third-party library support. To see the window classes for a window handle which your mouse is over, look for how to implement something like the MS Spy++ utility.
An easy case is if your mouse is mousing over a window inside your own application. For that, see this about.com link, which simply uses RTTI.

How to print (barcode) labels from a Ruby on Rails Application?

My first application I have developed in RoR is for some Kiosk Touchscreen PCs used in our stock. When the stock worker picked up some material he enters the quantity in a Form.
Now I want to print a label containing: customer name, material description, quantity, and a barcode on our Zebra printer.
How would I do that from a Ruby on Rails Application ?
Sending directly the control chars needed for ZPL (Zebra Printer Language) from the controller ? ( not very comfortable )
Create a view in HTML send it to the client, and the client has to print it. ( not very confortable and error prone, as the stock worker has to do additional steps, may choose the wrong printer or maybe don't print the label at all )
Create a pdf document from the controller and send it to the printer from the server ( oh, no the printer does not understand pdf, so I have to control a pdf reader to do the printing ?? That wouldn't be very fast as it will send the label as a graphic image to the printer
Create a gem which will hide all the logic needed for printing ? ( Are there any gems which already do this ? )
I would appreciate every comment.
Thanks
Klaus
I would send the raw ZPL to the printer. You can use a tool like Bartender (I would suggest installing Bartender Only from that link. You can basically design your label in this tool. After you've designed your label you would download the bartender printer drivers for your zebra printer and set up a dummy printer with these drivers and print this label you designed to a file. This will give you the raw zpl. From this you can basically substitute all the dynamic data into the zpl file you printed in the previous step and send this directly to the printer via serial, tcp/ip or usb.
Edit: I found a much better solution as I continued to dig on this. This is pretty significantly edited down to focus on the Java applet solution I ended up using.
Basically, you will generate the label as raw ZPL text. You then need to get that plain text to the printer, which will generate the label.
If your server can access the printer's IP address, you can copy the ZPL to the printer directly from the server process. If it's a remote web app, you need to get the client to send the ZPL for you. Browser sandboxing makes this hard to pull off - drivers want to helpfully get in the way. There are a few options; the most common is to use a small Java or Flash applet to do the actual copying. If you can get the specific web browser your users are using to print to a plain text printer without adding anything, you could use local printing, but generally the most robust approach is to use a helper Java applet.
The Java applet I use for this is jZebra: http://code.google.com/p/jzebra/
It's a very clean & straightforward approach, look at the sample HTML in the download package and a few lines of code print the label. I just edited down the sample and am planning to use it as my production code popup.. it's really that straightforward.
Two caveats with this approach:
Your users must have the JRE installed
jZebra finds the Zebra printer by printer name. There are very specific guides (they have detailed instructions for Mac, Windows, and Linux setup) for what you need to do - but it's well documented and you just have to have your users follow the instructions. Once it's set up correctly it works great.
More simple solution, and I believe better as well, Usually most of browser and machines has PDF viewer installed. So just create labels as PDF documents and sent it to browser.
We have implemented label printing using Zebra printer in ROR following way.
Create exact format label pages in html.
Convert the html to pdf using wickedPDF.
Usually labels contains barcodes as well.
So overall solution would be,
Create barcodes using barbie gem.
Create html using barcodes and your actuall data that needs to go on label.
Convert html view to PDF.
Sounds like a job for a ruby C extension. Perhaps one that also wraps something like gnu barcode http://www.gnu.org/software/barcode/ library and some other open standard for the zebra printer, if one exists? I once did a rails app that made coupons and made heavy use of gnu barcode, but I did simple shell command to interface to it.

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.

Web-based printing solutions

I'm building a new web-based product. The problem is that many clients have specific printers to print specific documents. Just think reports,barcodes,invoices etc. All on a special printer with the right paper etc...
Usually when printing from the web you cannot make the software choose a printer or change the settings. However it's just that that I want to do.
I want to print without a dialog. And enter the printer + settings with my software
The only solution I know of now is the commercial version of acrobat that has some javascript printing support..
Does anyone know of any other alternatives ?
Thanks in advance !
small-medium business
No heavy installion but common stuff is ok
ie. flash/silverlight/acrobat/whatever is possible
I generate what is necessary for printing (PDF/Tiff etc)
Who are your customers -- enterprises or SOHO? Are you generating PDFs? Or, raw tiffs? If you are generating PDFs there is something called a JDF file where you can specify the print settings to your heart's content. The flip side is the device needs to be capable of understanding JDFs. You can then attach the JDF with the PDF as a mime package. If you are generating tiffs, I think there isn't much need of printer settings except for the correct device profile(s) to be installed.
Because of security reasons, you cannot control that from within the browser.
If I where in your shoes, I'd create a small program for my clients to install, registering a specific file extension to this program and creating files in this format on the website, and have the program do the printing for me.
Your easy choices are either PDF or Microsoft's Reporting/Report Viewer

Resources