SEARCH YOUR SOLUTION HERE  

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:  2348
View Complete with Replies




Related Messages:

problem in printing swing components?   (290 Views)
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); } }
Java code printing junk characters in PDF   (224 Views)
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.
printing JTables - concatenating? what about the panels?   (356 Views)
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); }
Simple text printing with pagebreaks   (285 Views)
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
printing a jtable   (300 Views)
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
JTable printing problem   (311 Views)
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); } }); } }
Problem in printing JTable values   (282 Views)
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);
printing on A4 paper   (417 Views)
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 ------------------
printing html and images using JEditorPane   (263 Views)
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
printing data from JEditor Pane   (224 Views)
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:
printing html file   (233 Views)
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.
printing jframe content in core java   (265 Views)
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.
JTable printing . . .   (233 Views)
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.
Facing problems printing a ScrolledComponent in SWT   (228 Views)
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 .
problem in printing to file (JSE 6)   (229 Views)
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"); }
Help with reprinting downloaded text from FTP site onto GUI!   (203 Views)
*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!
Problem in printing Jpanel Data   (245 Views)
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); } }
how to convert byte array to images   (251 Views)
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
loading images in swings   (221 Views)
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,
Painting components over images   (228 Views)
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(); }