Open albinotonnina opened 10 years ago
Google drive preview:
Hi Albino, you solved the problem with this?
//var dims = getJpegSize(imageData);
Hi, not yet. for iOS I can do this: var imageView = Ti.UI.createImageView({image:imageData, width:"auto", height:"auto"}); var imageW = imageView.toImage().width,imageH = imageView.toImage().height;
but that's not good for Android.
Hi Albino, how did you manage to fix this for iOS? Just by adding the code above? I'm having similar troubles in that my PDF is fine when viewed in OSX Preview and on the iPad itself, but when viewing in Acrobat on a Mac or PC the images are missing. It's driving me nuts!
Exactly, just by adding the code above, try! But I don't have missing images, i have just distorted images (screenshot above). Android is still a problem...a very ugly fix is: create a imageview with your image, add it to a window, wait for some milliseconds, get size using toImage() function, then remove the imageview and then do the rest. very bad :)
All that's doing is crashing the app on the device - whereabouts are you adding it to? Underneath //var dims = getJpegSize(imageData);?
yes!
Doing that crashes the app on the device, although it's fine on the simulator. I did notice though that when I made some of my images smaller, they did display (albeit it distorted like yours were) so maybe they're not actually missing, but are still there.
I believe you, though it doesn't crash on my iphone 5s.
New iPad Mini I'm using. Some of my images are pretty large though and I'm shrinking them down quite a lot to make the text on the PDF nice and crisp. Don't know if that's the problem...
Anyway Core (don't know your name)...I'm planning to move to uk...do you think it's a good choice? :P
Where do you live now?!
Rome...
15 years of experience (front end developing, mostly), i had a company now (numidia.it) but I worked as employee a lot too...
Lots of front-end jobs going, London mostly if you can handle the astronomical cost of living.
Well, thanks for that! I think the same...I'd love to go to a smaller city like Bristol, Manchester, Liverpool etc but London has more possibilities...we'll see!
Manchester is the next best place outside London to be honest - a real digital hub. I live just near there actually. I'll do you a swap, always fancied living in Italy!!
Italy is nice...if you are a tourist :) I'll look for Manchester...you have a free beer from me :)
If I could get this PDF working, the drinks would be on me all night!
eheheh...I'll continue trying too
the original library (http://parall.ax/products/jspdf), mentioned that the image must be encoded to base 64 ... I was doing some tests so far have been unsuccessful ...maybe I'm missing something, any recommendations?
i try some changes, in jspdf.plugin.addimage.js line 163, modify this:
//TODO: this needs to use the original image width/height
//var dims = getJpegSize(imageData);
for this:
// TODO: this needs to use the original image width/height
((w=null) || (h==null)) ? var dims = getJpegSize(imageData) : var dims = [w,h];
and in app.js, change this:
var imgSample1 = Ti.Filesystem.resourcesDirectory + 'image1.jpg';
doc.addImage(imgSample1, 'JPEG', 10, 20, 128, 96);
for this:
var imgSample1 = Titanium.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + 'image1.jpg');
var readestImgSample1 = imgSample1.read();
var dataImgToAdd1 = 'data:image/jpeg;base64,'+Titanium.Utils.base64encode(readestImgSample1).toString();
//alert(dataImgToAdd1);
doc.addImage(dataImgToAdd1, 'JPEG', 10, 20, null, null);
another attempt ... on this occasion got the measurements of the image on an Android device but the file is not created successfully.
in app.js change this:
btn.addEventListener
(
'click',
function (e)
{
//original code ...blah blah blah!
}
);
for this:
var imgToAdd1;
var tempImageView;
btn.addEventListener
(
'click',
function (e)
{
imgToAdd1 = Titanium.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + 'image1.jpg');
tempImageView = Ti.UI.createImageView ( { } );
tempImageView.addEventListener("load",funcCreatePDF);
tempImageView.setImage(imgToAdd1);
win.add(tempImageView);
}
);
function funcCreatePDF()
{
var doc = new _jsPDF();
var blob = tempImageView.toBlob();
(blob === null) ? Ti.API.info("unable to get image size") : alert(blob.width + "x" + blob.height);
doc.addImage(imgToAdd1, 'JPEG', 10, 20, blob.width, blob.height);
var timeStampName = new Date().getTime();
if (_tempFile != null) {
_tempFile.deleteFile();
}
_tempFile = Ti.Filesystem.getFile(Ti.Filesystem.getTempDirectory(), timeStampName + '.pdf');
doc.save(_tempFile);
funcOpenFile(_tempFile); //function containing the remaining code to display the file generated
}
Hello, nice mod. Has this bug been resolved on android?
i have same issue on android, i can't see images but text it's working well... So, in iOS woks everything, somebody has the answer? thanks
Hi, thanks for this! Anyway...with Android and the demo I have rendering problems, here's a screenshot:
Looks like a strange problem...if I open that pdf via osx preview app the pdf is correct. With google drive or adobe reader on a pc I have funny results...
edit: so the problem is the original size of the images (1:1 images work fine) And I'm sure you know it, in fact: jspdf.plugin.addimage.js line 163 //TODO: this needs to use the original image width/height //var dims = getJpegSize(imageData);