Implementing QR and Barcode scanner and converting result to PDF in PDF CONVERTER Android App
Repository
https://github.com/Swati4star/Images-to-PDF
PDF Convertor
https://play.google.com/store/apps/details?id=swati4star.createpdf
PDF CONVERTER is an easy to use application to convert Images to PDF. This is basically an images to PDF Converter. The simplicity of this app makes it an ultimate PDF Converter for your device.
New Features
- What feature(s) did you add?
Added new feature to scan QR or Barcodes and convert the result in PF format. - How did you implement it/them?
As mentioned xzing in the task request by project owner, I considered the mobile version of zxing. Here is the implementation details. Zxing is an popular QR and barcode scanner open source library.
ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.
Created QrBarcodeScanFragment frament which will open camera based on user selection i. e. QR or Barcode. The scan result captured was initially written to a TEMP text file and later converted to PDF using existing implementation of the app.
File mDir = getContext().getCacheDir();
File mTempFile = new File(mDir.getPath() + "/" + mTempFileName);
PrintWriter mWriter = null;
try {
mWriter = new PrintWriter(mTempFile);
mWriter.print("");
mWriter.append("Result : " + result.getContents());
mWriter.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Uri uri = Uri.fromFile(mTempFile);
resultToTextPdf(uri);
Methods to open Camera to scan QR and Barcodes.
/**
* Open camera for Barcode Scan
*/
public void openCameraForBarcode() {
IntentIntegrator integrator = IntentIntegrator.forSupportFragment(this);
// use forSupportFragment or forFragment method to use fragments instead of activity
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt(mActivity.getString(R.string.scan_barcode));
integrator.setScanningRectangle(1000, 450);
integrator.setResultDisplayDuration(0); // milliseconds to display result on screen after scan
integrator.setCameraId(0); // Use a specific camera of the device
integrator.initiateScan();
}
/**
* Open camera for QRCode Scan
*/
public void openCameraForQrcode() {
IntentIntegrator integrator = IntentIntegrator.forSupportFragment(this);
// use forSupportFragment or forFragment method to use fragments instead of activity
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt(mActivity.getString(R.string.scan_qrcode));
integrator.setScanningRectangle(600, 600);
integrator.setResultDisplayDuration(0); // milliseconds to display result on screen after scan
integrator.setCameraId(0); // Use a specific camera of the device
integrator.initiateScan();
}
Converting text to PDF and preview..
/**
* Generate Result to PDF
* @param uri
*/
private void resultToTextPdf(Uri uri) {
new MaterialDialog.Builder(getActivity())
.title(R.string.creating_pdf)
.content(R.string.enter_file_name)
.input(getString(R.string.example), null, (dialog, input) -> {
if (StringUtils.isEmpty(input)) {
showSnackbar(getActivity(), R.string.snackbar_name_not_blank);
} else {
final String inputName = input.toString();
if (!mFileUtils.isFileExist(inputName + getString(R.string.pdf_ext))) {
createPdf(inputName, uri);
} else {
MaterialDialog.Builder builder = createOverwriteDialog(getActivity());
builder.onPositive((dialog12, which) -> createPdf(inputName, uri))
.onNegative((dialog1, which) -> resultToTextPdf(uri))
.show();
}
}
})
.show();
}
Thank you for your contribution. It's good to see you are taking the Features Request and working on it. Improving the code commenting would have been better. Since you are writing the file in a temp location, are you deleting the file after convert also before writing are you checking is the device has the required storage capacity.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Thank you for reviewing, Since we don't have implementation from converting direct text in PDF Converter so as of now we just added TEMP file just to read QR/Barcode result, every time its scans its gonna clear and add new result to it. Yes its not right approach soon i'm modifying core class to handle this operation.
Thank you for your review, @codingdefined!
So far this week you've reviewed 1 contributions. Keep up the good work!
Hey, @hiremani!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Hi @hiremani!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server