Chri O. Posted March 10 Share Posted March 10 (edited) Long story short after pulling out of the closet my over 30 years old Citizen GSX 140 printer after bit of cleaning to my surprise it's alive. 😁 EDIT : GSX 140 🙂 Well next thing you know I built a device to spy on printer port and hook up to modern computer. This turned out to be fun project 😷 I've been learning Processing and Java for like a week only but here is the outcome. And here is my problem I need to somehow figure out printer settings in processing using Java. PXL_20240310_080946602.mp4 For now I can only show you this I need to make better example. Spoiler import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Line2D; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterJob; Printer myPrinter; void setup() { size(960, 1024); myPrinter = new Printer(); } // By default, Processing loops through draw() continuously, executing the code within it. // However, the draw() loop may be stopped by calling noLoop(). // In that case, the draw() loop can be resumed with loop(). void draw() { // To do: I need to prepare example... } // function is called once every time a key is pressed. void keyPressed() { if (key=='p' || key=='P') myPrinter.StartPrinting(); println("Press key p or P to print new img."); } // --- printerclass --- public class Printer implements Printable { //--- Private instances declarations //private final double INCH = 72; public PrinterJob printJob; /** * Constructor */ public Printer() { //--- Create a printerJob object printJob = PrinterJob.getPrinterJob(); //--- Set the printable class to this one since we //--- are implementing the Printable interface printJob.setPrintable(this); } public void StartPrinting() { //--- Show a print dialog to the user. If the user //--- click the print button, then print otherwise //--- cancel the print job // this.g2d = myImage; //printJob.print(); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } } } /** * Method: print * <p> * * This class is responsible for rendering a page using the provided * parameters. The result will be a grid where each cell will be half an * inch by half an inch. * * @param g * a value of type Graphics * @param pageFormat * a value of type PageFormat * @param page * a value of type int * @return a value of type int */ public int print(Graphics pg, PageFormat pageFormat, int page) { //public int print(Graphics pg, PageFormat defaultPage, int page) { //int i; //Line2D.Double line = new Line2D.Double(); Graphics2D g2d; //--- Validate the page number, we only print the first page if (page == 0) { //--- Create a graphic2D object a set the default parameters g2d = (Graphics2D) pg; g2d.setColor(Color.black); //--- Translate the origin to be (0,0) // org g2d.translate(defaultPage.getWidth()/2-width/2, defaultPage.getWidth()/2); g2d.translate(pageFormat.getWidth()/2-width/2, pageFormat.getWidth()/2); pg.drawImage(g.image, 0, 0, null); return (PAGE_EXISTS); } else return (NO_SUCH_PAGE); } } // printerclass Edited March 10 by Chri O. 1 Quote Link to comment Share on other sites More sharing options...
ggn Posted March 11 Share Posted March 11 Sadly I have no experience with Java or Processing, but I'd like to post this message just to say that the project looks very cool! 1 Quote Link to comment Share on other sites More sharing options...
+DarkLord Posted March 11 Share Posted March 11 4 hours ago, ggn said: Sadly I have no experience with Java or Processing, but I'd like to post this message just to say that the project looks very cool! 2nd'ed...! 1 Quote Link to comment Share on other sites More sharing options...
Chri O. Posted March 13 Author Share Posted March 13 Thanks everyone. Well the good news is I think I did figure out the Printer page image resizing issue. 😃 Print_Job_Example CODE: Spoiler /** Print_Job_Example MIT License Chris O. 2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterJob; import java.awt.print.Paper; Printer myPrinter; // printerclass int x; int y; float outsideRadius = 480; float insideRadius = 100; int boxSizeX = 0; int boxSizeY = 0; void setup() { size(960, 1100); boxSizeX = width - 2; boxSizeY = height - 2; // NOTE: Only for Processing ver 4 +. windowTitle("Print Job Example, Key 'P' or Mouse click to open the print window"); myPrinter = new Printer(); background(255, 255, 255); // white x = width/2; y = height/2; rectMode(LEFT); println("Key 'P' or Mouse click to open the print window"); } // By default, Processing loops through draw() continuously, executing the code within it. // However, the draw() loop may be stopped by calling noLoop(). // In that case, the draw() loop can be resumed with loop(). void draw() { // example... background(255, 255, 255); // clear bg, white stroke(255, 0, 0); // Draw the box rect(0, 0, boxSizeX, boxSizeY); stroke(0, 0, 0); int numPoints = int(map(mouseX, 0, width, 6, 60)); float angle = 0; float angleStep = 180.0/numPoints; beginShape(TRIANGLE_STRIP); for (int i = 0; i <= numPoints; i++) { float px = x + cos(radians(angle)) * outsideRadius; float py = y + sin(radians(angle)) * outsideRadius; angle += angleStep; vertex(px, py); px = x + cos(radians(angle)) * insideRadius; py = y + sin(radians(angle)) * insideRadius; vertex(px, py); angle += angleStep; } endShape(); } // function is called once every time a key is pressed. void keyPressed() { if (key=='p' || key=='P') myPrinter.StartPrinting(); noLoop(); } void mousePressed() { myPrinter.StartPrinting(); noLoop(); } // --- printerclass --- public class Printer implements Printable { //--- Private instances declarations //private final double INCH = 72; public PrinterJob printJob; /** * Constructor */ public Printer() { //--- Create a printerJob object printJob = PrinterJob.getPrinterJob(); //--- Set the printable class to this one since we //--- are implementing the Printable interface printJob.setPrintable(this); } public void StartPrinting() { //--- Show a print dialog to the user. If the user //--- click the print button, then print otherwise //--- cancel the print job if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } } } /** * Method: print * <p> * * This class is responsible for rendering a page using the provided * parameters. The result will be a grid where each cell will be half an * inch by half an inch. * * @param g * a value of type Graphics * @param pageFormat * a value of type PageFormat * @param page * a value of type int * @return a value of type int */ public int print(Graphics pg, PageFormat pageFormat, int page) { Graphics2D g2d; //--- Validate the page number, we only print the first page if (page == 0) { //--- Create a graphic2D object a set the default parameters g2d = (Graphics2D) pg; g2d.setColor(Color.black); //println("DEBUG"); //println(pageFormat.getWidth()); //println(pageFormat.getHeight()); //println(pageFormat.getImageableWidth()); //println(pageFormat.getImageableHeight()); //--- Translate the origin to be (0,0) g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); // Wow this works ): // margin issue fix ( - 7 ) ? g2d.scale( (pageFormat.getImageableWidth() - 7 ) / boxSizeX, (pageFormat.getImageableHeight() - 7) / boxSizeY); //size(960, 1024) pg.drawImage(g.image, 0, 0, null); //g2d.drawImage(g.image, 0, 0, null); return (PAGE_EXISTS); } else return (NO_SUCH_PAGE); } // TODO: // Jason S, https://stackoverflow.com/questions/10455268/java-printing-creating-a-pageformat-with-minimum-acceptable-margin private PageFormat getMinimumMarginPageFormat(PrinterJob printJob) { PageFormat pf0 = printJob.defaultPage(); PageFormat pf1 = (PageFormat) pf0.clone(); Paper p = pf0.getPaper(); p.setImageableArea(0, 0, pf0.getWidth(), pf0.getHeight()); pf1.setPaper(p); PageFormat pf2 = printJob.validatePage(pf1); return pf2; } } // printerclass Quote Link to comment Share on other sites More sharing options...
Chri O. Posted March 13 Author Share Posted March 13 Any one up for testing the Printing application on other computer.😃 You are more than welcome please let me know.... Here are my executable application files for ~ Raspberry Pi 32 64 Bit ~ Linux ~ MS Windows. Only tested on MS Windows 10 so far, Mac OS app will come later. Print Job Example, Key 'P' or Mouse click to open the print window. windows-amd64.zip linux-arm.zip Pi 32 & 64 Print_Job_Example.zip 1 Quote Link to comment Share on other sites More sharing options...
Chri O. Posted March 14 Author Share Posted March 14 😷 2:40 am 😞 Video REC 1080p not the 4K as above. PXL_20240314_063126427.mp4 Quote Link to comment Share on other sites More sharing options...
Chri O. Posted April 27 Author Share Posted April 27 Just a quick update.. I made this Epson ESC/P Parser APP (Work-in-Progress) with Atari ST ASCII to Unicode lookup table. You can choose system installed fonts or fonts from app sketchPath("Fonts") folder. 😃 1 Quote Link to comment Share on other sites More sharing options...
Chri O. Posted May 11 Author Share Posted May 11 (edited) I partially implemented Canon Bubble Jet Printer BJ10s emulation 😷 360 by 360 dots per inch (dpi) for high resolution graphics. int W = 2880+20; // 20 for extra p. margin int H = 3600+40; Now I need 8K monitor 😁 Edited May 11 by Chri O. 1 Quote Link to comment Share on other sites More sharing options...
Chri O. Posted May 11 Author Share Posted May 11 AtariST to Unicode UTF-8 Enabled. PC UTF-8 Enabled. 7 JPGs: 2900 x 3640 exported JPGs.zip Quote Link to comment Share on other sites More sharing options...
Chri O. Posted May 14 Author Share Posted May 14 I just figured out PDF Export....😷 thanks to Processing PDF library. The PDF library makes it possible to write PDF files directly from Processing. These vector graphics files can be scaled to any size and output at very high resolutions. Smaller files but very high resolutions. artwork_0514-005335.pdf artwork_0514-005343.pdf artwork_0514-005348.pdf Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.