Hello all I am trying to print a string to my printer. I know that if I want to do that from Clojure I need to use Java Interop, specifically the Printable interface and the classes Graphics/Graphics2D and PrinterJob, but I have trouble to convert the equivelant Java code to Clojure. The java code and my attempt to Clojure are bellow. I have just started Clojure and I would be grateful if anyone can explain.
//Java///// import java.awt.*;import java.awt.print.*; public class foo implements Printable { private static Font sFont = new Font("Serif", Font.PLAIN , 64); public int print(Graphics g, PageFormat Pf, int pageIndex) throws PrinterException { if (pageIndex > 0) return NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D)g; g2.setFont(sFont); g2.setPaint(Color.black); g2.drawString("Save a tree!", 96, 144); return PAGE_EXISTS; } public static void main(String[] args) { PrinterJob job = PrinterJob.getPrinterJob( ); job.setPrintable(new foo( )); if (job.printDialog( )) { try { job.print( ); } catch (PrinterException e) {} } System.exit(0); }} ;;;;;;;;;Clojure;;;;;;; (ns controller.core (:gen-class) (:require [clj-http.client :as client] [cheshire.core :refer :all] [clojure.edn :as edn] [clojure.java.io :as io] [clojure.string :as str]) (:import [java.awt.print PrinterJob Printable PrinterException] [java.awt Graphics] ) ) (defn make-page [] (proxy [Printable] [] (print [graphics page-format page-index] (if (> page-index 0) Printable/NO_SUCH_PAGE (let [g2 graphics] (.drawstring g2 ("foooooooo" 96 144)) Printable/PAGE_EXISTS )) ) (defn prnt [] (let [print-j (PrinterJob/getPrinterJob)] (.setPrintable print-j (make-page)) (.print print-j))) (defn -main [& args] (prnt) ) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.