codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Home Page:https://www.codenameone.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rendering PDFs doesn't work in android

ddyer0 opened this issue · comments

using BrowserComponent to display PDF files does not work on Android devices. It works in the
simulator and on IOS. There is no indication of an error, except that a completely blank frame is
displayed.

''''java

package com.boardspace.dtest;

import com.codename1.ui.BrowserComponent;
// issue #
//
// drawing pdfs
//
//
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.ui.layouts.BorderLayout;

@SuppressWarnings("rawtypes")
public class Dtest{

private Form current;
@SuppressWarnings("unused")
private Resources theme;

public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Pro only feature, uncomment if you have a pro subscription
// Log.bindCrashProtection(true);
}

public void start() {

if(current != null){
    current.show();
}
Form hi = new Form("Hi >>0 World");
hi.setLayout(new BorderLayout());
BrowserComponent b = new BrowserComponent();
current = hi;
hi.addComponent(BorderLayout.CENTER,b);
b.setURL("https://boardspace.net/colorito/english/COLORITO_EN.pdf");
b.setPinchToZoomEnabled(true);
b.setVisible(true);
hi.show();

}
public void stop() {
current = Display.getInstance().getCurrent();
}

public void destroy() {
}

}
''''

Try loading an html page from the same server to rule out TLS certificate issues.

Also check device log.

Regular html pages work fine. There are no signs of activity in the device logs, codename1 logs, my logs.
No errors are thrown.

I researched this a little bit today - and apparently it is a limitation of the native browser, BUT
there is a workaround! https://stackoverflow.com/questions/7437602/how-to-display-a-pdf-via-android-web-browser-without-downloading-first
Using this, and the" shouldNavigate" callback, I can rewrite pdfs to feed them to google docs.

The underlying limitation is annoying, but with this workaround I think you have higher priority things to do.