garfild Baram

Ranch Hand
+ Follow
since Mar 24, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by garfild Baram

Hi guys,
The PrintServiceLookup.lookupPrintServices method returns a list of all the installed printers. of all such installed (networked) printers how can one know whether a printer is switched off or disconnected?

my code:

public void lookupPrinter(String printerName) throws ModelException {

PrintService selectedPrintService = null;
PrintService[] services = PrintServiceLookup.lookupPrintService(DocFlavor.SERVICE_FORMATTED.PRINTABLE,null);
if(services.length>0){
int printerIndex=0;
for(int i=0; i<services.length;i++){
if (services[i].getName().equalsIgnoreCase(printerName)) {
selectedPrintService = services[i];
}
}
}


should I use PrinterState for that perpose or printerStateReason ? if so, how?

PrinterState pState = services[0].getAttribute(PrinterState.class); - Doesnt work, I get null all the time

Please advise

thanks a lot..
18 years ago
sorry for the trubles....

All files are executed ,I just looked for the results in the wrong place.

All good

Thanks

Yossi
18 years ago
Hi helper,
I use in my code:

Process p = Runtime.getRuntime().exec(scriptToRun);

and it runs file1.cmd that containes the following:

file1.cmd:

set ADVANTAG_FOLDER=c:\Yoss_test
RD /s /q %ADVANTAG_FOLDER%


but it doesnt run file2.cmd :-(

file2.cmd:

echo "after File " >> after.txt


Do you have a clue why file1 is executed and file2 is not. I dont get any errors at all.

Thanks
Yossi
18 years ago
Hi,
Can you advise me How to print an image to a roll printer that prints stickers size 40X30 mm size?
When I use MediaSizeName all attributes are portraite and I need landscape :-(
Each print should be at aspecific size, How can I set the size of a print?
Thanks
Yossi
18 years ago
thanks Joe, I have found the solution for that :-)
18 years ago
yes, you are right, we have the File[] ff = File.listRoots();
The question here is how to iterate all root folders for a search of my specific folder?
What is the function that lists the content of folders in each root?
thanks man
Yossi
18 years ago
Hi,
Till now I was using the following to find the existance of "myDirectory" directory:

File currentDir = new File("c:" + File.separator + myDirecory");
boolean dirExist = currentDir.isDirectory();

I would like to search myDirectoryon in my whole computer with just specifying its name (without a path).
Can I do that?

Thanks

Yossi
18 years ago
hey,
All I'm trying to do is to set through the code different settings for JAVA_HOME and PATH.
I have an installation kit and each compter has different settings.
Now I use a setEnv.cmd file:
System\Service\setx JAVA_HOME c:\j2sdk1.4.2_02 -m
set JAVA_HOME=c:\j2sdk1.4.2_02
System\Service\setx MYSQL_HOME c:\mysql -m
set MYSQL_HOME=c:\mysql
System\Service\setx path "c:\j2sdk1.4.2_02\bin;c:\Eldat Common Path;c:\perl\bin;%path%" -m
set path=c:\j2sdk1.4.2_02\bin;c:\Eldat Common Path;c:\perl\bin;%path%;


The problem here is the static addresses, If I set it in the code it can be dynamic.

Can I do it?

thanks
Yossi
18 years ago
guys,
How do I set Enviroment variables(JAVA_HOME,MYSQL_HOME...) and different addresses in the system Path using java code?
Thanks

Yossi
18 years ago
hey,
I need it to insert my.ini configuration file for mysql in the SystemRoot directory, which is different for win2k and Xp.
I found a way:

String s = null;

try
{
Process pr = Runtime.getRuntime().exec("CMD /c \"echo %systemroot%\"");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
if ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
catch (Exception e)
{
System.err.println ("Error ....");
}
}

Thaks any way

Yossi
18 years ago
Hi,
I need to retrieve SystemRoot variable value withing a java class.
I couldnt find a way to do it.
Can you help me here?
Thanks
Yossi
18 years ago
Hi,
I'm using Jasper reports tool to create images to print.

......
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A9);
....
....

MediaSize and MediaSizeName are javax.print.attribute.standard classes.
Using the MediaSize class doesnt let me set the image X axis longer then the Y axis (landscape orientation).
All MediaSizeName formats, Y axis is greater then X axis (portrait orientation).
Do you know how to overcome this problem?

Thanks guys

Yossi
I have found the way and it works great.

I get the image by using:

JasperPrint print = JasperFillManager.fillReport(Compiled_file, parameters, new JRTableModelDataSource(new JRStickerDataSource(stickers,0)));
Image image = JasperPrintManager.printPageToImage(print, 0, 2.0f);


private void createJpeg(Image image,String imageName){
try{
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(image, 0);
mediaTracker.waitForID(0);
// determine thumbnail size from WIDTH and HEIGHT
int thumbWidth = Integer.parseInt("90");// size in pixels
int thumbHeight = Integer.parseInt("80");//size in pixles
double thumbRatio = (double)thumbWidth / (double)thumbHeight;
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
double imageRatio = (double)imageWidth / (double)imageHeight;
if (thumbRatio < imageRatio) {
thumbHeight = (int)(thumbWidth / imageRatio);
} else {
thumbWidth = (int)(thumbHeight * imageRatio);
}
// draw original image to thumbnail image object and
// scale it to the new size on-the-fly
BufferedImage thumbImage = new BufferedImage(thumbWidth,thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
// save thumbnail image to OUTFILE
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("C:\\" +imageName + ".jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
param.setQuality(1.0f, false); // Best quality - 1.0f, Lowest quality - 0.0f
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
}
catch(Exception ex){
logger.error("Jasper Error:\n"
+"Check if the jrxml file is the right one or check that the parameters names idetical.\n"
+"System message - " + ex.getMessage());
}
}

Good luck

Jo
Hi,
Does anyone knows how to create a jpeg image using jasperreport object?

Thanks

Jo
hi,

I succeeded printing in Landscape by using
JasperPrintManager.printReport(jPrint, false).

OFFSET_X field only shifts the page horizentaly.

Thanks any way

Yossi