Best font for POS printer in WPF C# App - c#

I have developed an application in WPF and C# as client requirement. Now I am facing problem in bill printing. Printer is WEP DR-400 series and I am using "FlowDocument" to preview bill and printing. Now my client wants these issue to solve;
Printing is slow than previous Foxpro based app
Numbers printed on bill creates confusion like 8,9 and 6 appears quite same.
I don't know how to solve these problems, for 2. i have "MS Gothic" with 12 then "Segoe" with 13 font size in FlowDocument after client request. My font selection is constrained by page width (i need to print 5 cols with Item Name which should be displayed in one line).
Any help would be appreciated!!!

POS printers are almost exclusively used in their native dot-matrix mode. You send the strings to print directly to the printer, bypassing the printer driver. The font you'll get is the one that's baked into the printer's firmware. Typically mono-spaced and optimized to work well with the rather restricted output capabilities of a typical POS printer. The code you need is in this KB article.
When you use the printer driver, the printer is switched into graphics mode by the driver. That makes them very slow.

With regard fonts, Georgia is good in distinguishing digits at small point sizes. (Although at 13 points, you shouldn't get a problem with any font.)
As a fully interpreted language, FoxPro is not terribly quick although runtime has a low memory footprint. Could your client benefit from more memory?

Related

Custom paper size in crystalrepots viewer

I have an application where I need the user to be able to print to a network printer through a print server.
The paper being used is 8 * 8 form feed paper. When I print to the printer from my development machine it works fine and I can print multiple documents with perfect alignment.
If I print from a test machine which has the paper size defined in the print server options with the same name as the one in the report the application prints to the alignment of letter size of 8 by 11.
Is there anything I am missing?
-- I would comment instead of answer, but I don't have enough reputation --
Based on the description of the problem and your recent comment, it sounds like this may not be an issue with Crystal, as much as a problem with the client/user level printer configuration.
Are you able to print anything using the 8 * 8 using the test machine? It is just the Crystal Report that isn't aligned properly?
One way to test whether crystal is operating correctly is to export to pdf from the test machine, or print to pdf - this will verify whether crystal reports is properly retaining the page configuration.

Printing HTML in A4 and A5 paper format

Apparently a question about Printing HTML in A4 and A5 format is the exact same thing as asking about Printing RTF formatted text, so here's another question with the details a bit more laid out.
I am developing a C# (WinForms) program that should print orders. This program is written for the .NET 2.0 framework. The program has to be able to print in both A4 and A5 paper formats, without any user interferrance (no dialogs). The printed order should look exactly like it does in a webbrowser. You can check out this sample if you like to see what it should look like. As you can see, very basic stuff.
Here's what I have tried so far:
Asking a question on StackOverflow, got closed for being a duplicate. Never found the duplicate.
Print with the WebBrowser element. Cannot print A5, so that was no solution.
Put the HTML in RichTextBox and print that. It worked, but it didnt show the HTML like it's viewed in a webbrowser, which is a requirement. Code can be found here.
I've looked into converting to PDF before printing, but that is either expensive or just impossible to use (for me, as a programmer with little C# experience). These tools usually rely on software being installed on the users' computer (like Acrobat Reader for printing), which I'm trying to avoid.
Viewed about every relevant link in Google for at least 13 pages, no luck. I've been at this for about 2 and a half days now.
If someone has a (free) better way to print formatted HTML like it's viewed in the browser without user interferrence or external dependancies, please share. I really need this to work.
Please don't close this question, believe me when I say I actively searched for a solution or article that describes my problem. Some were relevant, but did not solve the problem that I'm having. I also used the advanced searched on this website, with no luck.
Thank you for taking the time to read this.
Note: When I say I never found the duplicate, I mean I never found the article that literally describes my problem.
You're going to have to bite the bullet and use a PDF library, there is no way you are going to be able to fully control the end printed result from HTML with so many different users, browsers and printers. I did printing to A4 for an internal business application, we had a very limited user base (maybe 5) and all printing to a specific printer, even then it was flaky at best. I don't believe there is a way to distinguish between A4 and A5 without user interference, i.e. they have to select paper size from the print options.
Suggest you take a look at PDF Sharp, Sharp PDF and iTextSharp , they are all OpenSource.
This can all be done from the server, i.e. nothing needs to be installed on the users machine. It should be possible to select the paper size using this (I am not 100% sure), but what the end user prints it on ultimately up to them.
I have done this successfully using the PrintHelper method described here. I used it to enable users in multiple locations to print barcode labels from a CMS system. The labels had strict requirements regarding layout, font size and positioning and all this was managed using HTML and CSS.
The PrinterHelper class works by passing it a webcontrol populated with the print data (I used a repeater to allow multiple labels) & the helper class builds a page in memory and opens the print dialog. You register your CSS like so:
pg.ClientScript.RegisterStartupScript(pg.GetType(),"LabelCSS","<link href=\"Styles/labelPrint.css\" rel=\"stylesheet\" type=\"text/css\" />");
One caveat though, it only worked with Firefox, and some settings had to be changed e.g. margins set to zero, but as the CMS required the use of that browser it wasn't a problem.

TVS RP-45 roll paper printing

I have a receipt made using Crystal Reports where the page is 4 inch wide and the height should be dynamic. I set the height to 2 inches, because I don't know how to make it dynamic. The printer is a TVS RP-45 Justbill printer.
The printer is ejecting paper after printing. How do I stop this from happening?
Any solution besides Crystal Reports would be helpful. The program is written in C# .NET 2.0 Winforms and connects to a SQL Server 2005 database.
Report Header Section
Bill no : 101
______________________________________________
Detail Section
Item Code Qty Amount
[ItemCode] [Qty] [Amount]
______________________________________________
Report Footer Section
Grand Total [GrandTotal]
______________________________________________
The Report Footer Section is using around 2 inches so I set the Height of the paper to 2 inches. This did not solve the problem. The paper height is now 2 times what it should be if there is more than 1 item.
The printer uses roll paper and it should feed more paper proportionally with the number of items sold.
Please help me solve this without wasting paper.
I'm going to suggest something a little different.
Create a new document in Notepad on Windows or a plain text editor on other OS's.
This document (.txt) should just contain one line: TEST_LINE_1
Send that document to your printer and see if the same after print feed continues.
If it continues to feed after the single line of print:
Check settings as follows ( I know you said you've already checked ):
From the manual:
[ http://www.tvs-e.in/pos/pdf/RP-45%20User%20Manual.pdf ]
To set the factory settings of the printer, first press FONT, Line feed and
PRINT buttons together and then switch ON the printer using ON/OFF
switch.
Usually you have to hold those buttons while switching it off and back on - hold until the printer prints its config off.
If you can post back with what the print out says word for word that would be good.
If it doesn't feed after the single line:
Your design is most likely too wide for the format/internal limits of the paper width and it's wrapping around onto a new line for every line you have.
Are you able to post a photo of what is being printed with how much paper it's on-feeding by?
Try printer on a different computer or laptop if possible with single line text file (as above) or with your custom report job - is it the same output?
If the printer is installed as a USB device: Remove all traces of the driver files and completely uninstall it as a printer - reinstall fresh copies and see what happens - the same?
I appreciate some of these things always 'seem obvious' when you're up against a problem but it does help to start over with the most basic of things..
Just remove headers and footers, It will work fine.

.NET component for color PDF to grayscale conversion

Currently i use Ghostscript to convert color PDF's to grayscale PDF's. Now i'm looking for reliable .NET commercial or not commercial component/library for ghostscript replacement. I googled and I did not find any component/library that is able to do that easily or to do that at all.
EDIT #1:
Why Ghostscript does not work for me:
I implemented Ghostscript and I'm using it's native API's. The problem is that Ghostscript does not support multiple instances of the interpreter within a single process. -dJOBSERVER mode also does not work for me because i don't collect all job and them process them all at once. It happens that Ghostscript is processing large job which takes around 20 minutes and meanwhile i get some smaller job which has to be processed ASAP and cannot wait 20 minutes. Other problem is that Ghostscript page processed events are not easily to catch. I wrote a parser for ghostscript stdout messages and i can read out processed page number but not for each page when it's processed as ghostscript pushes message for group of processed pages. There are couple of more problems with Ghostscript like producing bad pdf's, duplicating font problems.....
You can find one more problem i had with ghostscript here: Ghostscript - PS to PDF - Inverted images problem
-
a year after UPDATE:
Before a year a go i asked this question. Later i made my own solution by using iTextSharp.
You can take a look at the converting PDF to grayscale solution here:
http://habjan.blogspot.com/2013/09/proof-of-concept-converting-pdf-files.html
or
https://itextsharpextended.codeplex.com/
Works for me in most cases :)
Not quite an answer, but I think you dismiss Ghostscript too quickly.
Are you aware of the GhostScript API (for in-process Ghostscript)? Or of the -dJOBSERVER mode that can take a series of PS commands piped to its standard in?
That still won't get you your callbacks however, and it's still not multi-threaded.
As previously stated, iText could do it, but it would be a matter of walking through all the content and images looking for non-grayscale color spaces and converting them in a space-specific manner.
You'd also have to replace the pixel data in any images you might find.
The good news is that iText[Sharp] is capable of operating in multiple threads, provided each document is used from one thread at a time.
I suspect this is also the case for the suggested commercial library, which isn't such a good deal.
And then a light went on above my head... drawn in gray scale.
Blending modes and transparency groups!
Take all the current page content and stick it in a transparency group that is blended with a solid black rectangle that covers the page. I think there's even a luminosity to alpha blend mode... lets see here.
Yep, PDF reference section 11.6.5.2 "Soft Mask Dictionaries". You'll want a "luminosity" group.
Now, the bad news. If your goal in switching to gray scale is to save space, this will fail utterly. It'll actually make each file a little larger... say a 100 bytes per page, give or take.
The software rendering the PDF better be pretty hot stuff too. Your cousin's undergrad rendering project need not apply. This is advanced graphics stuff here, infrequently used by Common PDF Files, so the last sort of thing to be implemented.
So... For each original page
Create a new page.
Cover it with a black background.
Cover it with a white rectangle (had it backwards earlier) in a transparency group that uses a soft mask dictionary set to be the luminosity of the original page's content (now stashed in an XObject Form).
Because this is all your own code, you'll have ample opportunity to do whatever it is you want to do at the beginning or end of each page.
By golly, that's just crazy enough to work! It does require some PDF-Fu, but not nearly as much as the "convert each color space and image in various ways as I step through the document". Deeper knowledge, less code to write.
This isn't a .net library, but rather a potential work-around. You could install a virtual printer that is capable of writing PDF files. I would suggest CutePDF, as it's free, easy to use and does a great job 'printing' a large number of file formats to PDF. You can do nearly everything with CutePDF that you can do with a normal printer, including printing to grayscale.
After the virtual printer is installed, you can use c# to 'print' a greyscale version.
Edit: I just remembered that the free version is not silent. Once you print to the CutePDF printer, it will ask you to 'Save As'. They do have an SDK available for purchase, but I couldn't say whether it would be able to help you convert to grayscale.
If a commercial product is a valid option for you, allow me to recommend Amyuni PDF Creator .Net. By using it you will be able to enumerate all items inside the page and change their colors accordingly, images can also be set as grayscale. Usual disclaimers apply
Sample code using Amyuni PDF Creator ActiveX, the .Net version would be similar:
pdfdoc.ReportState = ReportStateConstants.acReportStateDesign;
object[] page_items = (object[])pdfdoc.get_ObjectAttribute("Pages[1]", "Objects");
string[] color_attributes = new string[] { "TextColor", "BackColor", "BorderColor", "StrokeColor" };
foreach (acObject page_item in page_items)
{
object _type = page_item["ObjectType"];
if ((ACPDFCREACTIVEX.ObjectTypeConstants)_type == ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypePicture)
{
page_item["GrayScale"] = true;
}
else
foreach (string attr_name in color_attributes)
{
try
{
Color color = System.Drawing.ColorTranslator.FromWin32((int)page_item[attr_name]);
int grayColor = (int)(0.3 * color.R + 0.59 * color.G + 0.11 * color.B);
int newColorRef = System.Drawing.ColorTranslator.ToWin32(Color.FromArgb(grayColor, grayColor, grayColor));
page_item[attr_name] = newColorRef;
}
catch { } //not all items have all kinds of color attributes
}
}
Before a year a go i asked this question. Later i made my own solution by using iTextSharp.
You can take a look at the converting PDF to grayscale solution here: https://itextsharpextended.codeplex.com/
iTextPdf a good product for creating/managing pdf it has got both commercial and free versions.
Have a look at aspose.pdf for .net it provides below features and a lot more.
Add and remove watermarks from PDF document
Set page margin, size, orientation, transition type, zoom factor and appearance of PDF document
..
And here is a list of open source pdf libraries.
After a lot of investigation i found out about ABCpdf from Websupergoo. Their component can easily convert any PDF page to grayscale by simple call to Recolor method. The component is commercial.

How to convert a printer driver to a stand-alone console application which can generate a printer file containing the bytes to be sent to the printer?

I have a situation where the only way to generate a certain datafile is to print it manually to FILE: under Windows and save it in a file for further processing.
I would really like to have a small stand-alone program which embeds this binary printer driver so I can run it from a batch file and have it generate that binary file for me, as we can then fully automate the "save file in Visio, 'print' it and upload it to the final destination and trigger a remote test".
Is this possible with a suitable Windows SDK? I am a Java programmer, so I do not know Visual Studio and the possibilities with MSDN - yet! - but I'd appreciate pointers.
EDIT: I have the installation files for that printer driver, both 32 and 64 bit. Older versions may include a 16 bit driver.
EDIT: The "print to FILE:" functionality is just what was recommended by the documentation. I have played a little bit with using the LPR-protocol to see what it can do. I'd still prefer the "invoke small binary" approach.
The general problem which you formulate is difficult to solve. Mostly a printer driver consists from some well known components like Print Monitor, Print Processor etc. which are well documented in Windows Driver Kit http://msdn.microsoft.com/en-us/library/ff560885%28v=VS.85%29.aspx. Some years ago I wrote a Print Monitor. It worked many years at a customer. So I know exactly what I writing about. A Print Monitor is nothing more as a DLL with well documented functions. The same is about most other printer components. Those DLLs will be loaded and called from Spooler. If you have a modern printer driver it has no components which run in kernel mode. So one can load most of DLLs from which consist every printer driver and call corresponding function.
You are interesting for using one concert printer driver. So the first what one should do is to examine how this driver is implemented. If you find out which component do the job which you need, you will be probably able to load this DLL in your process and produce output which you need. It is possible that you post an URL where I could download this driver?
UPDATED: I though a little more about your requirements. It seems to me you can goes with the way suggested by developer of the printer driver. If the driver can print to a local port FILE, then it can print in any printer port. So you can give src of a Port Monitor Server driver from C:\WinDDK\7600.16385.1\src\print\monitors\localmon (see also http://msdn.microsoft.com/en-us/library/ff556478%28v=VS.85%29.aspx, http://msdn.microsoft.com/en-us/library/ff549405%28v=VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/ff563806%28v=VS.85%29.aspx). (I is a windows 32/64 DLL, not a real driver) and makes small modification. Instead of saving results to a file you can dispatch the results to your application. It will be work with 100% without any tricks. If you will have some problem to understand localmon I can give you some tips. It is really not complex. The main changes which you have to do is to modify LcmStartDocPort LcmWritePort LcmReadPort LcmEndDocPort functions from localmon.c. Some easy thing which is distinguish Port DLL from a typical DLL, that instead of exporting all DLL's functions it export only one InitializePrintMonitor2 with pointers to all other functions.
UPDATED 2: One more tip for usage of "Local Port" monitor. If goes in printer configuration, then choose "Add Port...", select "Local Port" and click "New Port..." you can type any file name like "C:\temp\my.bin". Then all what you print through a printer will be printed in this file without any user iteration. The name can be any win32 file name (UNC names or Named pipes are also allowed). With this way you can realize some scenarios without any programming with DDK.
UPDATED 3: I looked at the printer driver from different sides and looked one more time in the API in DDK. Now I want recommend you to choose the easiest way, and the way which will be full supported from the driver manufacturer. I suggest following:
You install a printer with the driver which you need and choose as the output port a Local Port with a fixed file name (see Update 2). I named here the destination filename as C:\TEMP\Output.afp. So you receive exactly the same situation like recommend you driver manufacturer. Fixed file name is absolutely the same as FILE: port. So if you print to the printer you receive in Output.afp file in the C:\TEMP directory. To be sure the end of writing you can use ReadDirectoryChangesW or FindNextChangeNotification / FindFirstChangeNotification functions with dwNotifyFilter equal to FILE_NOTIFY_CHANGE_LAST_WRITE. Then you receive notification after last write-time of the file. It means after the end of writing and after FileClose and after the cache is sufficiently flushed. So the file Output.afp is not locked and you can really safe read the results.
For printing of simple documents you can use WritePrinter function (see http://msdn.microsoft.com/en-us/library/dd162959%28VS.85%29.aspx and remark in the documentation http://msdn.microsoft.com/en-us/library/dd145226%28VS.85%29.aspx). Writing of complex files with bitmaps, color and different fonts you have to use typical GDI API like one this in Windows (see http://msdn.microsoft.com/en-us/library/dd162865%28v=VS.85%29.aspx).
This solution looks not very spectacular like writing a printer driver component or a simulation of spooler environment for printer driver, but it will work, will safe work and will be full supported from the driver manufacturer.
(It's been 10 years since I did anything like this, but I don't think the overall concepts have changed all that much:)
What you want to do is implement a custom print processor. A print processor is the piece of code that takes the output that the printer driver generates and transports it to the output device. Print processors are implemented as regular user-mode DLLs. You should be able to find everything you need, including samples, in the Windows DDK.
A while ago we made a commercial application which captured print streams from any windows application and converted the result to XML and tiff images
We did make a prototype with the DDK, but ended up buying a SDK for the print capturing
The SDK was from BlackIce. Although it wasn´t a free SDK, the distribution of the runtimes were royalty free.
Implementation was done with Visual C (unmanaged) and VB6.
The printer driver had to be installed on the server/PC that drove the printing process.
I remember that the tricky part was to control the printer settings in runtime (keep the tiffs compressed, output directory for the files, paper size:A4 or Letter and other settings that were defined in the DEVMODE print control structure).
UPDATE: (Your comment to #Oleg about MO:DCA P triggered my memory. Although it is not about a printer driver...)
For our commercial product, we also had to make a customization to convert MO:DCA (AFP) documents to tiffs and XML.
This SDK had to be able to extract both images and ascii text to enable later conversions
Conversion where then made in batch from AFP documents in one folder to XML and tiffs.
We chose to convert the AFP file after it had been printed (not during print).
The SDK is SnowBound RasterMaster and is available in different flavours (we used the Windows API with ActiveX, and I see now that it is available for Java)
So if your requirement is to convert an AFP document to someting else (extract images and extract ascii text) you could try out the software from SnowBound. Make sure you also get the Optional Feature to be able to extract ASCII text from the MO DCA documents.
This software SDK is more expensive, but it did the job.
They offer a trial version here.
At the moment i have one missing link in your explanation, so let me rephrase what i understood:
You have a special printer driver on your windows system, that is configured to print into a file.
You like to have a simple batch program that can give something to this printer driver to output a binary file.
You have a toolchain where this file can be further processed.
Now my missing part is, what do you want to give to your little batch script, so that it produces your binary file? Do you have a Visio file which should be automatically printed through this driver?
If yes, you should take a look into this little batch script. It is able to take any file with a registered file extension and send it to the default printer with its default settings. By using these settings you are able to change the printer settings within your windows system from a batch file to make your special driver the default one and putting the output into a file.
So if i understood you correctly i didn't had the complete solution but i think a good starting point to accomplish your task.
Update
Ok, after reading your comment, i fully understood what you like to achieve. To get this to work you have to follow Per Larsens advice to write your own driver with the windows ddk (or to be more precise the Windows Driver Kit [WDK]) and encapsulate the already existing driver.
So in short and simple: Your driver signs up as new printer driver. When it is called it gets all the raw bytes from the application. Passes it into the driver that can generate your datafile. Get the output from that driver back and do with it whatever you like.
Some samples to get started can also be found in MSDN as overview or more precisely here.
But just to say it right beforehand: This is not an easy or simple task and the effort is quite high. Maybe trying to manipulate the driver settings of your special driver through the already given batches or a simple application (written with AutoIt) can also solve your problem, by just interacting (automatically) with the settings of the driver.
I can live with "When a user prints any file to this particular Windows printer, then automatically capture the bytes that would have been sent to the printer".
In that case, you want something like RedMon, which redirects the bytes which would have gone to the printer into the input for another program.
Just to reiterate, probably the simplest capture method is using a new Local Port configured as a filename. You can to monitor the output file as previously discussed to catch the output.
Otherwise, you want to write your own port monitor - not a printer driver or a print processor. All a port monitor does is receive the already rendered data from the printer driver, and sends it to the output device. So writing your own port monitor will allow you to go in and change the output port associated with the existing printer driver to be your own output port, and your port monitor can simply write the data to a file, probably one with a unique filename in a dedicated directory.
Printer drivers are far too complicated for what you want to do, and while a print processor could also capture the output data, you'd probably get entangled in some scantily documented system issues you won't want to have to figure out.
The LocalMon sample in the Windows Driver Kit is THE starting point for writing a port monitor. However, it manages all the system local ports and is quite a bit more complex than you need. In fact, much of it is just likely to confuse you. I'd recommend you start with LocalMon, and compare it to the Redmon source, which is much simpler because it manages a dedicated port. Beware that the Redmon source was taken from localmon long ago and appears to have a few bugs, so use Redmon as a reference and pare back the LocalMon code to what's needed to just write the output to a file.
You don't embed drivers in executables- drivers are for the operating system to communicate with the hardware.
You print via the Operating system.
Your 'batch' needs to select the correct printer, and print...

Categories