Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding 2d barcode to a pdf using Java  RSS feed

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an application in Java which generates PDF reports. Currently it does not have barcode. Now I have to add a 2d barcode in that pdf reports.
I have checked in google and found links where Barcode4j jar generates 2d barcode as an image. But i could not see any explanation on how to add the bar code to a pdf file.
Please guide me on this. Thanks !!!
 
Sheriff
Posts: 23505
46
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you run the barcode application and now you have an image (which looks like a bar code). What you need next is a way to insert an image into a PDF file. So that's what you should be looking for.
 
murali jackson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Sorry for late reply .
I have added the image to my pdf using below method. It is working but the image quality is not good.
Is there any other efficient way of adding 2d barcode to pdf.  Please throw some light . Thanks !!!

 
Bartender
Posts: 19372
87
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a true "bar" code (1-D), you generally include a barcode font in the document properties and simply print the barcode value as text using that font.

For a 2-D scan code such as QR-code, you cannot do that because the data is "holographic". That is, it's not linearly laid out in a way that works with typesetting operations. So you have to generate an image. For best display/print quality, it would be a scalable image, but if not, a regular image will have to do. TIFF is the raster format used in PDFs.

Not much you can do to optimize that - you just load or generate the code image into RAM then output it into the PDF document. The biggest efficiency hit would come if your image scale wasn't optimal for the PDF. In which case a lot of computations would be required to resize it to fit. But you can avoid that by sizing your image properly.

Going back to choice of scalable versus raster (bitmap) image formats, scalable looks better, but does extract a price when displayed, since a complex drawing program must be executed. Bitmap scaling is usually faster (it depends on image complexity), but fuzzier.
 
murali jackson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for the detailed explanation !!!  As i am new to this kind of functionalities in java, im finding it little bit hard to understand your quotes.
Please explain.

The biggest efficiency hit would come if your image scale wasn't optimal for the PDF.



When you said image scale wasn't optimal, did you mean the size of the image is large to fit into a position in pdf ?


scalable looks better, but does extract a price when displayed, since a complex drawing program must be executed



I am having this basic question, what is scalable image and raster image ?

since a complex drawing program must be executed



Can you please give me any sample program on how to draw a barcode image. Im not asking for a complete program for my question, just  kind of a basic tutorial  drawing function from which i can learn and  write my own drawing method.
Thanks !!!


 
Tim Holloway
Bartender
Posts: 19372
87
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I say that the image size isn't optimal for the PDF, I mean that you have to re-size it to fit the desired page geometry. That could involve shrinking a larger image or it could involve expanding a smaller image. Neither is desirable, since scaling not only consumes computing resources, it also tends to distort the image.

There are basically 2 types of graphics systems. One is scalable, one is bitmap (raster). There's also something called vector graphics, but you probably won't run into that in modern systems.

Raster graphics is what you get on your terminal and on your printer. The image is made up of discrete pixels. This is what you find in a Windows BMP file, GIFs, JPEGs (more or less), and most other "picture" formats.

Scalable graphics are produced not by a data map, but by a set of instructions. For example, "draw a circle", "draw a line from here to there". Often the target device is actually raster-based (for example, your computer monitor), but by defining the image as a "program" instead of as simple data, you can run that program (render) optimized for the particular resolution, color capabilities, etc., of the display (or printer, or whatever). That means no fuzzy stuff, little or no jagged lines, and so forth. Samples of scalable graphics include Windows Metafiles, SVG (Scalable Vector Graphics) images, which can be produced by such programs as InkScape and displayed on web pages, most of the CAD program formats, and PostScript - the underlying language for PDFs.

I should note that many of the scalable formats include the ability to embed raster images in the "program", so that's how you can, for example, paste a photographic image into a PDF, even though the PDF is PostScript.

As far as barcode images go, it depends on which code you are using. I don't actually know how to render a QR code myself. There's a website I can go to, paste in text and it allows me to generate a downloadable image file. Your best bet, actually, is to find a ready-to-use barcode generation library and for that I'll have to leave you to the tender mercies of Google or whatever your preferred web search engine may be. Try looking for "java xxx library" where "xxx" is the bar code format you want (for example "QR Code").
 
murali jackson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for the detailed explanation !!!
I will try to get the library for my requirement and update the status here shortly. Thanks !!!

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!