java - Printing applet GUI -
i'm trying print same have in applet gui.
the things it's when print it's not same... size of each component changes in disproportionately way.
the gui:
printed:
the margins not problem, can fix them easily... can see barcode , vertical text has not proper size.
main class:
public class impresion extends applet{ printerjob job = printerjob.getprinterjob(); panel test; label test2; label test3; string copyparam = null; string dialogparam = null; string codeparam = null; string descparam = null; public void init(){ copyparam = this.getparameter("copias"); dialogparam = this.getparameter("ventanita"); codeparam = this.getparameter("codigo"); descparam = this.getparameter("descripcion"); copyparam = "1"; dialogparam = "1"; codeparam = "002/113"; descparam = "asd"; if (copyparam == null || dialogparam == null || codeparam == null || descparam == null){ system.out.println("faltan parametros. - "+copyparam+" - "+dialogparam+" - "+codeparam+" - "+descparam); } else { job.setprintable(new dibujar(codeparam, descparam)); printrequestattributeset aset = new hashprintrequestattributeset(); float leftmargin = (float) 0.1; float topmargin = (float) 0.1; float rightmargin = (float) 0.1; float bottommargin = (float) 0.1; float mediawidth = (float) 60.0; float mediaheight = (float) 50.0; aset.add(new mediaprintablearea(leftmargin, topmargin, (mediawidth - leftmargin - rightmargin), (mediaheight - topmargin - bottommargin), size2dsyntax.mm)); int copias = integer.parseint(copyparam); aset.add(new copies(copias)); boolean imprimir = true; if (dialogparam.indexof('1') != -1){ imprimir = job.printdialog(aset); } if (imprimir){ try { job.print(aset); } catch (printerexception e) { e.printstacktrace(); } } } } }
printable class:
public class dibujar implements printable{ string codeparam = null; string descparam = null; public dibujar(string code, string desc) { codeparam = code; descparam = desc; } public int print(graphics g, pageformat pageformat, int pageindex) throws printerexception{ if (pageindex > 0){ return no_such_page; } barcode b = null; try { b = barcodefactory.createcodabar(codeparam); b.setdrawingtext(false); b.setbarwidth(1); b.draw((graphics2d) g, 30, 8); } catch (barcodeexception | outputexception e1) { e1.printstacktrace(); } g.setfont(new font("arial", font.bold, 9)); string description = descparam; g.drawstring(description, 16, 70); affinetransform @ = affinetransform.getrotateinstance(math.toradians(90),16,8); graphics2d g2 = (graphics2d) g; g2.transform(at); g.setfont(new font("arial", font.bold, 14)); g2.drawstring(codeparam.replace("/", ""),16,8); g2.transform(new affinetransform()); return page_exists; } }
adjust parameters in this:
aset.add(new mediaprintablearea(leftmargin, topmargin, (mediawidth - leftmargin - rightmargin), (mediaheight - topmargin - bottommargin), size2dsyntax.mm));
or adjust parameters in these two:
b.draw((graphics2d) g, 30, 8); //.... g2.drawstring(codeparam.replace("/", ""),16,8);
Comments
Post a Comment