Multipage TIF to PDF

cv writing services sydney Recently I’ve continued the porting of iText adding the support for a new image type: multipage tif.

http://www.queen-jungle.com/order-of-body-paragraphs-in-essay/ order of body paragraphs in essay The only problem with this update is that actually it’s really slow and probably with very complex image files it can hang the player for too long. Probably I should modify the http://wpdalya.com/dissertation-sur-la-preface-de-pierre-et-jean/ dissertation sur la preface de pierre et jean ImageElement.getInstance method and make it asynchronous in order to prevent flash player to freeze…

genuine brand name cialis Anyway, the current trunk version of purePDF can handle TIF image and here a simple code example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.net.FileReference;
    import flash.utils.ByteArray;
    import flash.utils.Timer;
    import flash.utils.getQualifiedClassName;
   
    import org.purepdf.elements.RectangleElement;
    import org.purepdf.elements.images.ImageElement;
    import org.purepdf.io.RandomAccessFileOrArray;
    import org.purepdf.pdf.PageSize;
    import org.purepdf.pdf.PdfDocument;
    import org.purepdf.pdf.PdfViewPreferences;
    import org.purepdf.pdf.PdfWriter;
    import org.purepdf.pdf.codec.TiffImage;

    public class TestTIF extends Sprite
    {
        [Embed( source="assets/foxdog_multiplepages.tif", mimeType="application/octet-stream" )]
        private var cls1: Class;
     
        private var document: PdfDocument;
        private var writer: PdfWriter;
        private var buffer: ByteArray;
        private var filename: String;
        private var index: int;
        private var pages: int;
        private var stream: RandomAccessFileOrArray;

        public function TestTIF()
        {
            super();
         addEventListener( Event.ADDED_TO_STAGE, onAdded );
      }
     
      private function onAdded( event: Event ): void
      {
            stage.addEventListener( MouseEvent.CLICK, onClick );
        }

        private function createDocument( subject: String = null, rect: RectangleElement = null ): void
        {
            buffer = new ByteArray();

            if ( rect == null )
                rect = PageSize.A4;
            writer = PdfWriter.create( buffer, rect );
            document = writer.pdfDocument;
            document.addTitle( getQualifiedClassName( this ) );

            if ( subject )
                document.addSubject( subject );
            document.setViewerPreferences( PdfViewPreferences.FitWindow );
        }

        private function onClick( event: Event ): void
        {
            filename = getQualifiedClassName( this ).split( "::" ).pop() + ".pdf";
            var byte: ByteArray = new cls1();
            stream = new RandomAccessFileOrArray( byte );
            var image: ImageElement = ImageElement.getInstance( byte );
            createDocument( "Multi page TIFF Image Example", PageSize.A4 );
            document.open();
            // add the first page to the document
            document.add( image );
            // get the total number of pages
            pages = TiffImage.getNumberOfPages( stream );
         trace("number of pages: " + pages );
            // next page index to add to document (first page is 1)
            index = 2;
            var timer: Timer = new Timer( 100, 1 );
            timer.addEventListener( TimerEvent.TIMER, onTimerComplete );
            timer.start();
        }

        private function onComplete(): void
        {
            stream.close();
            document.close();
            save();
        }

        private function onTimerComplete( event: TimerEvent ): void
        {
            if ( index > pages )
            {
                onComplete();
                return;
            }
            document.add( TiffImage.getTiffImage( stream, index ) );
            index++;
            Timer( event.target ).reset();
            Timer( event.target ).start();
        }

        private function save( e: * = null ): void
        {
            var f: FileReference = new FileReference();
            f.save( buffer, filename );
        }
    }
}

http://www.designingdivas.com.au/write-essay-my-school/ write essay my school

essay pro con online education Here you can see the result PDF file.
And here the input TIF image.

purePDF and transparent BitmapData

cv writing service us york Recently I’ve updated purePDF to a new version fixing one bug which caused problems with PNG images.
However when you’re trying to add BitmapData with transparency  to a pdf document you probably get black backgrounds to your images. This is because internaly purePDF converts bitmapdata into 24bit tiff images, so no alpha informations.

hamlet critical analysis essay This is a script you can use to convert your BitmapData images into transparent pdf ImageElements:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * Create a transparent ImageElement
 *
 * An ImageElement with the input bitmapdata RGB informations will be
 * created and an ImageElement will be used as mask ( using the alpha info from the bitmapdata )
 * If the input bitmapdata is not transparent a regular ImageElement will be returned.
 */

protected function createTransparentImageElement( bitmap: BitmapData ): ImageElement
{
        var output: ByteArray = new ByteArray();
        var transparency: ByteArray = new ByteArray();
        var input: ByteArray = bitmap.getPixels( bitmap.rect );
        input.position = 0;
       
        while( input.bytesAvailable ){
                const pixel: uint = input.readInt();
               
                // write the RGB informations
                output.writeByte( (pixel >> 16) & 0xff );
                output.writeByte( (pixel >> 8) & 0xff );
                output.writeByte( (pixel >> 0) & 0xff );
               
                // write the alpha informations
                transparency.writeByte( (pixel >> 24) & 0xff );
        }
       
        output.position = 0;
        transparency.position = 0;
       
        var mask: ImageElement = ImageElement.getRawInstance( bitmap.width, bitmap.height, 1, 8, transparency, null );
        var image: ImageElement = ImageElement.getRawInstance( bitmap.width, bitmap.height, 3, 8, output, null );

        if( bitmap.transparent )
        {
                mask.makeMask();
                image.imageMask = mask;
        }
        return image;
}

dissertation sur le theatre et la representation and here there’s a demo app: http://bit.ly/dOT2ob

Android experiments

follow url As you probably understood during last days I’m completely absorbed in Android development.
While experimenting new things ( it remembers to me the first days with Flash 🙂 ) I did a couple of applications and I’ve published them to the market ( it takes less than one hour to be published on the market, just some weeks less than on the app store ).

http://sedth.gr/?p=descriptive-essay-writing-help First one is a simple note application, very similar to the iPhone note app. This one was for testing the ContentProvider and the built-in android search feature.
Second one is for view, search, plan routes for the Milan subway. This is a mix of features: google maps api, layar intergration, gps locations..

http://labimpresa.com/?p=how-to-do-a-dissertation-conclusion

here

How-to debug native code with Android

watch This is a step by step guide for executing and debugging native code on Android with Eclipse.

1. Prerequisites

http://experts24hr.com/?p=phd-thesis-on The SDK version used for this guide is Froyo with the NDK r4b ( crystax release ).
Also Eclipse CDT plugin it’s very useful for our purposes, so install it.
Last plugin to install it’s the Sequoyah plugin for Eclipse.

2. Project setup

http://apnoeashop.com/?p=college-admissions-resume-objective At this point let’s create a new Android project, name it “Example” and use the “com.darkwavegames.com” package name, add also an Activity name of your choice.
Select Android 2.2 as base SDK version and complete the project wizard.

best place to buy office project professional 2010 Now you need to add the native support for the newly created project. Just right click on the project root element in the package explorer and select “add native support”.

watch In the next dialog write the path of your NDK folder and give also name for your library.
After this operation a new folder “jni” will be created with a .cpp file, header filer and an Android makefile, Android.mk, which can be edited to modify all the includes, linker and compiler options. In the Android.mk file you also need to specify all the source file you want to use within the LOCAL_SRC_FILE directive.

3. Debug

enter In order to enable debug of native code in Android you have to face different problems, based also on the device and the firmware version, and if the native code is multi thread or single thread.
First of all you need to mofify the apa research papers for sale AndroidManifest.xml file adding the attribute “debuggable” to true ( remember also to enable the “Debug USB” option under the Application device menu ).
At this point you can debug all the java code within your eclipse debugger, for for the native C debug you need more steps.

http://www.docomomoiberico.com/?non-plagiarized-custom-research-assignments non plagiarized custom research assignments Continue reading

Playing with a LocalActivityManager bug

castigat ridendo mores dissertation If you already used the ActivityGroup class you probably used also the LocalActivityManager instance to manage your group’s activities. I was creating my activity which should also manages its internal history ( using a ViewFlipper for animating the activity views ).
The problem came out once I tried to destroy an activity from the history using the LocalActivityManager destroy method. After an activity was removed from both my internal history and from the local activity manager I was unable to create a new instance of the same activity.

Compare And Contrast Essay Helper After googling for my problem I found that it was because a bug in the LocalActivityManager class: http://code.google.com/p/android/issues/detail?id=12359
This is exactly my problem! In fact, debugging the android code ( see this post for debugging android code ) at that point it was clear that the record it’s not removed from the internal http://www.funnychan.net/dissertation-outline-format/ dissertation outline format mActivities map.

http://profitousit.com/?p=custom-term-papers-for-sale Fortunately there are Reflections which can help me! I added this piece of code after the call to the destroy method:

source url

1
2
3
Field mActivitiesField = getLocalActivityManager().getClass().getDeclaredField( "mActivities" );
mActivitiesField.setAccessible( true );
((Map) mActivitiesField.get( getLocalActivityManager() )).remove( id );

http://www.ctdesign.it/?computer-engineer-resume-cover-letter-audio and that trick does the job

Reading resource files from native code

how to write an illustrative essay If you’re working with android-ndk and you want to open an asset included in your apk package, you should make a request via jni to the Resource manager in your java code.
Something like:

writing essay for college admission entry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public int[] openAsset( String path )
{
   AssetFileDescriptor ad = null;
   try
   {
      ad = getResources().getAssets().openFd( path );
      Integer off = (int) ad.getStartOffset();
      Integer len = (int) ad.getLength();
      int res[] = { off, len };
      ad.close();
      return res;
   } catch( IOException e ) {
      Log.e( TAG, e.toString() );
   }
   return null;
}

http://www.giezentweewielers.nl/?essay-on-health However this is not a optimal solution expecially when you have tons of file io operations, also because I prefer to limit the amount of calls between java and C++.
A better solution I’m using is to open the current apk application using the libzip library. Just download the library and compile as static library, then include it in your Android.mk make file under the essay write online LOCAL_STATIC_LIBRARIES section.
What you have to do first is to send the current application filename from java, once at startup, in this way:

http://www.cnom.sante.gov.ml/x/history-as-a-subject/

1
2
3
4
5
6
7
8
PackageInfo info = null;
try {
   info = getContext().getPackageManager().getPackageInfo("com.example.text", 0);
} catch( NameNotFoundException e ) {
   Log.e( TAG, e.toString() );
   return;
}
setAppName( info.applicationInfo.sourceDir );

and in the C++ code you will have the corresponding 412 setAppName method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <zip .h>
#include <zipint .h>
#include <jni .h>

char packageName[1024] = {0};
zip   *pkg_zip;

JNIEXPORT void JNICALL Java_com_example_test_MySurfaceView_setAppName( JNIEnv * env, jobject obj, jstring pkgname )
{
   const char *buffer = env->GetStringUTFChars( pkgname, false );

   int error;
   pkg_zip = zip_open( buffer, 0, &error );
   strcpy( packageName, buffer );
   if( pkg_zip == NULL ){
      LOGE("Failed to open apk: %i", error );
   }
   env->ReleaseStringUTFChars( pkgname, buffer );
}

Now you have a reference to the zip package. In this way now you can query the zip package asking if a particular file exists:

1
2
3
4
5
6
7
8
9
bool FileExists(const char* fname)
{
   if( pkg_zip != NULL )
   {
      int result = zip_name_locate( pkg_zip, fname, 0);
      return result != -1;
   }
   return false;
}

And open any of the files included in your apk package:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
FILE *FileOpen( const char* fname )
{
   zip_file *zfile = zip_fopen( pkg_zip, fname, 0 );
   uint32_t offset = 0;
   uint32_t length = 0;

   if( zfile != NULL )
   {
      offset = zfile->fpos;
      length = zfile->bytes_left;
      zip_fclose( zfile );
      zfile = NULL;
   } else
   {
      return NULL;
   }

   FILE *fp = NULL;
   fp = fopen( packageName, "rb" );
   fseek( fp, offset, SEEK_SET );
   return fp;
}

Using this method you will have a FILE pointer to the whole apk file so you have to take care of the http://www.dilmah.pl/?argumentative-essay-on-eating-disorders argumentative essay on eating disorders offset and buy a custom essay length field when reading and seeking the file itself.

Disable asset compression with Android aapt

Trying to embed all the assets resources into my final apk was not so easy as I tought.. at least using the ADT Eclipse plugin for building project.
In fact, using AssetManager.openFd to return to the C++ code a FileDescriptor does not work with compressed sources.
When aapt compile the resources into the apk file it compress by default all the files which extensions are not recognized and those which recognize as text files.

These are the extensions not compressed:

1
2
3
4
5
6
7
8
9
<br />
static const char* kNoCompressExt[] = {<br />
".jpg", ".jpeg", ".png", ".gif",<br />
 ".wav", ".mp2", ".mp3", ".ogg", ".aac",<br />
 ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",<br />
 ".rtttl", ".imy", ".xmf", ".mp4", ".m4a",<br />
 ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",<br />
 ".amr", ".awb", ".wma", ".wmv"<br />
};<br />

I was looking into the .project file of my Eclipse project but it seems that changing things inside that file ( like values into the tag ) does not affect the builder.

The first thing I tried was to remap the aapt executable using a shell script ( and renaming the original aapt file into _aapt ):

1
2
3
4
5
6
7
8
9
10
11
12
<br />
#!/bin/bash</p>
<p>strParams=""<br />
CWD=’dirname $0’</p>
<p>for i in $@; do<br />
   if [ $i = "-S" ]; then<br />
      strParams="$(echo $strParams) -v -0 \"\""<br />
   fi<br />
   strParams="$(echo $strParams) $i"<br />
done</p>
<p>tool="$CWD/_aapt $strParams"<br />
$tool 1>&2<br />

In fact, when building the project in eclipse I could see the whole output, but the files are still being compressed, even if I call the same command in a shell the assets aren’t compressed.
I haven’t yet find a solution so for the meantime I decided to use ant to build my project overriding the default “-package-resources” target in this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<br />
    <target name="-package-resources"><br />
        <echo>Packaging resources</echo><br />
      <echo>${asset.absolute.dir}</echo><br />
        <aapt executable="${aapt}"<br />
                command="package"<br />
            verbose="${verbose}"<br />
                versioncode="${version.code}"<br />
                manifest="AndroidManifest.xml"<br />
                assets="${asset.absolute.dir}"<br />
                androidjar="${android.jar}"<br />
                apkfolder="${out.absolute.dir}"<br />
                resourcefilename="${resource.package.file.name}"<br />
                resourcefilter="${aapt.resource.filter}"><br />
            <res path="${resource.absolute.dir}" /><br />
            <nocompress /></target></p>
<p>    <br />

In this way the project is being compiled correctly and all my assets are embedded not compressed!

P.S. my claim token is: 7C8AATS7Q5A3

Android: Create your own sharing app

One of the first applications I did for Android was a very simple application which simply takes a picture using Camera and then send it to a remote server. Very simple, but it introduced to me into the android world and the notion of activities and communication between different applications.
A little addition to this application I wanted to make was the possibility to share any of the pictures already taken. To do that I wanted to add the application to the list of the choices which appear when an user click on the “share” button when view an image using the default Gallery application.

Continue reading