Comments (4)
Hello! OpenPDF 2.0.2 is possibly the best PDF library for Java with a LGPL and MPL license.
See: https://github.com/zxing/zxing or find some other Java QR code library.
BarcodeQRCode was added in itext 5.0.2, while OpenPDF is a fork of iText 4 a long time ago.
https://github.com/itext/itextpdf/blob/master/itext/src/main/java/com/itextpdf/text/pdf/BarcodeQRCode.java
from openpdf.
Hi! Someone was provide me very nice response / answer, which was a lot helpfull, I i think this is removed, why?
from openpdf.
Hi! I have copied iTextPDF -> BarcodeQRCode and do changes what are required!
and implement here: OpenPDF\openpdf\src\main\java\com\lowagie\text\pdf\BarcodeQRCode.java
Note: It solve my problme, currently, but it will be more better, if this class official suported and implemented in OpenPDF Library, please!
package com.lowagie.text.pdf;
import java.awt.Color;
import java.awt.image.MemoryImageSource;
import java.util.Map;
import com.lowagie.text.BadElementException;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.codec.CCITTG4Encoder;
import com.lowagie.text.Rectangle;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.EncodeHintType;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.WriterException;
public class BarcodeQRCode {
private final BitMatrix bm;
public BarcodeQRCode(String content, int width, int height, Map<EncodeHintType, Object> hints) {
try {
QRCodeWriter qc = new QRCodeWriter();
bm = qc.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
} catch (WriterException ex) {
throw new ExceptionConverter(ex);
}
}
private byte[] getBitMatrix() {
int width = bm.getWidth();
int height = bm.getHeight();
int stride = (width + 7) / 8;
byte[] b = new byte[stride * height];
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
if (bm.get(x, y)) {
int offset = stride * y + x / 8;
b[offset] |= (byte) (0x80 >> (x % 8));
}
}
}
return b;
}
public Image getImage() throws BadElementException {
byte[] b = getBitMatrix();
byte g4[] = CCITTG4Encoder.compress(b, bm.getWidth(), bm.getHeight());
return Image.getInstance(bm.getWidth(), bm.getHeight(), false, Image.CCITTG4, Image.CCITT_BLACKIS1, g4, null);
}
// AWT related methods (remove this if you port to Android / GAE)
public java.awt.Image createAwtImage(Color foreground, Color background) {
int f = foreground.getRGB();
int g = background.getRGB();
java.awt.Canvas canvas = new java.awt.Canvas();
int width = bm.getWidth();
int height = bm.getHeight();
int pix[] = new int[width * height];
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
pix[y * width + x] = bm.get(x, y) ? f : g;
}
}
java.awt.Image img = canvas.createImage(new MemoryImageSource(width, height, pix, 0, width));
return img;
}
public void placeBarcode(PdfContentByte cb, Color foreground, float moduleSide) {
int width = bm.getWidth();
int height = bm.getHeight();
cb.setColorFill(foreground);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
if (bm.get(x, y)) {
cb.rectangle(x * moduleSide, (height - y - 1) * moduleSide, moduleSide, moduleSide);
}
}
}
cb.fill();
}
public Rectangle getBarcodeSize() {
return new Rectangle(0, 0, bm.getWidth(), bm.getHeight());
}
}
And maven dependency: OpenPDF\openpdf\pom.xml
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.5.3</version>
</dependency>
from openpdf.
@ctoabidmaqbool
just to be sure. You want to create QR-Codes, right? There are many implementations of Barcodes in OpenPDF, but as @andreasrosdal mentioned, the QR-Code aren't part of OpenPDF.
And copying the implementation of iText is not an option. So we need a new fresh implementation, where we can probably use some library.
There are some libraries which implement already QR-Codes. ZXing seems to be the most popular one.
At the other hand we want to keep the number of dependencies small.
So we need a fresh implementation using an optional dependency, or let the users use ZXing on their side, using e.g. a code like the one you posted here.
from openpdf.
Related Issues (20)
- Nested Lists in ColumnText not rendered correctly
- [bug] ERROR: Infinite table loop HOT 2
- PdfCopy cannot be used for writing HOT 1
- Streamlining Chunk Addition in ColumnText Without Storing All in JVM HOT 5
- Handling Row Content Splitting in PdfPTable.writeSelectedRows() HOT 3
- font can't display Complete when text length greater than pdf edit box length HOT 2
- Is OpenPDB library is fully supported on Android? HOT 3
- Support for Circular Shaped Images HOT 1
- Does OpenPDF support multiThreadding ? HOT 1
- Opening a file with `PdfReader` (or `RandomAccessFileOrArray`) keeps the file locked after `close()` HOT 1
- Print large text cells that exceed the remaining height of one page of paper starting from the second page rather than from the remaining height of the first page HOT 1
- Prevent leading from affecting the first cell HOT 2
- Unable to insert text in Identity-H encoding using a subset font file HOT 2
- Please provide Android support for GrallVM native-image feature; HOT 1
- Is there html to pdf capability HOT 2
- Japanese symbols are not rendered into PDF file HOT 14
- Rendering Multi lingual Text HOT 1
- Example code for RadioCheckField HOT 1
- "Unknown encryption type R = 5" HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openpdf.