Closed rajesh-shanthi closed 4 years ago
necesito ayuda estoy tratando de imprimir una imagen pero me salen otros caracteres
u can use this
you can check this
this repo use 3 laiblary
secreenshot to convert widget to image and image library to convert it to uint8 and pos_print to print it ass u love to show
https://github.com/blackangiliq/flutter_pos_printer_spport_arabic
Hi
Thanks for your effort and work. Really appreciated!
I copied the code you provided, but It did not work for me. The printer does not print anything. Then, I did what u said about figuring out the width and height in the ImageHelper class as it might cause an issue then it worked :)
So, I only added width and height
ImageHelper helper = new ImageHelper (384,58);
I am just sharing my experience as it could help others
So, thanks again
good try this:
import com.github.anastaciocintra.escpos.EscPos; import com.github.anastaciocintra.escpos.image.*; import image.ImageHelper; import java.awt.*; import java.awt.image.BufferedImage; import java.io.CharConversionException; import java.io.IOException; import static java.awt.image.BufferedImage.TYPE_INT_RGB; public class CoffeeBitmap2 { public void exec(EscPos escpos) throws IOException { final int FontSize = 30; // final String arabicText = "الصفحة الرئيسية"; final String arabicText = "تجربة تجربة"; // 1 - create one buffered image with width and height BufferedImage image = new BufferedImage(576, 150, TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // change background and foregroud colors g.setColor(Color.white); g.fillRect(0, 0, g.getDeviceConfiguration().getBounds().width, g.getDeviceConfiguration().getBounds().height); g.setColor(Color.BLACK); // choose your font //OBS: not all fonts work well with Arabic language // read more on https://docs.oracle.com/javase/tutorial/2d/text/advanced.html // // choose the font... below you have some combinations Font fontMonoSpacePlan = new Font (Font.MONOSPACED, Font.PLAIN, FontSize); Font fontMonoSpaceBold = new Font (Font.MONOSPACED, Font.BOLD, FontSize); Font fontMonoSpaceBoldItalic = new Font (Font.MONOSPACED, Font.ITALIC|Font.BOLD, FontSize); Font fontSerifPlan = new Font (Font.SERIF, Font.PLAIN, FontSize); Font fontSerifBold = new Font (Font.SERIF, Font.BOLD, FontSize); Font fontSansSerif = new Font (Font.SANS_SERIF, Font.PLAIN, FontSize); Font fontSansSerifBold = new Font (Font.SANS_SERIF, Font.BOLD, FontSize); // doc about canDisplayUpTo /** * Indicates whether or not this <code>Font</code> can display a * specified <code>String</code>. For strings with Unicode encoding, * it is important to know if a particular font can display the * string. This method returns an offset into the <code>String</code> * <code>str</code> which is the first character this * <code>Font</code> cannot display without using the missing glyph * code. If the <code>Font</code> can display all characters, -1 is * returned. * @param str a <code>String</code> object * @return an offset into <code>str</code> that points * to the first character in <code>str</code> that this * <code>Font</code> cannot display; or <code>-1</code> if * this <code>Font</code> can display all characters in * <code>str</code>. * @since 1.2 */ // .. // you can test the font if(fontMonoSpaceBold.canDisplayUpTo(arabicText) != -1){ throw new CharConversionException("the font doesn't work with these glyphs"); } // set the font to be used g.setFont(fontMonoSpaceBold); // write your text g.drawString("hello Arabian Character", 1, 90); // other line ... g.drawString(arabicText, 1, 140); // send the graphic to the escpos printer... **ImageHelper helper = new ImageHelper();** Bitonal algorithm = new BitonalThreshold(); // GraphicsImageWrapper imageWrapper = new GraphicsImageWrapper(); RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper(); helper.write(escpos, new CoffeeImageImpl(image),imageWrapper,algorithm); escpos.feed(5).cut(EscPos.CutMode.FULL); escpos.close(); } public void printCodeTable(EscPos escpos, int codeTable, int codMin, int codMax) throws IOException { escpos.setCharacterCodeTable(EscPos.CharacterCodeTable.CP437_USA_Standard_Europe); escpos.writeLF(String.format("character code table for code [%d], " + "\nbetween %d and %d", codeTable,codMin, codMax)); escpos.setPrinterCharacterTable(codeTable); for(int code = codMin; code <= codMax; code++){ escpos.write(code); escpos.write(" "); } escpos.writeLF(""); escpos.feed(5).cut(EscPos.CutMode.FULL); } }
good try this:
import com.github.anastaciocintra.escpos.EscPos; import com.github.anastaciocintra.escpos.image.*; import image.ImageHelper; import java.awt.*; import java.awt.image.BufferedImage; import java.io.CharConversionException; import java.io.IOException; import static java.awt.image.BufferedImage.TYPE_INT_RGB; public class CoffeeBitmap2 { public void exec(EscPos escpos) throws IOException { final int FontSize = 30; // final String arabicText = "الصفحة الرئيسية"; final String arabicText = "تجربة تجربة"; // 1 - create one buffered image with width and height BufferedImage image = new BufferedImage(576, 150, TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // change background and foregroud colors g.setColor(Color.white); g.fillRect(0, 0, g.getDeviceConfiguration().getBounds().width, g.getDeviceConfiguration().getBounds().height); g.setColor(Color.BLACK); // choose your font //OBS: not all fonts work well with Arabic language // read more on https://docs.oracle.com/javase/tutorial/2d/text/advanced.html // // choose the font... below you have some combinations Font fontMonoSpacePlan = new Font (Font.MONOSPACED, Font.PLAIN, FontSize); Font fontMonoSpaceBold = new Font (Font.MONOSPACED, Font.BOLD, FontSize); Font fontMonoSpaceBoldItalic = new Font (Font.MONOSPACED, Font.ITALIC|Font.BOLD, FontSize); Font fontSerifPlan = new Font (Font.SERIF, Font.PLAIN, FontSize); Font fontSerifBold = new Font (Font.SERIF, Font.BOLD, FontSize); Font fontSansSerif = new Font (Font.SANS_SERIF, Font.PLAIN, FontSize); Font fontSansSerifBold = new Font (Font.SANS_SERIF, Font.BOLD, FontSize); // doc about canDisplayUpTo /** * Indicates whether or not this <code>Font</code> can display a * specified <code>String</code>. For strings with Unicode encoding, * it is important to know if a particular font can display the * string. This method returns an offset into the <code>String</code> * <code>str</code> which is the first character this * <code>Font</code> cannot display without using the missing glyph * code. If the <code>Font</code> can display all characters, -1 is * returned. * @param str a <code>String</code> object * @return an offset into <code>str</code> that points * to the first character in <code>str</code> that this * <code>Font</code> cannot display; or <code>-1</code> if * this <code>Font</code> can display all characters in * <code>str</code>. * @since 1.2 */ // .. // you can test the font if(fontMonoSpaceBold.canDisplayUpTo(arabicText) != -1){ throw new CharConversionException("the font doesn't work with these glyphs"); } // set the font to be used g.setFont(fontMonoSpaceBold); // write your text g.drawString("hello Arabian Character", 1, 90); // other line ... g.drawString(arabicText, 1, 140); // send the graphic to the escpos printer... ImageHelper helper = new ImageHelper(); Bitonal algorithm = new BitonalThreshold(); // GraphicsImageWrapper imageWrapper = new GraphicsImageWrapper(); RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper(); helper.write(escpos, new CoffeeImageImpl(image),imageWrapper,algorithm); escpos.feed(5).cut(EscPos.CutMode.FULL); escpos.close(); } public void printCodeTable(EscPos escpos, int codeTable, int codMin, int codMax) throws IOException { escpos.setCharacterCodeTable(EscPos.CharacterCodeTable.CP437_USA_Standard_Europe); escpos.writeLF(String.format("character code table for code [%d], " + "\nbetween %d and %d", codeTable,codMin, codMax)); escpos.setPrinterCharacterTable(codeTable); for(int code = codMin; code <= codMax; code++){ escpos.write(code); escpos.write(" "); } escpos.writeLF(""); escpos.feed(5).cut(EscPos.CutMode.FULL); } }
Please could you tell me how i can get this fonts for windows in otf or ttf extension
@Hany1Gadallah, take a look at Font.createFont(...) https://docs.oracle.com/javase/8/docs/api/java/awt/Font.html
@Hany1Gadallah, take a look at Font.createFont(...) https://docs.oracle.com/javase/8/docs/api/java/awt/Font.html
I taked a look but i cant see a method to create this fonts in otf/ttf extention could you create this fonts in ttf or otf please i want to use your fonts in windows .. thank you for your reply and interesting
Hi,
I am trying to print arabic language and i get ????? as printed for the arabic text. The following is my code in java. public void Sample(String printerName) {
Can you please help me, what is the problem for junk characters getting printed. I just opened a texpad and pasted some arabic content and saved file in utf-8 encoding and fired printout to my pos printer , it is prining the arabic characters
Regards, Rajesh.