-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rotation/Orientation #58
Comments
Hi @proxseas |
I'll have to look into that. If it's trivial to turn text into an image that eventually looks the same when printed, then this might be my solution. Thanks. |
take a look at https://github.com/anastaciocintra/escpos-coffee-samples/blob/master/miscellaneous/CoffeeBitmap/src/main/java/CoffeeBitmap.java and how to rotate image ... putting all together public class Rotate {
public void exec(EscPos escpos) throws IOException {
String html = "" +
"<html>\n" +
"<head>\n" +
"<style>\n" +
"body {\n" +
" background-color: lightblue;\n" +
"}\n" +
"\n" +
"h1 {\n" +
" text-align: center;\n" +
"}\n" +
"\n" +
"p {\n" +
" font-family: verdana;\n" +
" font-size: 20px;\n" +
"}\n" +
"p.korean {\n" +
" font-family: Single Day;\n" +
" font-size: 20px;\n" +
"}\n" +
"</style>\n" +
"</head>" +
"<body>" +
"<h1>Hello, world.</h1>" +
"<p>الصفحة الرئيسية \n" + // Arabiac
"<br>你好,世界 \n" + // Chinese
"<br>こんにちは世界 \n" + // Japanese
"<br>Привет мир \n" + // Russian
"<br>नमस्ते दुनिया \n" + // Hindi
"<p class=\"korean\"><br>안녕하세요 세계</p>" + // if necessary, you can download and install on your environment the Single Day from fonts.google...
"</body>"
;
int width = 576, height = 576;
// Create a `BufferedImage` and create the its `Graphics`
BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration()
.createCompatibleImage(width, height);
Graphics graphics = image.createGraphics();
// Create an `JEditorPane` and invoke `print(Graphics)`
// JEditorPane jep = new JEditorPane("text/html", html);
JEditorPane jep = new JEditorPane();
jep.setContentType("text/html");
jep.setText(html);
jep.setSize(width, height);
jep.print(graphics);
BufferedImage rotatedImage = rotate(image);
// send the graphic to the escpos printer...
new ImageHelper().write(escpos, new CoffeeImageImpl(rotatedImage),new RasterBitImageWrapper(),new BitonalThreshold());
escpos.feed(5).cut(EscPos.CutMode.FULL);
escpos.close();
/* DEBUG, you can save the image */
File output = new File("/home/marco/desenv/html.png");
ImageIO.write(rotatedImage, "png", output);
}
private BufferedImage rotate(BufferedImage img) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage newImage = new BufferedImage(w, h, img.getType());
Graphics2D g2 = newImage.createGraphics();
g2.rotate(Math.toRadians(90), w/2, h/2);
g2.drawImage(img,null,0,0);
return newImage;
} |
Has anyone applied this and worked ? |
hi @Eftychiou , |
yes i have this printer (https://www.xprintertech.com/pos-printer-xprinter) that supports rotation.
Label printer compatible with TSPL\ EPL\ DPL\ ZPL emulation.
Your code (dantsu) looks perfect for usage and implementation therefore the code provided by dantsu does not implement rotation. How can we apply the rotation feature on the code provided by dantsu ?
Best Regards,
George Eftichiou
Cyprus
[https://img5541.weyesimg.com/uploads/rsirawa8.allweyes.com/images/777ce2954082e50b6d739efff0c0ceff.jpg]<https://www.xprintertech.com/pos-printer-xprinter>
XP-P200<https://www.xprintertech.com/pos-printer-xprinter>
Want to know more about pos printer form Xprinter Group? Click in to learn more!
www.xprintertech.com
…________________________________
From: Marco Antonio ***@***.***>
Sent: Monday, April 18, 2022 2:21 PM
To: anastaciocintra/escpos-coffee ***@***.***>
Cc: Eftychiou ***@***.***>; Mention ***@***.***>
Subject: Re: [anastaciocintra/escpos-coffee] Rotation/Orientation (#58)
hi @Eftychiou<https://github.com/Eftychiou> ,
can you share your specific problem? is this about rotation?
—
Reply to this email directly, view it on GitHub<#58 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ARL4ZVPQGGR7TPJIVXGOJT3VFVASBANCNFSM4VGGKB2A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
ok, point of attention:
if the answer is not, then I don't know if this solution fits for your printer.the idea is not send escpos rotation commands to the printer, but, instead of this, create one image with graphics2d, then rotate image and then print rotated image... If your printer is compatible with escpos commands, it can work! import com.github.anastaciocintra.escpos.EscPos;
import com.github.anastaciocintra.escpos.EscPosConst;
import com.github.anastaciocintra.escpos.image.BitonalThreshold;
import com.github.anastaciocintra.escpos.image.CoffeeImageImpl;
import com.github.anastaciocintra.escpos.image.RasterBitImageWrapper;
import com.github.anastaciocintra.output.PrinterOutputStream;
import image.ImageHelper;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.print.PrintService;
import javax.swing.*;
public class Rotate {
public void exec(EscPos escpos) throws IOException {
String html = "" +
"<html>\n" +
"<head>\n" +
"<style>\n" +
"body {\n" +
" background-color: lightblue;\n" +
"}\n" +
"\n" +
"h1 {\n" +
" text-align: center;\n" +
"}\n" +
"\n" +
"p {\n" +
" font-family: verdana;\n" +
" font-size: 20px;\n" +
"}\n" +
"p.korean {\n" +
" font-family: Single Day;\n" +
" font-size: 20px;\n" +
"}\n" +
"</style>\n" +
"</head>" +
"<body>" +
"<h1>Hello, world.</h1>" +
"<p>الصفحة الرئيسية \n" + // Arabiac
"<br>你好,世界 \n" + // Chinese
"<br>こんにちは世界 \n" + // Japanese
"<br>Привет мир \n" + // Russian
"<br>नमस्ते दुनिया \n" + // Hindi
"<p class=\"korean\"><br>안녕하세요 세계</p>" + // if necessary, you can download and install on your environment the Single Day from fonts.google...
"</body>"
;
int width = 576, height = 576;
// Create a `BufferedImage` and create the its `Graphics`
BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration()
.createCompatibleImage(width, height);
Graphics graphics = image.createGraphics();
// Create an `JEditorPane` and invoke `print(Graphics)`
// JEditorPane jep = new JEditorPane("text/html", html);
JEditorPane jep = new JEditorPane();
jep.setContentType("text/html");
jep.setText(html);
jep.setSize(width, height);
jep.print(graphics);
BufferedImage rotatedImage = rotate(image);
// BufferedImage rotatedImage = image;
// send the graphic to the escpos printer...
new ImageHelper().write(escpos, new CoffeeImageImpl(rotatedImage),new RasterBitImageWrapper(),new BitonalThreshold());
escpos.feed(5).cut(EscPos.CutMode.FULL);
escpos.close();
/* DEBUG, you can save the image */
File output = new File("/home/marco/desenv/html.png");
ImageIO.write(rotatedImage, "png", output);
}
private BufferedImage rotate(BufferedImage img) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage newImage = new BufferedImage(w, h, img.getType());
Graphics2D g2 = newImage.createGraphics();
g2.rotate(Math.toRadians(90), w/2, h/2);
g2.drawImage(img,null,0,0);
return newImage;
}
public static void main(String[] args) throws IOException {
PrintService printService = PrinterOutputStream.getPrintServiceByName("TM-T20");
PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
EscPos escpos = new EscPos(printerOutputStream);
Rotate obj = new Rotate();
obj.exec(escpos);
}
} |
Sorry for mentioning dantsu code in the previous email. Now i can see what you are solving with this library.
As this could be my last solution of creating an image then rotating it. Do you have any sample code that shows this implementation ?
Do you have an example case that this library was tested on android/gradle ?
…________________________________
From: Marco Antonio ***@***.***>
Sent: Monday, April 18, 2022 7:35 PM
To: anastaciocintra/escpos-coffee ***@***.***>
Cc: Eftychiou ***@***.***>; Mention ***@***.***>
Subject: Re: [anastaciocintra/escpos-coffee] Rotation/Orientation (#58)
ok, point of attention:
unfortunately, the escpos-coffee doesn't work with another pattern than esc/pos,
and, I'm in doubt if your printer is compatible with escpos!
Label printer compatible with TSPL\ EPL\ DPL\ ZPL emulation.
if the answer is not, then I don't know if this solution fits for your printer.
the idea is not send escpos rotation commands to the printer, but, instead of this, create one image with graphics2d, then rotate image and then print rotated image...
If your printer is compatible with escpos commands, it can work!
if are you using another library then espos-coffee it can work too!
I hope it works!
[78a70d0e-f171-433a-b2e5-7e0520ca7d10]<https://user-images.githubusercontent.com/43155086/163838817-eeaba3cc-6d6b-47de-8bc9-9ab65a330f0e.jpeg>
—
Reply to this email directly, view it on GitHub<#58 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ARL4ZVNEWDDQ7PF5JMNVQ6LVFWFNXANCNFSM4VGGKB2A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
no problem, it is an excellent library
yeap, on last post at the final part.
sure, caveats about rotation solution: see you, |
thank you very much and sorry for asking twice questions that you had answered earlier :p |
count on me |
To my knowledge, there is currently no way to set the print orientation in this library. To me this is important, because one of the receipt printers I'm working with prints upside down, by default. This is something I'm able to change in the printer settings in Windows and then prove that this change worked by printing a test page (through Windows). However, when I use EscPos, it bypasses all the Windows settings, so I think this feature should be made available through the EscPos library.
The text was updated successfully, but these errors were encountered: