Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing JTable to PDF so that text is searchable  RSS feed

 
Malcolm Storey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you print (eg a JTable) from Java/Swing and choose "Adobe PDF" as the printer, you get an Acrobat file. But the PDF isn't searchable because the text has already been rendered by Java before Adobe PDF gets to see it. Is there a way to make printing use a more high-level interface to the printer driver so that the text is left intact?

For the avoidance of doubt: I'm not asking for Java to generate PostScript, although I guess that would be a solution - as would OCR'ing the resultant PDF.
 
Malcolm Storey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JTable printing examples do what I want, https://docs.oracle.com/javase/tutorial/uiswing/misc/printtable.html so it's something I'm doing wrong. I wrote the code a while ago, so need to investigate - probably printing the container not the JTable.

Apologies for wasting people's time.
 
Malcolm Storey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case anybody's interested I tracked it down. I was trying to hide the grid by making it transparent:

Obviously this is better:

Apparently if there's any transparency, Java renders the text itself rather than trying to do it in PostScript.
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We usually discuss tables in our GUIs forum. Moving discussion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!