I have some pdf content which i retrieved from the API and i converted it using webcontent_converter package. But when i try to download it, it is throwing error or not downloading.
here is the code:
var dir = await getApplicationDocumentsDirectory();
var savedPath = "${dir.path}/$title.pdf";
var result = await WebcontentConverter.contentToPDF(
content: content,
savedPath: savedPath,
format: PaperFormat.a4,
margins:
PdfMargins.px(top: 55, bottom: 55, right: 55, left: 55),
);
I can convert the above result into file by :
File file = File(result!)
but how can i download the file?
Related
I am using 'cz.adaptech.tesseract4android:tesseract4android:4.3.0' in my Android project.
Is it possible to get bounding box with text data like in example below?
(32, 24, 60, 17) Maitre
(100, 24, 82, 19) corbeau,
(191, 28, 29, 13) sur
(227, 28, 22, 12) un
(257, 24, 50, 17) arbre
(315, 24, 70, 21) perché,
(79, 49, 58, 17) Tenait
Official sample shows how to get plain text only, not boxes with text inside:
TessBaseAPI tess = getTessBaseAPI(path, context);
String text = tess.getUTF8Text();
To get bounding box with text use next code:
TessBaseAPI tess = new TessBaseAPI();
// Given path must contain subdirectory `tessdata` where are `*.traineddata` language files
String dataPath = context.getExternalFilesDir(null).getPath() + "/OCRme/";
// Initialize API for specified language (can be called multiple times during Tesseract lifetime)
if (!tess.init(dataPath, "eng", TessBaseAPI.OEM_TESSERACT_LSTM_COMBINED)) {
throw new IOException("Error initializing Tesseract (wrong data path or language)");
}
// Specify image and then recognize it and get result (can be called multiple times during Tesseract lifetime)
tess.setImage(bitmap);
tess.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
tess.getUTF8Text();
ResultIterator resultIterator = tess.getResultIterator();
List < Rect > boxes = new ArrayList < > ();
List < String > texts = new ArrayList < > ();
while (resultIterator.next(TessBaseAPI.PageIteratorLevel.RIL_WORD)) {
Rect rect = resultIterator.getBoundingRect(TessBaseAPI.PageIteratorLevel.RIL_WORD);
String text = resultIterator.getUTF8Text(TessBaseAPI.PageIteratorLevel.RIL_WORD);
boxes.add(rect);
texts.add(text);
}
At first, I am converting a PDF file to Image file.
Then I make changes on the Image(converted PDF).
Now, I want to convert everything back to PDF and also have a copy in a base64 format of the PDF.
This is how I convert my PDF:
Future<List<List<int>>> imageFromPdfFileFullImage(
Future<PdfDocument> pdfFile) async {
int height = 0, width = 0;
final document = await pdfFile;
im.Image imImage;
for (int i = 1; i <= document.pagesCount; i++) {
final page = await document.getPage(i);
final pdfPageImage = await page.render(
width: page.width, height: page.height, format: PdfPageFormat.JPEG);
imImage = im.decodeJpg(pdfPageImage.bytes); // First issue in this line
height += imImage.height;
if (imImage.width > width) {
width = imImage.width;
}
//List<Image> buffer 'package:image/image.dart'
imageList.add(imImage);
//List<List<int>> 'package:image/image.dart' as im
//I want this encodeImaegList to be converted back to PDF later
encodeImageList.add(im.encodePng(imageList[i - 1]));
await page.close();
}
return encodeImageList;
}
This may be useful for those who's looking to convert some pdf files to images.
I hope you can help me on my problem too. Thanks guys!
Try this package, hope it helps
https://pub.dev/packages/pdf
I am trying to send Base64 data as string to another page using NavController using below code:
ConvertHTMLToPDF = () => {
let htmlGrid = document.getElementById('customContent');
const options = {background: "white", height: htmlGrid.clientHeight, width: htmlGrid.clientWidth};
html2canvas(htmlGrid, options).then((canvas) => {
let doc = new jsPDF("p", "mm", "a4");
let imgData = canvas.toDataURL("image/PNG");
//Add image Canvas to PDF
doc.addImage(imgData, 'PNG', 20, 20);
let pdfData = doc.output('datauri');
let obj = {PDFSrc: pdfData};
this.navCtrl.setRoot('SaveConsentLetterPage', obj);
});
};
This is perfectly working when the Base64 data is small in size like 3Kb or 4Kb. But, when the data is like 1.2Mb, the NavController can redirect to SaveConsentLetterPage. It crashes the application.
Why is that? Is there any limit to send data with setRoot to another page in Ionic 2/3?
Actually the problem was with below line:
let pdfData = doc.output('datauri');
This opens the data uri/pdfData in current window and as a result, preventing to go the next page.
But, below line returns only the data uri string and as a result, can easily pass the data to next page.
doc.output('datauristring');
Hello smartface community,
I need help to convert the base64 string back to image in smartface.io.
For example, following code converts image to base64
var img = new SMF.Image(e.file);
var blob = img.getBlob();
var base64StringDataForRegisterImage = blob.toBase64String();
Now I have another page where I am receiving base64 string from webservice but I am not able to convert it to image to assign to image control.
Please assist with the working code to achieve same.
Thanks
You can directly assign your base64 string to the SMF.UI.image object's image property.
Let say you have an image object named imgProfilePic on Page2.
var myBase64StringFromWebservice = (...) // base64 string from your service
var imgProfilePic = new SMF.UI.Image({
top: "20%",
left: "15%",
height: "20%",
width: "70%",
image: myBase64StringFromWebservice,
imageFillType: SMF.UI.ImageFillType.stretch
});
Pages.Page2.add(imgProfilePic);
BMP image is here: https://www.filepicker.io/api/file/fdsYv4NSaCGUefBAQmER
And the code to reproduce the failure:
var fpfile = { url: 'https://www.filepicker.io/api/file/fdsYv4NSaCGUefBAQmER',
filename: 'customers.jpg', mimetype: 'image/jpeg', isWriteable: false, size: 629454};
console.log("Converting...");
/*an element where we can display the resulting image*/
var result = document.getElementById("convert-result");
filepicker.convert(fpfile, {width: 200, height: 200},
function(new_FPFile){
console.log(new_FPFile.url);
result.src = new_FPFile.url;
}
);
Unclear what I am doing wrong here, any help would be most appreciated.
thanks
We don't currently support .bmp's for conversion, but we're in the process of adding it.