Jump to content
IGNORED

Anyone familiar with Java and processing here I could use a hand. Citizen GSX 140 Printer hack..


Recommended Posts

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 🙂

image.thumb.jpeg.f560679b1c0dc19477bc5600e9c3df5d.jpeg

Well next thing you know I built a device to spy on printer port and hook up to modern computer.

image.thumb.jpeg.d23439dab09f832d16b1eb197f9e8719.jpeg

This turned out to be fun project 😷

image.thumb.jpeg.f06bb5b5152ae88c6ecb0010aedf2b13.jpeg

image.thumb.jpeg.16b92c6276a881acb83d139098440630.jpeg

I've been learning Processing and Java for like a week only but here is the outcome.

image.thumb.jpeg.124d8b02265370b6b1419458fe2d740a.jpeg

And here is my problem I need to somehow figure out printer settings in processing using Java.

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 by Chri O.
  • Like 1
Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

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.

😃

image.thumb.jpeg.67b4aaac617c23ad729a12b705494a00.jpeg

image.thumb.jpeg.975aedad8abf021a2e209f5d044a539a.jpeg

 

image.thumb.jpeg.98a6269ab1a79d54a57436980c080377.jpeg

image.thumb.jpeg.ce923a3670b5cbd78a11035d6be1243b.jpeg

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
Posted (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 😁

image.thumb.jpeg.5472254b7bf37abb229c98073d201c78.jpeg

 

image.thumb.jpeg.c656cd69454f9531cd3594d0e1e2cd4a.jpeg

 

image.thumb.jpeg.a6acdd02fdbf3d9e0e76bb72799acd46.jpeg

Edited by Chri O.
  • Like 1
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...