Problems in generating a proper qr-code using zxing - java

i have a problem in generating proper qr-codes with the zxing api.
I am able to generate a qr-code but when i read the qr-code then chars like "äü" arent displayed right.
code:
BitMatrix matrix = writer.encode(text, BarcodeFormat.QR_CODE, 200,200);
//text is String text = "geändert";
bufferedImage = MatrixToImageWriter.toBufferedImage(matrix);
If i start with "ü" then followed by "äö" then its displayed correct
anyone knows why?

You can read the QR Code from zxing api from below code.
binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream("QR_Code.JPG")))));
result = new MultiFormatReader().decode(binaryBitmap);
System.out.println("QR Code : "+result.getText());

If you look at the developer documentation from zxing http://code.google.com/p/zxing/wiki/DeveloperNotes you will see that they expressly talk about the issue with non latin based characters.
As the QR Code standard does not define an exact way of specificing the character encoding within a QR code there recommendation is to only use characters which appear within all three standard encodings (ISO-8859-1, ISO-8859-15, UTF-8)

In the Hashtable of hints that you pass the encoder, set EncoderHintType.CHARACTER_SET to "UTF-8". Barry's answer is correct, but forcing it to try UTF-8 might happen to work better for you.

You can read the QR Code from zxing api from below code.
binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream("QR_Code.JPG")))));
result = new MultiFormatReader().decode(binaryBitmap);
System.out.println("QR Code : "+result.getText());

Related

Extract textual data from a PDF

I'm using a Java program to extract textual data from a PDF.
When I use this type of PDF I have no problem :
But when I use this type the extraction is not performed :
Have you any idea to resolve this problem?
Try using iText7 and following code:
File inputFile = new File("path_to_your_pdf");
PdfDocument pdfDocument = new PdfDocument(new PdfReader(inputFile));
String text = PdfTextExtractor.getTextFromPage(pdfDocument.getPage(1));
pdfDocument.close();
And let us know what the output is. And whether the output corresponds to what you'd expect.
As #mkl points out, this may simply be the the difference between extracting form-fields or not. In any case, the links to your pdfs would be much appreciated. As well as some code.
But you can of course extract both using iText.
Reading material:
http://developers.itextpdf.com/content/itext-7-examples/itext-7-form-examples
http://developers.itextpdf.com/content/itext-7-examples/itext-7-content-extraction-and-redaction

How do I generate a PDF417 Barcode with Java4Less?

For our standard PDF & Barcode generation, we have the Java4Less library (java4less-1.0rel.jar) so that our customers can print tickets sold to/by them. We use this library to create CODE128(C), Aztec, QR barcodes and so on.
Right now we're looking into PDF417 Barcodes; and while this library supports this generation, something isn't going right. Have a look at the following code from a small Netbeans project:
BarCode bc= new BarCode();
bc.setSize(400 , 200);
bc.barType = BarCode.PDF417;
bc.resolution=1;
bc.leftMarginCM= 50;
bc.topMarginCM= 50;
bc.checkCharacter =true;
bc.code = "THISISJUSTATESTTEXT";
bc.barColor = Color.black;
bc.backColor= Color.red;
bc.fontColor = Color.blue;
bc.textFont = new Font("Arial",Font.BOLD,14);
bc.X = 1;
bc.N = 3;
bc.paint(region);
ImageIO.write(img, "PNG", new File("barcode.png"));
This piece of code generates a .png image with the requested barcode-type. All barcodes are generated, except for the PDF417.
Here's an image that shows a CODE128 and a PDF417 generation:
As you can see, the CODE128 generates its barcode, but the PDF417 doesn't. The only thing changed in the code is the following:
bc.barType = BarCode.CODE128; --> bc.barType = BarCode.PDF417;
I've looked up the documentation, examples; I even downloaded the demo from the official Java4Less website, and in a war/Java project, it generates a PDF417 normally.
So what is going wrong here? Is it a bug in the library that anyone knows of, or am I missing a step?
It would seem that our current library, despite claiming to support PDF417 creation, was outdated. When using the demo's library I managed to succesfully create a PDF417 barcode with the previousley mentioned code.

Get cover art from a music file using JAudioTagger in Java

I'm using JAudioTagger to fetch the metadata from music files, getting the title, year etc is working fine but I am having a problem with getting the cover art. I have not been able to find any examples searching online, any help would be great!
Here is my current code, which the coverArt BufferedImage is showing up as null when debugging. I have checked and the mp3 file has a cover image.
ID3v23Tag id3v23Tag = (ID3v23Tag)tag;
TagField coverArtField =
id3v23Tag.getFirstField(org.jaudiotagger.tag.id3.ID3v23FieldKey.COVER_ART.getFieldName());
FrameBodyAPIC body = (FrameBodyAPIC)((ID3v23Frame)coverArtField).getBody();
byte[] imageRawData = (byte[])body.getObjectValue(DataTypes.OBJ_PICTURE_DATA);
coverArt = ImageIO.read(ImageIO.createImageInputStream(new ByteArrayInputStream(imageRawData)));
In my application I use
MP3File mp3;
mp3.getTag().getFirstArtwork();
which returns the firstArtwork of the MP3 (which is in most cases the cover you are looking for). This can be cast to a BufferedImage if necessary.
Anyone still looking for an answer can do this..
AudioFile f = AudioFileIO.read(new File(path));
Tag tag = f.getTag();
if(tag.hasField("Cover Art")){
byte[] b = tag.getFirstArtwork().getBinaryData();
}
Now you have your image in binary data. you can easily use it with glide or picasso if you want..
Glide.with(this).load(b).into(ImageView);
Normally, the easiest way is simply:
List<Artwork> existingArtworkList = tag.getArtworkList();
You don't have to perform any casting nor work at the frame body level. Is there are reason you are doing this?
Take a look at the imageRawData - is that being read correctly? Maybe the problem is at the imageio level. If it's a JPEG it should begin 0xFF, 0xD8 for example.

QR code decoding without using camera in java

** I am developing a Java Application for reading(decoding) QR Codes with out using camera in the laptop. I am using the ZXING JAR for the generation of QR Code.**
I am doing some manipulation for that QR Code. Now, I wanted to check whether the QR Code is fine or not with out using camera.
Is there any way it can be done?
ZXing has a JavaSE module which provides the crucial BufferedImageLuminanceSource for decoding a regular Java BufferedImage.
The bare minimum, extracted from ZXing's JavaSE DecodeThread:
BufferedImage image = ...
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = new MultiFormatReader().decode(bitmap);
If decode() doesn't throw an exception, ZXing was able to decode the barcode (and you can check the contents of the bar code).
http://zxing.org/w/docs/javadoc/com/google/zxing/Reader.html#decode(com.google.zxing.BinaryBitmap, java.util.Map)
You can configure the MultiFormatReader, e.g. to only parse QR codes, by using the decode(BinaryBitmap, Map<DecodeHintType,?> hints) overload, allowing you to specify any number of decoding hints. Alternatively, if you really only want QR codes, use a QRCodeReader instead of MultiFormatReader.

Wrong parsing with iText's PdfTextExtractor

I'm facing a problem when I try to read the content of a PDF document. I'm using iText 2.1.7 with Java, and I need to analyze the content of a PDF document: at first I was using the PdfTextExtractor's getTextFromPage method and it was working right, but only when the page is just text, if it contains an image, then the String that I get with the getTextFromPage is a set of meaningless symbols (maybe a different character encoding?), and I lose the content of the whole page. I tried with the last version of iText and works fine, but if I'm not wrong the license wouldn't be totally free (I'm working in a web application for a commercial customer, which serves PDFs on the fly) so I can't use it. I would really appreciate if you have any suggestion.
In case you need it, here is the code:
PdfReader pdf = new PdfReader(doc); //doc is just a byte[]
int pageCount = pdf.getNumberOfPages();
for (int i = 1; i <= pageCount; i++) {
PdfTextExtractor pdfTextExtractor = new PdfTextExtractor(pdf);
String pageText = pdfTextExtractor.getTextFromPage(i);
Thanks in advance, regards.
I think that you PDF has an inline image. I do not think that iText 2.1.7 will deal with that.
You can find information regarding the license here

Categories