You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dane Laverty <da...@chemeketa.edu> on 2008/10/14 21:09:33 UTC

Trouble printing image

I'm adding an image to my page with the following code. It works
correctly, and the image displays fine. However, we are getting reports
from some IE users that the image will not print. It prints fine for
most IE users, but there are a handful who can't get it to print. 

 

While I don't know the reason, I did notice that when you right-click
the image and "Save As...", it doesn't have a name. In IE, the Save As
dialog calls it "untitled.bmp" (in spite of it being a png) and in
Firefox it's "print.png". Perhaps this is the source of the issue? If
so, how do you give an image a name when you're adding it as a Resource?

 

(For anyone who's interested in looking, you can find the offending
image at http://foodhandler.org. Log in with username/password
"guest/guest". Then click the "Print Your Card" button on the navigation
bar. When you print the page, the only two images that should print are
the "Thawte 100% Secure" image at the top of the page and the card image
in the center of the page - the rest are turned off in a print
stylesheet.)

 

PrintPage.java:

 

public class PrintPage extends NavigationTemplate

{

      public PrintPage()

      {

            Resource cardImage = getBothCardImageResource();

            add(new NonCachingImage("bothCardImage", cardImage));       

            

      }

 

      public Resource getBothCardImageResource()

    {

        final BufferedDynamicImageResource resource = new
BufferedDynamicImageResource();

        BufferedImage image;

                

        try {

            image = ImageIO.read(((WebApplication)
Application.get()).getServletContext().getResourceAsStream("/path/to/MyI
mage.png"));

                  

            Graphics graphics = image.getGraphics();

            ... Do some stuff with the graphics ...

        }

        

        resource.setImage(image);

        return resource;              

    }

}


RE: Trouble printing image

Posted by Dane Laverty <da...@chemeketa.edu>.
I should have said that your class worked great for displaying the
image; it just didn't keep the image name. Well, time to study up on
Serkan's suggestion on Content-Disposition and see what that does.

-----Original Message-----
From: James Carman [mailto:james@carmanconsulting.com] 
Sent: Tuesday, October 14, 2008 2:31 PM
To: users@wicket.apache.org
Subject: Re: Trouble printing image

Yeah, sorry about that.  I think the FileUtils class is one of my own,
actually (from work or I'd just give it to you).  I leave it up to the
reader to write the file copy method. :)


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trouble printing image

Posted by James Carman <ja...@carmanconsulting.com>.
Yeah, sorry about that.  I think the FileUtils class is one of my own,
actually (from work or I'd just give it to you).  I leave it up to the
reader to write the file copy method. :)

On Tue, Oct 14, 2008 at 4:35 PM, Dane Laverty <da...@chemeketa.edu> wrote:
> Thanks for the hint. I tried your class with some minor modifications
> (see below -- I commented out two lines and used the Apache FileUtils,
> since I'm not sure which FileUtils class your referenced) but without
> any success. However, while playing with that, I did notice that
> untitled.bmp that IE returns is 4+ MB, as compared to 200 KB for the
> print.png that FireFox returns. I'm not sure what that means, but it
> seems odd to me that the file returned would be browser-specific.
>
> Thanks again,
>
> Dane
>
> Modified FileImageResource class:
>
> public class FileImageResource extends DynamicImageResource
>        {
>            private static final long serialVersionUID = 1L;
>            private final String path;
>
>            public FileImageResource( File file, String format )
>            {
>                super(format);
>                this.path = file.getAbsolutePath();
>                //setCacheable(true);
>
> //setLastModifiedTime(Time.valueOf(file.lastModified()));
>            }
>
>            protected byte[] getImageData()
>            {
>                try {
>                        return FileUtils.readFileToByteArray(new
> File(path));
>                } catch (IOException ioe) {
>                        logger.error("Trouble reading the image file.",
> ioe);
>                        return null;
>                }
>            }
>        }
>
> -----Original Message-----
> From: James Carman [mailto:james@carmanconsulting.com]
> Sent: Tuesday, October 14, 2008 12:16 PM
> To: users@wicket.apache.org
> Subject: Re: Trouble printing image
>
> Try the FileImageResource class mentioned here (by me :):
>
> http://www.nabble.com/Mount-files-outside-container-td19232069.html
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Trouble printing image

Posted by Dane Laverty <da...@chemeketa.edu>.
Thanks for the hint. I tried your class with some minor modifications
(see below -- I commented out two lines and used the Apache FileUtils,
since I'm not sure which FileUtils class your referenced) but without
any success. However, while playing with that, I did notice that
untitled.bmp that IE returns is 4+ MB, as compared to 200 KB for the
print.png that FireFox returns. I'm not sure what that means, but it
seems odd to me that the file returned would be browser-specific.

Thanks again,

Dane

Modified FileImageResource class:

public class FileImageResource extends DynamicImageResource
	{
	    private static final long serialVersionUID = 1L;
	    private final String path;

	    public FileImageResource( File file, String format )
	    {
	        super(format);
	        this.path = file.getAbsolutePath();
	        //setCacheable(true);
	
//setLastModifiedTime(Time.valueOf(file.lastModified()));
	    }

	    protected byte[] getImageData()
	    {
	        try {
	        	return FileUtils.readFileToByteArray(new
File(path));
	        } catch (IOException ioe) {
	        	logger.error("Trouble reading the image file.",
ioe);
	        	return null;
	        }
	    }
	}

-----Original Message-----
From: James Carman [mailto:james@carmanconsulting.com] 
Sent: Tuesday, October 14, 2008 12:16 PM
To: users@wicket.apache.org
Subject: Re: Trouble printing image

Try the FileImageResource class mentioned here (by me :):

http://www.nabble.com/Mount-files-outside-container-td19232069.html


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trouble printing image

Posted by James Carman <ja...@carmanconsulting.com>.
Try the FileImageResource class mentioned here (by me :):

http://www.nabble.com/Mount-files-outside-container-td19232069.html


On Tue, Oct 14, 2008 at 3:09 PM, Dane Laverty <da...@chemeketa.edu> wrote:
> I'm adding an image to my page with the following code. It works
> correctly, and the image displays fine. However, we are getting reports
> from some IE users that the image will not print. It prints fine for
> most IE users, but there are a handful who can't get it to print.
>
>
>
> While I don't know the reason, I did notice that when you right-click
> the image and "Save As...", it doesn't have a name. In IE, the Save As
> dialog calls it "untitled.bmp" (in spite of it being a png) and in
> Firefox it's "print.png". Perhaps this is the source of the issue? If
> so, how do you give an image a name when you're adding it as a Resource?
>
>
>
> (For anyone who's interested in looking, you can find the offending
> image at http://foodhandler.org. Log in with username/password
> "guest/guest". Then click the "Print Your Card" button on the navigation
> bar. When you print the page, the only two images that should print are
> the "Thawte 100% Secure" image at the top of the page and the card image
> in the center of the page - the rest are turned off in a print
> stylesheet.)
>
>
>
> PrintPage.java:
>
>
>
> public class PrintPage extends NavigationTemplate
>
> {
>
>      public PrintPage()
>
>      {
>
>            Resource cardImage = getBothCardImageResource();
>
>            add(new NonCachingImage("bothCardImage", cardImage));
>
>
>
>      }
>
>
>
>      public Resource getBothCardImageResource()
>
>    {
>
>        final BufferedDynamicImageResource resource = new
> BufferedDynamicImageResource();
>
>        BufferedImage image;
>
>
>
>        try {
>
>            image = ImageIO.read(((WebApplication)
> Application.get()).getServletContext().getResourceAsStream("/path/to/MyI
> mage.png"));
>
>
>
>            Graphics graphics = image.getGraphics();
>
>            ... Do some stuff with the graphics ...
>
>        }
>
>
>
>        resource.setImage(image);
>
>        return resource;
>
>    }
>
> }
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Trouble printing image

Posted by Dane Laverty <da...@chemeketa.edu>.
This ended up working for Firefox, but not for IE. The image served in
Firefox will Save As "x.png", but the image in IE still shows as
"untitled.bmp". Thanks for the suggestion though, it at least taught me
a lot about resources and setting headers :)

Dane

-----Original Message-----
From: Serkan Camurcuoglu [mailto:serkanc@telenity.com] 
Sent: Tuesday, October 14, 2008 12:25 PM
To: users@wicket.apache.org
Subject: Re: Trouble printing image


while serving the image resource, setting the Content-Disposition http
header
to

inline; filename=x.png

might help, but this is just a guess..


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trouble printing image

Posted by Serkan Camurcuoglu <se...@telenity.com>.
while serving the image resource, setting the Content-Disposition http header
to

inline; filename=x.png

might help, but this is just a guess..





Dane Laverty wrote:
> 
> I'm adding an image to my page with the following code. It works
> correctly, and the image displays fine. However, we are getting reports
> from some IE users that the image will not print. It prints fine for
> most IE users, but there are a handful who can't get it to print. 
> 
>  
> 
> While I don't know the reason, I did notice that when you right-click
> the image and "Save As...", it doesn't have a name. In IE, the Save As
> dialog calls it "untitled.bmp" (in spite of it being a png) and in
> Firefox it's "print.png". Perhaps this is the source of the issue? If
> so, how do you give an image a name when you're adding it as a Resource?
> 
>  
> 
> (For anyone who's interested in looking, you can find the offending
> image at http://foodhandler.org. Log in with username/password
> "guest/guest". Then click the "Print Your Card" button on the navigation
> bar. When you print the page, the only two images that should print are
> the "Thawte 100% Secure" image at the top of the page and the card image
> in the center of the page - the rest are turned off in a print
> stylesheet.)
> 
>  
> 
> PrintPage.java:
> 
>  
> 
> public class PrintPage extends NavigationTemplate
> 
> {
> 
>       public PrintPage()
> 
>       {
> 
>             Resource cardImage = getBothCardImageResource();
> 
>             add(new NonCachingImage("bothCardImage", cardImage));       
> 
>             
> 
>       }
> 
>  
> 
>       public Resource getBothCardImageResource()
> 
>     {
> 
>         final BufferedDynamicImageResource resource = new
> BufferedDynamicImageResource();
> 
>         BufferedImage image;
> 
>                 
> 
>         try {
> 
>             image = ImageIO.read(((WebApplication)
> Application.get()).getServletContext().getResourceAsStream("/path/to/MyI
> mage.png"));
> 
>                   
> 
>             Graphics graphics = image.getGraphics();
> 
>             ... Do some stuff with the graphics ...
> 
>         }
> 
>         
> 
>         resource.setImage(image);
> 
>         return resource;              
> 
>     }
> 
> }
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trouble-printing-image-tp19980180p19980423.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org