Free Support Forum - aspose.com

Re: How to reduce barcode image size?

Hi! I just downloaded Aspose a few days ago, and I wanted to say that I’m experiencing the same problem.

I’ll give the “webpage that outputs an image” idea you posed above a try… but I see in the documentation that at one point there was a BarCode Image Handler class. The documentation’s pretty sparse, and it says it’s obsolete (which makes me hesitate to use it).

However I imagine that such a handler class would accomplish the desired task effectively (that is, preventing multiple firings of the page_load event and multiple re-postings of the page to render the barcodes).

Is it a bad idea to try and use these HttpHandler objects? If not, is there some more documentation on them and how they can be used? Thanks!

Hi EdgarVerona,

Thank you for your post!

The BarCodeWebControl supports 3 RenderMethods: FromCache, FromSession, FromHttpHandler. You can select the RenderMethods by setting the RenderMethod property. Considering the advantage of convenient usage, we do not suggest the HttpHandler method, but if you are farmiler with the processing of HttpHandler and it's easy to modify the Web.config file in your application, you can also apply the FromHttpHandler Render Method.

1st. Set the BarCodeWebControl.RenderMethod property to be FromHttpHandler.

2nd.Modify the Web.config as showing below:

...



...

Then the barcode images will be generated by the BarCodeImageHandler class and other behavior will be the same.

Thanks

Would that prevent the multiple re-loading of the page? I’ll give it a shot and report the results here.

If this’ll help prevent the page from re-loading multiple times, it’s worth the extra effort I think… as long as this capability won’t go away in a future release! =) I was hoping I could just check for if IsPostBack was true and not process in that situation, but it seems that whenever the barcode control needs to re-render it does a whole new post (i.e. not a Post-Back).

I have a scenario where there’s a variable quantity of barcodes depending on some passed in information. In order to do this, I use a repeater and set the barcode’s image on databind. It works, but because of the repeater/databind and the fact that the barcode control in its default setting reposts the site every time one changes, I found that it reposts somewhere along the lines of N ^ 2 times (N being the number of barcodes on the page).

I haven’t been able to test it accurately yet because once I do the databind, the line-by-line debug in Visual Studio goes CRAZY (I think it’s sending multiple re-post requests at once, which confuses Visual Studio), but it’s definitely more than just N times. For instance, if I end up generating 3 barcodes, the page seems to refresh/repost at least 9 times before it displays. I think it’s because since it’s not a PostBack event, the repeater re-binds again which causes the barcode controls to set their value again, which causes another refresh… why it doesn’t do it infinitely many times, I don’t know… but it stops after a while and displays the page properly. It just refreshes (and consequently, queries my database during the databind process) too many times for my liking.

But anyways, I’ll go try the HttpHandler method and see if that smooths out this situation. Be back once I’ve got it figured out. =)

Fantastic! Using the HttpHandler was EXACTLY what I was looking for, thanks!

It didn’t attempt to re-post the page at all when rendering the barcodes: just went straight to the HttpHandler to generate the image. I highly support keeping HttpHandler support in Aspose.Barcode, as it’s extremely useful and helpful. Woot!

On a small side note, I had to change the web.config line from “BarCodeImageService.axd” (as you put in your example) to “BarCodeImageHandler.axd”… it wasn’t rendering when it was pointing to BarCodeImageService.axd, and when I investigated I realized that the control was looking for a “BarCodeImageHandler.axdto process it, not BarCodeImageService.axd.

Once I changed that, it worked like a charm. Thanks! I think you guys should consider re-adding this information into your documentation, as I imagine there may be many people like me who’d like to use the Barcode control without having the page re-post multiple times.

Hi EdgarVerona,

Thank you for your information and also sorry for my mistake :)

We will re-active the section of using Httphandler into the next version of document, thanks again.

No worries! Was but a small thing. =) I’m glad to hear that you guys will be putting it back in as a feature, it works very well! =)