I need Print file code in java
hi,
i am deveping the editor ,,,,,,,,we can edit the code in JEditorPane
i want to add the print functionality in it...........plz tell me....
Good Bye...
[http://en.wikipedia.org/wiki/Java2d|http://en.wikipedia.org/wiki/Java2d]
[http://en.wikipedia.org/wiki/Java3d|http://en.wikipedia.org/wiki/Java3d]
Similar Messages
-
Printing a Binary Print File from java
I would like to print a binary print file directly from java. The file is normally created when you print and choose "Print to file". I have not found any way of doing this. Could anyone help me out on this one.
Different printers use different binary formats to drive them. Different manufacturers, alas, use different codes.
Print to file typically dumps these printer codes to a file, and it requires a driver specific to the language the printer in question uses.
Now I'm not yet sure about how the java.awt.print stuff handles the different propriatry formats. It's clearly picking up stuff from the operating system to do the job (since it brings up system standard dialogs and options which Sun won't know about.)
It's clearly not going to extend easilly.
You can check out the attributes stuff in javax.print. Maybe there's one to divert print output. -
How to print pdf file by using java print API ? I am trying with this code
import java.io.FileInputStream;
import java.io.InputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSizeName;
public class PDFPrint {
static public void print(InputStream inputStream, PrintService printService) throws PrintException {
Doc doc = new SimpleDoc(inputStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(MediaSizeName.ISO_A4);
attributes.add(new Copies(1));
print(doc, attributes, printService);
}//print()
static public void print(Doc doc, PrintRequestAttributeSet attributes, PrintService printService) throws PrintException {
if (printService == null) {
printService = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("The Printer Name is :"+printService.getName());
DocPrintJob docPrintJob = printService.createPrintJob();
System.out.println("Before Print Start()");
docPrintJob.print(doc, attributes);
}//print()
public static void main(String args[])
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
String file="c:/BackUp/file.pdf";
FileInputStream fis=new FileInputStream(file);
System.out.println("Before Print() called ..");
print(fis,defaultPrintService);
System.out.println("After Printing....");
I am using this code to print pdf file. But when I try this one automatically the printer starting with print ascii codes with infinite loop.
I am using jdk1.4,Acrobat 8.0, Windows environment.
Can u help me in this regard'
Thank u
graniimport java.io.FileInputStream;
import java.io.InputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSizeName;
public class PDFPrint {
static public void print(InputStream inputStream, PrintService printService) throws PrintException {
Doc doc = new SimpleDoc(inputStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(MediaSizeName.ISO_A4);
attributes.add(new Copies(1));
print(doc, attributes, printService);
}//print()
static public void print(Doc doc, PrintRequestAttributeSet attributes, PrintService printService) throws PrintException {
if (printService == null) {
printService = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("The Printer Name is :"+printService.getName());
DocPrintJob docPrintJob = printService.createPrintJob();
System.out.println("Before Print Start()");
docPrintJob.print(doc, attributes);
}//print()
public static void main(String args[])
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
String file="c:/BackUp/file.pdf";
FileInputStream fis=new FileInputStream(file);
System.out.println("Before Print() called ..");
print(fis,defaultPrintService);
System.out.println("After Printing....");
I am using this code to print pdf file. But when I try this one automatically the printer starting with print ascii codes with infinite loop.
I am using jdk1.4,Acrobat 8.0, Windows environment.
Can u help me in this regard'
Thank u
grani -
Hi
I want to print a file txt in java. I use this code, but the printer receive an empty page. Why???
This is the code: (the fileLocation is right, I've checked this).
private void printFileTextPlain(String fileLocation){
// Attribute Set storage
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
// We're looking for PostScript-capable printers
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
// Return list of printers capable of printing PostScript
PrintService printService[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
// Get the default printer
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
// Display the print dialog with default printer selected
// --->>> CON DEFAULT PRINTER PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, null, flavor, pras);
// If user selected "OK"...
try{
if (service != null) {
// Create a print job
DocPrintJob job = service.createPrintJob();
InputStream is = new BufferedInputStream(new FileInputStream(fileLocation));
//JarInputStream jis = new java.util.jar.JarInputStream(new FileInputStream(new File(fileLocation)));
//jis.getNextEntry();
// Create storage for attributes
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(is, flavor, das);
// Print the job
job.print(doc, pras);
// Wait a few seconds for job to spool
Thread.sleep(10000);
is.close();
catch (IOException e) {
JOptionPane.showMessageDialog(null, "Errore nella generazione del file di stampa","Attenzione", JOptionPane.ERROR_MESSAGE);
//log error
log.error("printFile(): "+e.getMessage(),e);
catch (PrintException pe) {
JOptionPane.showMessageDialog(null, "Errore nella generazione del file di stampa","Attenzione", JOptionPane.ERROR_MESSAGE);
//log error
log.error("printFile(): "+pe.getMessage(),pe);
catch (InterruptedException ie) {
JOptionPane.showMessageDialog(null, "Errore nella generazione del file di stampa","Attenzione", JOptionPane.ERROR_MESSAGE);
//log error
log.error("printFile(): "+ie.getMessage(),ie);
}There is no speciall handling needed for unicode chars. Problam seems that the viewer that you are using to view the file does not support unicode or the font it is using is not a unicode fond which support chinese chars.
If you switch to a unicode supported viewer and chinese supported unicode font then you should ge the chars properly -
Need to find the source code for java.util.LinkedList
Hello all,
I'm new to the forums and I actually need the LinkedList source file as well as all the source files for all Java packages and libraries. Please post a link here if you can, or email me at [email protected]
Thanks again!
copter_manBut those must be platform dependant, not really that
interesting to look at. I have never felt any need to
look at those at least.Wake up and smell the coffee, abbie! I read the source code all the time and constantly tell my students to do that, too.
1. Java source code is not platform dependent. The original poster wanted to look at linked list code, how could that be platform dependent?
2. It is the implementation of the SDK APIs, so by definition it is implementation dependent code, liable to change in a later version. So don't assume anything beyond what is claimed in the API documentation. However, sometimes the documentation is incomplete or ambiguous to you, and reading the source can provide some insight, however implementation dependent. (Light a candle or curse the darkness.)
3. Why read source code? It's a good way to learn how to program. You see something in the API and ask: how'd they do that? Or you realize you want to do something broadly similar, but you can't reuse the source code.
For example, Images are not Serializable, but suppose you want a small image that is part of an object to be serialized with the rest of the object without too much fuss (ie, without using javax.imageio). You notice ImageIcon is serializable, so you use it. (An ImageIcon has-an Image.) Then you wonder: how'd they do that? You read the source and then you know.
You live, you learn,
Nax -
Hi All
I had one more urgent requirement
I need to put Print option in webdynpro java for to give print the entire table
So if the table have 30 records the entire records have to display with header details also
please give your inputs
Thanks
RenuHi All,
But in my screen I had one table and some other fields also
i want to print only the table not those fields
I given below code line but its giving entire page print , but I am not expecting that , I need only the table and with header details.
WDPrintService.getPrintService().print(wdControllerAPI);
Thanks
Renu -
Help needed while exporting crystal reports to HTML file format using java
Help needed while exporting crystal reports to HTML file format using java api(not using crystalviewer).i want to download the
html file of the report
thanksthe ReportExportFormat class does not have HTML format, it has got to be XML. Export to HTML is available from CR Designer only.
Edited by: Aasavari Bhave on Jan 24, 2012 11:37 AM -
I need an Array in my JAVA CODE
I need an array in my java code for my last class in my Java 1 course
my code does compile in dos using javac,....and it does work
It is a mortgage calculator for 3 loans of 3 different years loaned,.... and each have a different interest rate.
I need to have my code in an ARRAY for my last week .
any help would be appreciated
here is my code :
import java.text.*; //20 May 2008, Revision ...many
import java.io.IOException;
class memortgage //program class name
public static void main(String[] args) throws IOException
double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
double rate [ ] = {.0535, .055, .0575}; //the three interest rates
int [ ] term = {7,15,30}; //7, 15 and 30 year term loans
int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
char answer,test;
boolean validChoice;
System.in.skip(System.in.available()); //clear the stream for the next entered character
do
validChoice = true;
System.out.println("What Choice would you Like\n");
System.out.println("1-Interest rate of 5.35% for 7 years?"); //just as it reads for each to select from
System.out.println("2-Interest rate of 5.55% for 15 years?");
System.out.println("3-Interest rate of 5.75% for 30 years?");
System.out.println("4-Quit");
answer = (char)System.in.read();
if (answer == '1') //7 yr loan at 5.35%
ratePlace = 0;
firstIterate = 4;
secondIterate = 21;
totalMo= 84;
else if (answer == '2') //15 yr loan at 5.55%
ratePlace = 1;
firstIterate = 9; //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
secondIterate = 20; //now it is only of -0.40 cents....DAMN ME
totalMo = 180;
else if (answer == '3') //30 yr loan at 5.75%
ratePlace = 2;
firstIterate = 15;
secondIterate = 24;
totalMo = 360;
else if (answer == '4') //exit or quit
System.exit(0);
else
System.in.skip(System.in.available()); //validates choice
System.out.println("Invalid choice, try again.\n\n");
validChoice = false;
}while(!validChoice); //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)
for(int x = 0; x < 25; x++)System.out.println();
amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
moPay = (amount / totalMo);
totalInt = (principal * rate[ratePlace] * term[ratePlace]);
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
"% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
(df.format (moPay) + " Dollars a month\n\n"));
System.in.skip(System.in.available());
System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
answer = (char)System.in.read();
if (answer == 'y')
System.out.println((term[ratePlace]*12) + " monthly payments:");
String monthlyPayment = df.format(moPay);
for (int a = 1; a <= firstIterate; a++)
System.out.println(" Payment Schedule \n\n ");
System.out.println("Month Payment Balance\n");
for (int b = 1; b <= secondIterate; b++)
amount -= Double.parseDouble(monthlyPayment);
System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
System.in.skip(System.in.available());
System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
System.in.read();
}here is what was commented from my instructor for my week 4...is what you sen in the code....but I fixed loan 2 tonight
"Week 4 Great work, the numbers were a little off on the 1st and 2nd loans. Next time
try putting the values you displayed in an array. "
import java.text.*; //20 May 2008, Revision ...many
import java.io.IOException;
class memortgage //program class name
public static void main(String[] args) throws IOException
double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
double rate [ ] = {.0535, .055, .0575}; //the three interest rates
int [ ] term = {7,15,30}; //7, 15 and 30 year term loans
int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
char answer,test;
boolean validChoice;
System.in.skip(System.in.available()); //clear the stream for the next entered character
do
validChoice = true;
System.out.println("What Choice would you Like\n");
System.out.println("1-Interest rate of 5.35% for 7 years?"); //just as it reads for each to select from
System.out.println("2-Interest rate of 5.55% for 15 years?");
System.out.println("3-Interest rate of 5.75% for 30 years?");
System.out.println("4-Quit");
answer = (char)System.in.read();
if (answer == '1') //7 yr loan at 5.35%
ratePlace = 0;
firstIterate = 4;
secondIterate = 21;
totalMo= 84;
else if (answer == '2') //15 yr loan at 5.55%
ratePlace = 1;
firstIterate = 9; //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
secondIterate = 20; //now it is only of -0.40 cents....DAMN ME
totalMo = 180;
else if (answer == '3') //30 yr loan at 5.75%
ratePlace = 2;
firstIterate = 15;
secondIterate = 24;
totalMo = 360;
else if (answer == '4') //exit or quit
System.exit(0);
else
System.in.skip(System.in.available()); //validates choice
System.out.println("Invalid choice, try again.\n\n");
validChoice = false;
}while(!validChoice); //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)
for(int x = 0; x < 25; x++)System.out.println();
amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
moPay = (amount / totalMo);
totalInt = (principal * rate[ratePlace] * term[ratePlace]);
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
"% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
(df.format (moPay) + " Dollars a month\n\n"));
System.in.skip(System.in.available());
System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
answer = (char)System.in.read();
if (answer == 'y')
System.out.println((term[ratePlace]*12) + " monthly payments:");
String monthlyPayment = df.format(moPay);
for (int a = 1; a <= firstIterate; a++)
System.out.println(" Payment Schedule \n\n ");
System.out.println("Month Payment Balance\n");
for (int b = 1; b <= secondIterate; b++)
amount -= Double.parseDouble(monthlyPayment);
System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
System.in.skip(System.in.available());
System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
System.in.read();
} -
How to use .properties files in Webdynpro Java code?
Hi all,
I want to use a logon.properties file when I initial a JCO connection pool in my webdynpro DC (JCO.addClientPool()),but I found when I deployed this DC to the server, it always giv e me an FileNotFoundException. So I donot know how to deploy a .properties file to the server and how to access this file in my Java code?
Thans and Best regards
DeyangHi,
1) put .properties file to your packege under src\packages folder (src\packages\com\sdn\properties\jco.properties)
2) load property:
final InputStream is = getClass().getClassLoader().getResourceAsStream("com/sdn/properties/jco.properties");
final Properties properties = new Properties();
try
properties.load(is);
catch(Exception e)
wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
Regatds Maxim R. -
Why the need of "import" statements for Java base code?
If for documentation purposes, a compiler option to produce an "import list" would have been sufficient.
import statements act as really simple namespaces.
Instead of the programer having to specify:
java.io.File f = new java.io.File("c:\\");
the code can have a 'namespace' added to do the following:
import java.io.file;
File f = new File("c:\\);
it's a way of getting around similiarly named classes, but still have the ability to drop the 'java.io.' part. -
I need pdf files so I can export, not hard copy. When I 'print' then 'save as pdf', I get blank docs. Why? How can it be resolved?
Which version of Acrobat?
What app are you printing from?
Which version of Mac or Windows?
Do these seem to be normal PDF documents - but just blank pages? How many blank pages? -
How to read the contents of XML file from my java code
All,
I created an rtf report for one of my EBS reports. Now I want to email this report to several people. Using Tim's blog I implemented the email part. I am sending emails to myself based on the USERID logic.
However I want to email to different people other then me. My email addresses are in the XML file.
From the java program which sends the email, how can I read the fields from XML file. If any one has done this, Please point me to the right examples.
Please let me know if there are any exmaples/BLOG's which explain how to do this(basically read the contents of XML file in the Java program).
Thank You,
PadmaIke,
Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
Please help me.
Thank you for your posting.
Padma. -
i have a c util which i need to use in a java application do anyone has a clue?
check out the spec for JNI (java native interface)
You may save time tho just re-implementing in java -
Running a batch file in a java servlets programme
this is what i have
Process p = Runtime.getRuntime().exec("C:\\sync.bat");
Now i need a way for the program to wait until this is finished running. I dont want to print anything until this is done. Is there a way to do thisWill this even run sync.bat or do i have to do more.Here is my entire code
import java.io.*;
import java.io.File;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.*;
public class index_test extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<body>");
try
Process p = Runtime.getRuntime().exec("C:\\sync.bat");
String dir = "C:\\Perforce";
File what = new File(dir);
String [] listy = new String [100];
String [] products = new String[5];
String lists;
listy = what.list();
out.println("<form action =getBuilds Method = get>");
out.println("Please select which Product you wish to search in: ");
out.println("<br>");
int j = 0;
if(listy[j] != null)
products[j] = listy[j];
j++;
int i =0;
for(i = 0; i<listy.length && listy[i] !=null;i++)
out.println("<input type ='radio' name = 'product' value='"+dir+"\\"+products[i]+"\\build'>");
out.println(products);
out.println("<br>");
out.println("<input type ='submit' value ='Submit'>");
out.println("<br>");
catch(IOException e){}
out.println("<img src='C:\\tomcat4\\webapps\\Tracker\\dancing2.gif'>");
out.println("</form></body></html>");
What i need is to run sync.bat, wait till its finished then print out the folders in the Perforce directory. I can print out the contents of Perforce grand i just dont know how to run the batch file and get the progeam to wwait until its finished -
Hi,
I am in the process of trying to silently print PDFs via java in a Windows NT 4.0 environment. The solution so far has been to convert then into postscript files using pdftops (co/ xpdf) and then simply send the postscript file to the printer using the java PrintService.
Which would work fine except for the fact that I need to print envelopes (DL and C4) (not a problem but for the fact that some of the printers only have Postscript Level 2 Emulation and don�t recognize the fact that an envelope is being printed).
And I need to be able to print to a specific (i.e. default) tray on a network printer, and using the java PrintService uses the wrong tray.
Tried using JPedal and JPrint, and the get past the tray problem but haven�t tried them with the envelopes yet � can�t see that being a problem though.
Big question is does anybody have experience with print files from java to a specific tray on a network printer.
Thanks
Richard Petersduffymo
Acrobat 5.0 when I open a pdf on my system.
This is exactly the code currently in my program.
I just ran it again to test it and it works.
1) The application has an ugly square gray box on the screen while printing.
2) The Acrobat reader starts on the task bar.
3) For the application to continue I have to expand the reader and close it myself.
public void actionPerformed(ActionEvent e) {
String selectedDocument = SelectedDocument();
if (selectedDocument != null) {
try {
String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
Runtime rn = Runtime.getRuntime();
Process process = rn.exec(command);
process.waitFor();
catch (Exception pEX) {showSystemError("Unable to print document.", selectedDocument, pEX, false);}
}It is not what I wanted to do - I wanted to do the print
internally in the program.
rykk
Maybe you are looking for
-
How do I create custom field in MDM shopping cart preview screen (srm-mdm)
Hi Am on SRM 5.0 MDM 2.0. Requirement is 'temp labor'. i have a price form a specific supplier for a specific service is $80 in SRM_MDM internal catalog. But i talked to supplier and they have agreed on a new price of $75. After I select this catalog
-
Subscription to Myanmar 60 mins doesn't work, but ...
Hi, please help me to solve a problem with my subscription. I have paid for it 19th of March, and my order no is Order No. 595160215.But when I called to myanmar it was a note there that I overused my limit and subscribtion will start automatically 2
-
Anyone try larger (600-750G or higher) internal drives?
Have any new Mac Pro owners tried internal drives larger than the 500GB Apple-supplied drives? The 750GB Seagate, for example? I find my dual 2.5GB GB Mac does not handle larger external drives well, even with an extra PCI card wth added Firewire 800
-
Error in Complex Inbound Delivery
I am doing one complex inbound scenario. Did packing and unloading. then to automatic warehouse task to Deconsolidate, Putaway. warehouse task got confirmed. but in monitor IB01-unloading - c- completed IB03-Putaway - B -waiting IB02 i
-
What Color Space Should I Shoot In.
First, I'll admit that the entire color management aspect of photography/monitors/printing, is a bit too dense for me to completely comprehend. However, I do have some working knowledge of it. So, here's my pre-LR setup. I shoot in sRGB and used Phot