4 Replies - 216 Views - Last Post: 20 April 2019 - 12:45 PM Rate Topic: -----

#1 Larry71   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 66
  • Joined: 05-June 12

drawString() sends nothing to printer

Posted 13 April 2019 - 09:24 AM

Hallo to everyone,

I have a class that implements Printable and it gets an array as input and sends it to printer.

The problem is that the array is correctly printed but if I try to add one more drawString, it does nothing.

My code :

	public int print(Graphics g, PageFormat pf, int page) {

    if (page > 0) { /* We have only one page, and 'page' is zero-based */
        return Printable.NO_SUCH_PAGE;
    }

   
	
    Graphics2D g2d = (Graphics2D)g;
	
    pf.setOrientation(PageFormat.PORTRAIT);
    
    g2d.translate(pf.getImageableX(), pf.getImageableY());
    
    g2d.setFont(new Font("Arial",Font.PLAIN,11));
    

    // Printing is OK for the loop

    for(int counter=1; counter<5; counter++) {

	g2d.drawString("●", counter * 2, counter * 5); // printed OK
			
    }

        // Never going to be printed
    	g2d.drawString("●", 90, 90);

    return Printable.PAGE_EXISTS;
	}


This post has been edited by Larry71: 13 April 2019 - 09:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: drawString() sends nothing to printer

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: drawString() sends nothing to printer

Posted 13 April 2019 - 11:34 AM

Quote

pf.getImageableX(), pf.getImageableY()

What are those returning?
Was This Post Helpful? 0
  • +
  • -

#3 Larry71   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 66
  • Joined: 05-June 12

Re: drawString() sends nothing to printer

Posted 14 April 2019 - 12:02 AM

pf.getImageableX() returns 9 and
pf.getImageableY() returns 8.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: drawString() sends nothing to printer

Posted 14 April 2019 - 05:38 AM

I think you're going to have to look at more metrics. See https://stackoverflo...300-dpi-printer
You might need to look at FontMetrics too

This post has been edited by g00se: 14 April 2019 - 05:40 AM

Was This Post Helpful? 1
  • +
  • -

#5 Larry71   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 66
  • Joined: 05-June 12

Re: drawString() sends nothing to printer

Posted 20 April 2019 - 12:45 PM

Thanks a lot g00se.

The problem was the paper's dimensions. The drawString() was trying to draw out from the bounds.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1