jsPDF within Cordova / Phonegap - Impossible to add images - android

I have a problem,
I'm trying to add images in my pdf with jsPDF. b64Tab is an array containing the base64 data of my jpg images that i want to add.
After the
doc.output();
The different pages are created with the text added, but the images are not displayed. I test this on a 4.2.2 Android phone.
Here is a piece of code :
for (var j = 0; j < b64Tab.length; j++) {
doc.addPage();
doc.setFontSize(22);
doc.text(130, 65, descriptions[j]);
doc.addImage(b64Tab[j], 'JPEG', 40, 100, 500, 500);
}
I'm using the latest jsPDF's build.
Any help would be welcomed.
Thanks.

If you are not using File plugin then replace pdf output with doc.output("blob");
If you are using File plugin then create a buffer to write on the file eg.
var data = getPDFFile();
var buffer = new ArrayBuffer(data.length);
var array = new Uint8Array(buffer);
for (var i = 0; i < data.length; i++) {
array[i] = data.charCodeAt(i);
}
writer.write(buffer); // here you write on file using File plugin

Related

Recyclerview list to pdf

I have a recyclerview data is set from server i want to save the data to pdf file
how can i achieve please help
JSONArray jsonArray = jobj.getJSONArray("Complaint Details");
rcview.setBackgroundResource(R.drawable.bbg1);
for (int i = 0; i < jsonArray.length(); i++) {
jobj = jsonArray.getJSONObject(i);
viewcmplist item = new viewcmplist(
jobj.getString("subject"),
jobj.getString("mark"),
jobj.getString("ce"),
jobj.getString("te"),
jobj.getString("grade")
);
listitems1.add(item);
}
cmpadapter = new CmpviewAdapter(listitems1, getApplicationContext());
rcview.setAdapter(cmpadapter);
You can use a custom library such as https://github.com/HendrixString/Android-PdfMyXml. I prefer this library than any other method. Just Go through these.
but there is another way -
How to convert Android View to PDF - that generate a pdf that contains bitmap of your layout

How can i change image targets and video in videoplayback of qualcomm sdk in android

How can i change image targets and video in videoplayback of qualcomm sdk, i have got dat and xml file for two new target images but now able to play video for those image targets, what steps should i follow two work it for two new target images and play video corresponding.
you have to give refrence of those XML in your Project just like the Reference given of the other XML for this here is sample that is also in ImageTarget Project.
In image target Project there is a method in JNI Imagetarget.cpp
Java_com_qualcomm_QCARSamples_Imagtargets_Imagetargets_loadTrackerData(JNIEnv *, jobject)
this method is dealing with multiple XML Files
it will help you how to load multiple XMLS
on the contrary if you want to detect multiple markers but with single XML and DAt file recognise your targets from the Vuforia Server combine it in single Xml file and then u can use like this
static const int NUM_TARGETS =4;
static const int Test1 = 0;
static const int Test2 = 0;
static const int Test3 = 0;
static const int Test4 = 0;
static const int Test5 = 0;
and in renderframe method
o like this
if (strcmp(trackable->getName(), "Test1 ") == 0)
currentTarget=Test1 ;
if (strcmp(trackable->getName(), "Test2 ") == 0)
currentTarget=Test2 ;
if (strcmp(trackable->getName(), "Test3 ") == 0)
currentTarget=Test3 ;
if (strcmp(trackable->getName(), "Test4 ") == 0)
currentTarget=Test4 ;
if (strcmp(trackable->getName(), "Test5 ") == 0)
currentTarget=Test5 ;
if you just want new image to be tracked and new video should play go through this:
for new target image:
replace dat and xml in asset folder in android videoplayback sample project with your dat and xml downloaded from Vuforia trackermaneger site. and don't forget to rename them to default if you don't want to build again JNI code.
for new video to be played :
either you replace video file in asset folder with same name or (i recommend this) you use any server url as video link,like this-
Uri videolink = Uri.parse("http://commonsware.com/misc/test2.3gp");
mMediaPlayer.setDataSource(mParentActivity,videolink);
in videoplaybackhelper class
hope this helps

as3 air for android download folder and contents

Is it possible to download a folder and its contents using air for android? I would like to also use the same code on iPhone.
I need it to be stored in the application storage so we can reference the content once downloaded.
I know it's possible to download content as referenced in this question: Download Content using Air For Android
but can a person download the entire folder and again store it in the application directory?
Thanks
#lukevain? :)
Are you downloading this from a web server? If so this is not going to work and I would recommend using a php script to list all the files in the remote directory.
If this is local you can use this:
//using the application storage dir. This will work on iOS and Android
var f:File = File.applicationStorageDirectory.resolvePath("yourFolder/");
//you can also use getDirectoryListingAsync to have this run in the background
var filesList:Array = f.getDirectoryListing();
for (var i:int = 0; i < filesList.length; i++) {
trace(filesList[i].nativePath);
}
This is not the answer of how to get contents of a folder from the server but it is a way to search through a folder of your choice on the local machine. It only goes 3 levels deep and it may not be the best way to find folders because it checks to see if their extension is null and I made it assume it is a folder. Then I search in that folder. Anyway here it is.
You will need do create a text field and give it an instance name of "daText";
Here is the code:
import flash.filesystem.*;
import flash.media.*;
var myFolder:String = "images/"; /// change this to the folder of your choice :)
var desktop:File = File.applicationDirectory.resolvePath(myFolder);
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++)
{
if (files[i].extension == null)
{
daText.text += files[i].name + "\n";
var anotherArray:File = File.applicationDirectory.resolvePath(myFolder+files[i].name);
var h:Array = anotherArray.getDirectoryListing();
for (var a:uint = 0; a < h.length; a++)
{
daText.text += "----" + h[a].name + "\n";
if (h[a].extension == null)
{
var oneMoreArray:File = File.applicationDirectory.resolvePath(myFolder+files[i].name+"/"+h[a].name+"/");
var C:Array = oneMoreArray.getDirectoryListing();
for (var B:uint = 0; B < C.length; B++)
{
daText.text += "*******"+C[B].name + "\n";
}
}
}
}
}

Issue accessing local xml files in apk file - Air for Android

This is my first time really getting my teeth into Air for Android so please forgive me if this issue has been covered already. If it has then I've been unable to find it.
So I have an application that loads and displays xml data.
In the app I've got code to check if wiFi or equivalent is available and if so then pull live xml file and if not then pull the local xml file that was packaged with the application.
The app works fine if I am pulling in the xml from the live url but not if pulling from local.
After doing some research I discovered that when pulling in local file then Air for Android works slightly differently. So I need to resolve the application directory.
I did this and still no joy.
After a bit more research I read some post's that said I should use fileStream()
Tried this and still nada :(
All the time whilst testing in Flash IDE it works as intended.
If I had any more hair left I would be pulling it out right now!
The local xml file is set in the "includes"
Sample code below I am using for testing
var subURL:String = "xml_feeds/myxmlfile.xml"
var fileStream:FileStream = new FileStream();
var file:File = File.applicationDirectory.resolvePath(subURL);
fileStream.addEventListener(Event.COMPLETE, processXMLData);
fileStream.openAsync(file, FileMode.READ);
MovieClip(parent).txStates.text = file.url+" - TRYING"
var prefsXML:XML = new XML()
function processXMLData(event:Event):void{
MovieClip(parent).txStates.text = file.url+" - OPEN"
prefsXML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
var tempArr:Array = new Array();
var reportCount:Number = prefsXML.row.column.length()
for (var i = 0; i < reportCount; i++) {
var rName:String = prefsXML.row.column[i].#name.toString();
var rValue:String = prefsXML.row.column[i].toString();
var rTitle:String = prefsXML.row.column[i].#name.toString()
tempArr.push([rName, rValue, rTitle]);
}
showData()
fileStream.close();
}
Is there anything I've missed?
UPDATE: 21/08/12
No idea what is going on with this. Here is the code i now have to use in order to load in the local xml file. Seems rather long winded
function listing():void{
var folders:Array = new Array();
folders = File.applicationDirectory.getDirectoryListing();
for(var i:Number =0;i<folders.length;i++){
if(folders[i].isDirectory){
if(folders[i].name=="xml_feeds"){
var files:Array = new Array();
files = folders[i].getDirectoryListing();
for(var j:Number=0;j<files.length;j++){
if(files[j].name=="CTSection2.xml"){
fileStream.openAsync(files[j], FileMode.READ);
fileStream.addEventListener(Event.COMPLETE, processXMLData);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, localXMLFailLoad);
}
}
}
}
}
}

saving a string array to a file error

How to format directory in android project folder as jvm can't see datass.txt or sometimes logcat says read only file...(i am putting datass.txt in main project root)
i am passing an array of strings and want to save it to a file datass.txt so i can retrieve data when internet is not connected
public void FileWrite(String[] temp) throws IOException{
File m = new File("datass.txt");
final String[] descs = temp ;
DataOutputStream out = new DataOutputStream(new
BufferedOutputStream(
new FileOutputStream(m)));
for (int i = 0; i < 31; i ++) {
out.writeUTF(descs[i]);
}
}
You need to add File Writing Permission in your AndroidManiFest.xml file.
android.permission.WRITE_EXTERNAL_STORAGE
Please visit this link for various other permission set.
it seems that you could a Index out of bound exception i am not sure but to guard your self change the for loop header to this
for(int i =0; i < descs.length ; ++i)

Categories

Resources