java - PDF page to Image, Apportable BridgeKit -



java - PDF page to Image, Apportable BridgeKit -

i modified code post:

need help convert pdf page bitmap in android java

to seek , page pdf, convert byte[] , pass xcode project displayed. i'm doing using apportables bridgekit framework , compiles without errors.

the problem app crashes 1 time loaded on device.

imageextractor.java

package com.pdflib; import android.graphics.bitmap; import android.os.environment; import android.util.log; import com.sun.pdfview.pdffile; import com.sun.pdfview.pdfpage; import net.sf.andpdf.nio.bytebuffer; import java.io.bytearrayoutputstream; import java.io.file; import java.io.randomaccessfile; public class imageextractor { //globals: private int viewsize = 0; //load images: private byte[] pdfloadimages() { seek { file file = new file(environment.getexternalstoragedirectory().getpath() + "/backs.pdf"); randomaccessfile f = new randomaccessfile(file, "r"); byte[] info = new byte[(int)f.length()]; f.readfully(data); //create pdf document object bytes bytebuffer bb = bytebuffer.new(data); pdffile pdf = new pdffile(bb); //get first page pdf doc pdfpage pdfpage = pdf.getpage(1, true); //create scaling value according webview width final float scale = viewsize / pdfpage.getwidth() * 0.95f; //convert page bitmap scaling value bitmap page = pdfpage.getimage((int)(pdfpage.getwidth() * scale), (int)(pdfpage.getheight() * scale), null, true, true); //save bitmap byte array bytearrayoutputstream stream = new bytearrayoutputstream(); page.compress(bitmap.compressformat.png, 100, stream); byte[] bytearray = stream.tobytearray(); stream.reset(); homecoming bytearray; } grab (exception e) { log.d("error", e.tostring()); } homecoming null; } }

mainscene.m

#import "mainscene.h" #import "createtexture.h" @implementation mainscene - (void)didloadfromccb { cgsize size = cgsizemake(100, 75); createtexture* sprite = [[createtexture alloc] initwithbacksize: size]; sprite.positioninpoints = cgpointmake(100, 100); [self addchild: sprite]; } @end

createtexture.m

#import "createtexture.h" #ifdef android #import "pdfbridge.h" #endif @implementation createtexture - (instancetype) initwithbacksize: (cgsize) size { #ifdef apportable pdfbridge *temp = [[pdfbridge alloc] init]; [temp testbridge]; nsdata* tempbytes = temp.imagebytes; uiimage* image = [[uiimage alloc] initwithdata:tempbytes]; cctexture* texture = [[cctexture alloc] initwithcgimage: image.cgimage contentscale: image.scale]; self = [super initwithtexture: texture]; #endif nsassert (self, @"initializer failed"); homecoming self; } @end

pdfbridge.m

#import "pdfbridge.h" @implementation pdfbridge @dynamic imagebytes; - (void) testbridge { #ifdef apportable [pdfbridge registerinstancemethod:@"pdfloadimages" selector:@selector(imagebytes) returnvalue:[nsdata classname]]; #endif } + (nsstring *)classname { homecoming @"com.pdflib.imageextractor"; } @end

instead of - (void) testbridge method, should override +[javaobject initializejava], like:

class="lang-objectivec prettyprint-override">+ (void)initializejava { // phone call [super initializejava] [super initializejava]; // register bridge constructors, methods, callbacks here ... }

also note open-source parsebridge provides extensive illustration of using apportable bridgekit.

java android image pdf apportable

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -