Dot matrix fast printing - java

I'd like to know, what practical way of printing on EPSON Dot Matrix printers in Java. I'm having the LX300+II model to play, with USB connectivity.
I searched too much on internet but all the codes available for network and serial(port LPT) printers.
like : https://code.google.com/p/escprinter/, http://devpath.blogspot.in/2008/01/java-como-imprimir-na-epson-lx-300-via.html
I tried with Java print service 2D Graphics, it works but taking time.
I know we have two ways of using this printer:
By directly raw ASCII data to printer
By Graphical printing, with graphical fonts and precise positioning.
How can I use both fast printing fonts (provided by 1) and precise positioning (provided by 2)? Any code or API?

There is a third-party API, RTextPrinter which seems to support the following Dot Matrix printer command sets:
Epson ESCP and ESCP2 or compatible
HP-PCL5 or compatible
HP-PCL 3 (known also as Laset Jet Plus Emulation)
IBM Proprinter or compatible
IBM PPDS
Diablo
Plain (no features)
It supports the following features as listed in its details page:
Font selection (courier ...)
Font style (bold, italic and underlined)
Font size (characters per inch)
Lines (vertical and horizontal) and rectangles
Character set managing and charater value mapping
Other: subscripts and superscripts, double wide, landscape format and interline spacing
However, this is not a free API and you will have to purchase a license to use it. You can try a demo to see if it satisfies your requirement though.
Hope this helps.

Related

How to count color pages in a PDF/Word doc using Java

I am looking to develop a desktop application using Java to count the number of colored pages in a PDF or Word file. This will be used as part of an overall system to help calculate the cost of printing a document in terms of how many pages there are (color/B&W).
Ideally, the user of the application would use a file dialog to select the desired PRF/Word file, the application could then count and output the number of colored pages, allowing the system to automatically calculate document cost accordingly.
i.e
if A4 colored pages cost 50c per page to print,
and B&W cost 10c per page,
calculate the total cost of the document per colored/B&W pages.
I am aware of the existing software Rapid PDF Count http://www.traction-software.co.uk/rapidpdfcount/, but would be unsuitable as part on integration into a new system. I have also tried using GhostScript/Python as per this solution: http://root42.blogspot.de/2012/10/counting-color-pages-in-pdf-files.html, however this takes too long (5mins to count a 100 page pdf), and would be difficult to implement into a desktop app.
Is there any method of counting the number of colored pages in a PDF or Word file using Java (or alternative language)
Thanks
Although it might sound easy, the task is rather complicated.
One option would be to use a program such as iText to walk every single token in the PDF, look for tokens that support color and compare that to your definition of "black". However, this will only get you basic text and drawing commands. Images are a completely different beast so you'll probably need to find an image parser or grab a copy of each spec and then walk each of those.
One of the downsides of token walking is you need to properly handle tokens that reference other things and further walk those tokens.
Another downside is that things can overlap each other so you'd probably want be aware of their coordinates, z-index, transparency and such.
There will be many more bumps in the road but that's a good start. What's most interesting is that if you accomplish this, you'll actually have found that you've partially built a PDF renderer!
Next, you'll need to define "black". Off the top of my head there's RGB black, CMYK black, Grey black and maybe Lab black along with some Pantones. That shouldn't be too hard but if I were to build this I'd want to know "blank ink usage" which could also be shades of grey. There's also "rich blank" that you might need to deal with, too!
So, all that said, I think that the GhostScript option you found is really the best bet. It literally renders the PDF and calculates the ink coverage from an RGB standpoint. You still should handle grey's, too, but that shouldn't be too hard, here's a good starting point.
Wanting to know what the click-charge is going to be is a pretty common problem, but it's not easy to solve at all. As already indicated by the answer Chris Haas gave, but I want to put another spin on it.
First of all, you have to wonder whether you really want to support both Word and PDF documents. Analysing Word files is less useful than you might think because that Word file is probably going to be converted into something else before it's going to be printed. And because of the fact that you're starting from Word, the chance that your nice RGB black text in Word gets converted to less-than-perfect 4 color black in PDF is very high. In other words, even though you might count a page of black text in Word as a 'cheap' page, it might turn into an expensive color page after conversion from Word to something that can be printed.
Let's consider the PDF case then. PDF supports a whole host of color spaces (gray, RGB, CMYK, the same with an ICC Profile attached, spot color and a few multi-spot color variants, CalGray and CalRGB and Lab. Besides that there is a whole range of very tricky features such as transparency, overprint, shades, images, masks... that you all have to take into account. The only truly good way to calculate what you need is to do essentially the same work as your printer will do; convert the PDF into one image per page and examine the pixels.
Because of what you want to do, the best way to progress would be to:
1) Convert any word files into PDF
2) Convert any PDF files into CMYK
3) Render each page of that CMYK file into an image.
Once you've done that you can examine the image and see whether you have any colors left. There are a number of potential technologies you can use for this. GhostScript is definitely one, but there are commercial solutions too that would certainly be more expensive but potentially faster.

Using a CFF / Type1c / Type2 font in Java

I'm trying to use some of the fonts embedded in PDF files in a Java application. Apparently, Java is able to load Type1 and TrueType fonts. According to several websites the Type1c fonts in a PDF are basically a CFF or Type2 font. A new feature of Java 7 is to load CFF font but Font.createFont() by this doesn't work.
So where am I going wrong? Is a Type1c font really a CFF/OpenType font? Is there any conversion required?
Is the font subsetted? (in which case it will contain only some characters and not the whole font).
In general CFF fonts embedded in PDFs can need a lot of conversion work to make them generally usable - if you have been following the development of our PDF to HTML5 converter on our blog (http://blog.idrsolutions.com), you will have seen lots of posts about various issues with fonts.
sfntly and fontforge are useful tools for font manipulation.
You're going to have to find out exactly what battle you're trying to fight I'm afraid. Don't believe web sites about fonts, read the PDF specification:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
Specifically you're looking for chapter 9.6 - Simple Fonts and 9.7 - Composite fonts.
To summarize, the fonts in a PDF file can be a number of types:
- Type 0
- Type 1
- Type 3
- TrueType
Type 1 and TrueType are the simplest ones and you're very likely to encounter them in PDF files. Type 3 is a font type where you can use graphics to draw the characters. Not very common.
Type 0 is a more complex font type which was originally devised to allow you to use large character sets (think Japanese / Chinese), but it is now also routinely generated by many professional design and layout applications. There are two subtypes of this Type 0 font type:
- SubType 0, which is a Type 1 font massaged into a Type 0 jacket, and
- SubType 2, which is a TrueType font massages into a Type 0 jacket
In all cases there are significant differences between "real" fonts that live on your system and those same fonts embedded in a PDF file.
Start by having a look at the PDF file with the fonts you want to use. Use a tool such as pdfToolbox from callas (http://www.callassoftware.com/callas/doku.php/en:download) or Browser from Enfocus (http://www.enfocus.com/en/products/browser). Both of these tools allow you to investigate the low-level structure of a PDF file, including looking at the actual page description code and looking at the font dictionaries. pdfToolbox is particularly good at diving into the fonts in a PDF file, including looking at the actual shapes and the instructions used to draw those shapes.
FontVerter is an open source java lib I wrote a little bit ago that can convert bare CFF* and Type0/composite fonts that come from PDFs into OTF/TTFs and WOFF1/2. It can also attempt to fix and normalize OTF/TTF fonts that don't work correctly in browsers, I found open type fonts embedded in PDFs often had various issues like missing tables which would prevent chrome from rendering them correctly.
FontVerter github
(*bare CFF = type1c I believe?, it's been a little and I'm forgetting which type is which)

Android fuzzy / faded fonts possible?

So I am developing a very simple app, mostly for personal use, am am looking for a simple solution to a simple problem.
In its simplest form I am looking for a way to have a line of text with just one or two words blurred out. Basically I am looking to blur text beyond readability but still hinting at what is hidden. Kind of a knowledge / memory app to help memorize some definitions by prompting with a few key words.
I am having issues finding a simple way to accomplish this. Am I just missing an attribute to blur text?
I have thought about:
overriding say the textview onDraw but that seems overkill and I am unsure if there are any methods available to easily blur text.
using the toHtml and trying out the new CSS3 blur effects but I don't think that that is a reasonable solution and I am not sure that the Android platform supports all the CSS3 format, if any.
the simplest and most desirable solution in my book was to find a font (ttf, off, etc) file, derived from a common font, that is already blurred as I described, and use that alternating with the non blurred version of that font to achieve the desired effect.
make the described font but that just plain requires too much time on my part and the outcome is not necessarily good :)
I have thought about some alternative ways to simulate this effect but they all result in fading the text, which is undesirable, since I want to have some visual prompts to indicate the obscured texts length.
Any ideas? It's been years since I have developed in Java and I am unsure what is available and what the Android OS supports.
I haven't looked into using these properties for only part of the text, but TextView has some possibly useful properties related to text shadows. Using something like the following XML attributes, you could hide the actual text and just show a blurred shadow.
android:textColor - #0000 (fully transparent so that the crisp text is not shown)
android:shadowColor - #FFFF (or whatever color you want to appear)
android:shadowDx - 0 (the shadow is in the same horizontal position as the text)
android:shadowDy - 0 (the shadow is in the same vertical position as the text)
android:shadowRadius - Depends on how much you want to blur. A very small non-zero value, such as 0.001, will be sharp. Larger values blur more, and at some point the shadow becomes illegible.

Advice needed: A programmatic way for creating vector graphics with heavy usage of text

I need a way for render a tree-like structures, similar to flowcharts.
Surprisingly, I can't find(or I'm doing wrong) a suitable tool.
First, I looked at SVG. But I couldn't find a way to draw a bounding box around the text
without using ECMAScript: I tried to do a simple thing drawing two text surrounded by boxes and linked by a line, centered by sides(some thing like O-O, where O is a box with text).And when you use ECMAScript, you heavily limit the tools that can be used for SVG rendering(for example you can't convert corrently such SVG to png or pdf with ImageMagick).
Second, I tried Asymptote, but it is quite heavy when you start manipulating with text(you need an LaTeX system installed and configured).
I look for a tool in which you can:
Programmatically access to font properties: baseline, ascent, descent, height
Computing height/width of a string(or the bounding box)
basic vector graphics functionality like drawing lines, shapes etc.
I don't think that's a hard stuff. For example, all such functionality exists for example in Java2D. Sure, I can use it as last resort and get raster graphics, but may be there is something handy to use?
Have you looked at GraphViz (http://www.graphviz.org/)? It does not really match your requirements since you give up some control and instead let the tool do the layout and rendering based on a declarative a description of a graph or tree, but I have found it to be the easiest way to generate tree-like output.
Not sure if it should be free?
Here's a commercial solution with an extensive API
http://www-01.ibm.com/software/integration/visualization/java/

Java print barcode labels

Can someone point in the right direction for printing barcode labels using Java? I can use the barbecue library (http://barbecue.sourceforge.net/) to generate them bar codes as images, but I need a way to put the image (and human readable caption) into an Avery document template for printing.
The iText library supports pretty much every kind of barcode imaginable. You can generate pdfs and either save them or print them internally.
I suggest using the barcode4j library instead of barbecue for 2 reasons:
Barbecue barcode objects are unnecessarily coupled to Java UI components (e.g. Barcode class extends JComponent). This creates unnecessary dependencies if the Java UI is not being used, e.g. for batch or command line based applications. They should have used aggregation rather than inheritance if they wanted to use their barcode classes with the Java UI.
Barcode4J looks like it is currently supported - version 2.0 released and copyright date is 2012
Then you have the problem of translating the barcode into a format that your printer understands. For this I suggest openlabelprint.org (which I wrote!) - it's another open source project that uses barcode4j and provides:
facilities to define a label layout using SVG (Scalable Vector Graphics - an open w3c standard) and
rasterization to a bitmap of the SVG from barcode4j (and the surrounding label layout in SVG) (openlabelprint applies the excellent Apache SVG Batik Java libraries for rasterization as well as for other SVG tasks)
printing of the bitmap on Zebra printers using their ZPL low level language. openlabelprint has a built in utility to convert png bitmaps to ZPL and send this to the Zebra printer via the standard Java printer system. Also openlabelprint provides APIs to extend it for other printer languages though ZPL is supported by some non-Zebra brands
I'm printing bar codes using java but I'm using a printer which have a pre-programmed function for printing bar codes. So I'm only telling the printer what codes to print and it does the rest. If you willing to pay for a printer it might saves you some time.
This may or may not be useful to you, but I thought i'd mention it.
I think you will have to measure your Avery label page with a ruler and then in your Java code, you will have to create a full Letter/A4/whatever page to print and offset your barcode image on that page to the appropriate location based on your measurements with the ruler.
Have you tried printing the image that you got from "barbecue" ?
You should try JZebra this is an applet and a good start point for you, take a look at the java source code.
http://code.google.com/p/jzebra/
For zebra you this simple guide will help you.
On this Zebra commands
N
q609
Q203,26
B26,26,0,UA0,2,2,152,B,"777777"
A253,56,0,3,1,1,N,"JHON3:16"
A253,26,0,3,1,1,N,"JESUSLOVESYOU"
A253,86,0,3,1,1,N,"TEST TEST TEST"
A253,116,0,3,1,1,N,"ANOTHER TEST"
A253,146,0,3,1,1,N,"SOME LETTERS"
P1,1
on JZebra
var applet = document.jzebra;
if (applet != null) {
applet.append("N\n");
applet.append("q609\n");
applet.append("Q203,26\n");
applet.append("B26,26,0,UA0,2,2,152,B,\"777777\"\n");
applet.append("A253,56,0,3,1,1,N,\"JHON3:16\"\n");
applet.append("A253,26,0,3,1,1,N,\"JESUSLOVESYOU\"\n");
applet.append("A253,86,0,3,1,1,N,\"TEST TEST TEST\"\n");
applet.append("A253,116,0,3,1,1,N,\"ANOTHER TEST\"\n");
applet.append("A253,146,0,3,1,1,N,\"SOME LETTERS\"\n");
applet.append("P1,1\n");}
Having clear this:
EPL is one command per line. A command starts out with a command identifier, typically a letter, followed by a comma-separated list of parameters specific to that command. You can look up each of these commands in the EPL2 programming documentation. Here’s an English-language version of the commands in the above example.
Sending an initial newline guarantees that any previous borked
command is submitted.
[N] Clear the image buffer. This is an important step and
generally should be the first command in any EPL document;
who knows what state the previous job left the printer in.
[q] Set the label width to 609 dots (3 inch label x 203 dpi
= 609 dots wide).
[Q] Set the label height to 203 dots (1 inch label) with a 26
dot gap between the labels. (The printer will probably auto-
sense, but this doesn't hurt.)
[B] Draw a UPC-A barcode with value "777777" at
x = 26 dots (1/8 in), y = 26 dots (1/8 in) with a narrow bar
width of 2 dots and make it 152 dots (3/4 in) high. (The
origin of the label coordinate system is the top left corner
of the label.)
[A] Draw the text "JESUSLOVESYOU" at
x = 253 dots (3/4 in), y = 26 dots (1/8 in) in
printer font "3", normal horizontal and vertical scaling,
and no fancy white-on-black effect.
All tha A starting lines are similar.
10. [P] Print one copy of one label.

Categories

Resources