Printing tiff images in java


Hi

I want to print tiff images in java using jdk1.2.
i am posting this query because the print related api is available in java.awt.print.*.
I will be
Posted On: Tuesday 23rd of October 2012 11:38:06 PM Total Views:  2384
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




problem in printing swing components?

i have a registration page, and after registration of a student i need to print the tc (transfer certificate), in the (Photo1430.jpg) image format, (in the same format shown in the image). field values are coming from the database.(ie. value of name, value of dob, value of place so on...) i am doing something like this: import java.awt.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; public class PrintUIWindow implements Printable, ActionListener { JFrame frameToPrint; JLabel lblStuName, lblBirthPlace, lblDob, lblLastSch, lblLastExam, lblYearOdAdd,lblStudyingStandard; JLabel d, d1, d2, d3, d4; static JPanel panel; Box horiz1, horiz2, horiz3, horiz4, horiz5, horiz6; public PrintUIWindow() { panel = new JPanel(); lblStuName = new JLabel("1.) Name of Student (in Full)"); lblBirthPlace = new JLabel("2.) Place of Birth"); lblDob = new JLabel("3.) Date of Birth, Month and year (in figures)"); lblLastSch = new JLabel("4.) Last School College Attended"); lblLastExam = new JLabel("5.) Last Examination Passed"); d1 = new JLabel(" : ........................................................."); d2 = new JLabel(" : ........................................................."); d3 = new JLabel(" : ........................................................."); d4 = new JLabel(" : ........................................................."); d = new JLabel(" : ........................................................."); horiz1 = Box.createHorizontalBox(); horiz1.add(lblStuName); horiz1.add(d); horiz2 = Box.createHorizontalBox(); horiz2.add(lblBirthPlace); horiz2.add(d1); horiz3 = Box.createHorizontalBox(); horiz3.add(lblDob); horiz3.add(d2); horiz4 = Box.createHorizontalBox(); horiz4.add(lblLastSch); horiz4.add(d3); horiz5 = Box.createHorizontalBox(); horiz5.add(lblLastExam); horiz5.add(d4); Box vert = Box.createVerticalBox(); vert.add(Box.createVerticalStrut(100)); vert.add(horiz1); vert.add(Box.createVerticalStrut(30)); vert.add(horiz2); vert.add(Box.createVerticalStrut(30)); vert.add(horiz3); vert.add(Box.createVerticalStrut(30)); vert.add(horiz4); vert.add(Box.createVerticalStrut(30)); vert.add(horiz5); panel.add(vert); } public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { /* We have only one page, and 'page' is zero-based */ return NO_SUCH_PAGE; } /* * User (0,0) is typically outside the imageable area, so we must translate * by the X and Y values in the PageFormat to avoid clipping */ Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); /* Now print the window and its visible contents */ frameToPrint.print(g); /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; } public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException ex) { /* The job did not successfully complete */ } } } public static void main(String args[]) { JFrame f = new JFrame("Print TC"); JButton printButton = new JButton("Print TC"); printButton.addActionListener(new PrintUIWindow()); panel.add("South", printButton); f.add(panel); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); } }
VIEWS ON THIS POST

301

Posted on:

Tuesday 25th September 2012
View Replies!

Java code printing junk characters in PDF

I have a JAVA code that reads a PDF file from remote server. It then merges it with an existing PDF file and print the resultant. However, sometimes I observe that the PDF printed contains gibbersih data. It doesn't happen always. Is it some issue with the fonts used in PDF Or some inherent issue of Java, while printing PDF files. I use a print job object to print PDF file. Logic for printing the PDF file is as following private boolean printDocument(String fileName){ System.out.println("printComplianceDocument : Begin"); boolean result = false; PDDocument document = null; PDPage page = new PDPage(); try { document = PDDocument.load(fileName); PrinterJob pjob = PrinterJob.getPrinterJob(); PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet(); attr_set.add(Sides.DUPLEX); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attr_set); for(PrintService service : services){ if (service.getName().equalsIgnoreCase(SystemProp.getInstance().getWorkStation().getDfltRptPrinter().getAddress().trim())){ System.out.println("Printing Document to printer: " + service.getName()); pjob.setPrintService(service); pjob.setPageable(document); pjob.print(attr_set); result = true; break; } } //Try printing to Default Printer if appropriate Print Service is not found if(!result){ PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService(); System.out.println("Printing Document to Default Printer: " + defaultPrintService.getName()); pjob.setPrintService(defaultPrintService); pjob.setPageable(document); pjob.print(attr_set); result = true; } } catch (IOException e) { // Exception } catch (PrinterException e) { // Exception } System.out.println("printDocument : End"); return result; } Please share your ideas and suggest solutions if you could.
VIEWS ON THIS POST

231

Posted on:

Monday 1st October 2012
View Replies!

printing JTables - concatenating? what about the panels?

I am printing a JTable in this manner: StringBuffer sb = new StringBuffer(); PrintRequestAttributeSet attribs = new HashPrintRequestAttributeSet(); attribs.add(new Copies(1)); attribs.add(OrientationRequested.PORTRAIT); int xx = 1; //left and right margin int yy = 1; //top and bottom margin. Note that bottom margin cannot be less than 15 mm int ww = 845; //Width int hh = 599; //Height int units = MediaPrintableArea.MM; attribs.add(new MediaPrintableArea(xx, yy, ww, hh, units)); String title = "My Table"; sb.append(title); MessageFormat footer = new MessageFormat("Page {0}"); getPayrollHeadcountList().getTable().setPreferredSize(new Dimension(500, 500)); getPayrollHeadcountTotalList().getTable().setPreferredSize(new Dimension(500, 100)); try { getPayrollHeadcountList().getTable().print(PrintMode.FIT_WIDTH, header, footer, true, attribs, false); //getPayrollHeadcountTotalList().getTable().print(PrintMode.FIT_WIDTH, header, footer, true, attribs, false); } catch (PrinterException pe) { Debug.trace(pe); }
VIEWS ON THIS POST

369

Posted on:

Wednesday 17th October 2012
View Replies!

Simple text printing with pagebreaks

I have a report displayed in a GUI application as a simple text within JTextComponent. My goal is to print it but with page breaks at certain points. I have inserted \f at those places, however when I print page breaks are ignored and I get a weird character printed in those places where \f was and the rest of the text is just printed out without page breaks. One thing I v noticed is that if I output the report to a file and open it with MS Word page breaks are recognised and report is displayed correctly. However, if I try to open it with notepad page breaks are not recognised. I have tried converting the text to RTF but the \f character was still ignored. I would really appreciate if anyone shares their experience with something similar and how did you solve it cheers
VIEWS ON THIS POST

296

Posted on:

Wednesday 17th October 2012
View Replies!

printing a jtable

I've got a swing JTable of about 20 rows ans 40 columns that I want to print on paper. I tried the table.print() method but that doesn't work, I just get one big empty cell on the paper. I tried an example from another site and that one works perfectly (http://java.sun.com/docs/books/tutorial/uiswing/misc/printtable.html). Does anyone know what's going wrong Is my table too large for the paper and do I need to resize it, and if so how
VIEWS ON THIS POST

308

Posted on:

Wednesday 17th October 2012
View Replies!

JTable printing problem

I have sample of JTable with data that i would like to be right aligned, also orange background color cell renderer is applied, and font is set to be Tahoma BoldItalic with font size of 13. Problems that arise are, grid lines are over cell text, and also applied background color looks strange when PDF printer is used and document is zoomed. Interesting thing is that when font is set to be even grid lines doesn't intersect cell text. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.JTable.PrintMode; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; public class TablePrintTest extends JFrame { private static final long serialVersionUID = 1L; private static final Object[] COLUMN_NAMES = { "Column1", "Column2", "Column3" }; private static final Object[][] CELL_VALUES = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; private JButton printButton; private JTable table; public TablePrintTest() { super("TablePrintTest"); createGui(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void createGui() { table = new JTable(new DefaultTableModel() { private static final long serialVersionUID = 1L; @Override public Class getColumnClass(int columnIndex) { return Number.class; } @Override public int getColumnCount() { return COLUMN_NAMES.length; } @Override public int getRowCount() { return CELL_VALUES.length; } @Override public String getColumnName(int column) { return COLUMN_NAMES[column].toString(); } @Override public Object getValueAt(int row, int column) { return CELL_VALUES[row][column]; } }); table.setDefaultRenderer(Number.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); label.setHorizontalAlignment(SwingConstants.RIGHT); return label; } public java.awt.Color getBackground() { return Color.orange; }; }); table.setFont(new Font("Tahoma", Font.ITALIC | Font.BOLD, 13)); printButton = new JButton("Print"); printButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Printable printable = table.getPrintable(PrintMode.NORMAL, null, null); PrinterJob pJob = PrinterJob.getPrinterJob(); pJob.setPrintable(printable); if (pJob.printDialog()) { try { pJob.print(); } catch (PrinterException e1) { e1.printStackTrace(); } } } }); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(printButton, BorderLayout.NORTH); contentPane.add(new JScrollPane(table), BorderLayout.CENTER); setContentPane(contentPane); pack(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TablePrintTest().setVisible(true); } }); } }
VIEWS ON THIS POST

328

Posted on:

Wednesday 17th October 2012
View Replies!

Problem in printing JTable values

Dear Friends, I have to print the JTable values (on paper using print dialogue box). I'm using jtableObj.print to print the table values. But jtableObj.print takes more time to print the table values because it prints the values as a image(approximately 5 mins to print 10 pages). My code is , boolean complete = tableObj.print(mode, header, footer, showPrintDialog, null, interactive, null);
VIEWS ON THIS POST

296

Posted on:

Wednesday 17th October 2012
View Replies!

printing on A4 paper

The paper object creates a letter sized piece of paper with one inch margins. Is there any way to set different margins to allow a page designed to fit on letter to also print on A4 by reducing the margins Or any other ideas ------------------
VIEWS ON THIS POST

428

Posted on:

Thursday 18th October 2012
View Replies!

printing html and images using JEditorPane

hi i am working on printing multiple html and images(png) in a single batch.. i am able to print all in a single batch if html files are single page files but if they are multipage files i am unable to print them. i am rendering html to a JEditorPane. i can print multiple multipage html files in a single batch but unable to do html files and images in a single batch .. anyone can help me thanx in advance -if you want i can provide code bye madhu
VIEWS ON THIS POST

269

Posted on:

Thursday 18th October 2012
View Replies!

printing data from JEditor Pane

I have a program in which the data is shown in JEditor Pane. I have used HTMl tags to get the deed format. Now i want to print it. how should i proceed :roll:
VIEWS ON THIS POST

230

Posted on:

Thursday 18th October 2012
View Replies!

printing html file

hello, i have a html file. i want to print it. i using jeditorpane for showing the html file. because html file is large enough that i cannot show it whole in jeditorpane. so i used the container jscrollpane. when i want to print the document showing in the jscrollpane it print only the current shwing document not the whole document. please help me to solve this.
VIEWS ON THIS POST

239

Posted on:

Thursday 18th October 2012
View Replies!

printing jframe content in core java

I want to print Jframe like our word document. I have one jframe on jframe i have Jpanel ond on that panel i have j label . In jlabel i written a letter i want to print that letter so how can I print that letter.
VIEWS ON THIS POST

272

Posted on:

Sunday 21st October 2012
View Replies!

JTable printing . . .

I have customized the column widths of a JTable to display properly on screen. But this size of the JTable doesn't looks good on the print when i set the JTable.PrintMode.FIT_WIDTH option, which produces small table on paper. But when the column widths are reduced on screen it looks very good on paper, and losses its look on screen.So, i want to make the table to fit width both on the screen and paper also. How to achieve this Thank you.
VIEWS ON THIS POST

241

Posted on:

Monday 22nd October 2012
View Replies!

Facing problems printing a ScrolledComponent in SWT

Hi , I am facing problems printing a ScrolledComponent in SWT . I am able to print the contents that are visible but not able to print the contents below the scroll . This happens for both vertical and horizontal scroll . Can some one please suggest how to proceed .
VIEWS ON THIS POST

237

Posted on:

Monday 22nd October 2012
View Replies!

problem in printing to file (JSE 6)

I tried using printing support in JTextComponent, as provided in Java SE 6. The code I used is really simple: try { boolean complete = jTextArea1.print(); if (complete) { /* show a success message */ System.out.print("success"); } else { /*show a message indicating that printing was cancelled */ System.out.print("cancelled"); } } catch (PrinterException pe) { /* Printing failed, report to the user */ System.out.print("exception"); }
VIEWS ON THIS POST

240

Posted on:

Monday 22nd October 2012
View Replies!

Help with reprinting downloaded text from FTP site onto GUI!

*This has already been posted on the Sun Java Forum, but I need help quickly, so I am cross-posting. Thank you!* Basically, I have all of the data download from the FTP site but I can't get it to be reprinted to the GUI after the GUI is already opened initially. I'm pretty sure I have to make a new method at the very bottom of the GUIWindow.java class but I don't know what goes there. If anyone needs to look at the other classes, let me know. By the way, I'm handing this in for my final project in Computer Science tomorrow, so I need help quick!
VIEWS ON THIS POST

208

Posted on:

Monday 22nd October 2012
View Replies!

Problem in printing Jpanel Data

I am working on a swings application I have a Jpanel, I am facing serious problem with printing this JPanel data with "card printer". This is working fine when i using paper color printer but when i am using card printer its printing nothing. I have tested the printer using some Images and it is printing fine when i print any Image directly but using my application having problem the card printer not receiving any data while the paper printer is printing fine. Any one faced this before or anyone please help me out. This is my code: private void printCard(){ PrinterJob printjob = PrinterJob.getPrinterJob(); printjob.setJobName(" CUSTOMER CARD "); printjob.setPrintable (new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum){ pf.setOrientation(PageFormat.LANDSCAPE); if (pageNum > 0){ return Printable.NO_SUCH_PAGE; } Graphics2D g2 = (Graphics2D) pg; g2.translate(pf.getImageableX(), pf.getImageableY()); g2.translate( 0f, 0f ); jLayeredPane2.paint(g2); return Printable.PAGE_EXISTS; } }); if (printjob.printDialog() == false) return; try { printjob.print(); } catch (PrinterException ex) { System.out.println("NO PAGE FOUND."+ex); } }
VIEWS ON THIS POST

250

Posted on:

Monday 22nd October 2012
View Replies!

how to convert byte array to images

hi folks i want to display some images in the jsp. by taking the images from DataBase ,i already inserted the image into the dataBase as a BLOB and i have retrived the image from DataBase as a byte array now i dont no how to convert the byte array to image iam using struts and hibernate eagerly waiting for your replies
VIEWS ON THIS POST

257

Posted on:

Monday 22nd October 2012
View Replies!

loading images in swings

Hi to all, I use JSplitpane to to split two panels(left and right), left panel contains JTree, right panel is loading the required images when i click the corresponding node in the JTree. images came from database . Based on the images length i created required JLables and set it to the images. Initially i am loading images in the right panel (i.e fine), But i am clicking the node in the JTree, right Panel images are not refreshed with new one. Please help me,
VIEWS ON THIS POST

226

Posted on:

Monday 22nd October 2012
View Replies!

Painting components over images

I've exteneded a JFrame and overridden it's paint() method because I want to draw an image in the background and then display a component on top of it (label, button, etc). But my component is not displaying in the right place. It only displays in the top left corner, even though I've set the location to something else. I don't think I'm painting it right somehow. Here's a snippet: JLabel label1 = new JLabel("hello"); label1.setSize(150, 50); label1.setLocation(200, 200); ... public void paint(Graphics g) { Graphics offScreenGraphics = offScreenImage.getGraphics(); offScreenGraphics.drawImage(myImage, 0, 0, 800, 600, 0, 0, 800, 600, this); paint(offScreenGraphics); label1.paint(offScreenGraphics); g.drawImage(offScreenImage, 0, 0, this); offScreenGraphics.dispose(); }
VIEWS ON THIS POST

236

Posted on:

Tuesday 23rd October 2012
View Replies!