izettle / android-html2bitmap Goto Github PK
View Code? Open in Web Editor NEWGenerates a bitmap from html by rendering the content inside an off screen webview
License: MIT License
Generates a bitmap from html by rendering the content inside an off screen webview
License: MIT License
I check your code and don't see anything you need that min version, are some reason for that restriction?
@erikeelde @BeeeQueue @warting @hfreire @bborisovs
Hi,
Sorry for mentioning everyone.
Thanks for making such a wonderful thing.
If I write CSS codes inside the style tag of the head tag, it works fine.
Is there a way to include a CSS file from the project files? Not from an external internet link.
I am pretty new to these things. If this is possible, please teach me a little about the procedure.
Thanks in advance.
This is a confusing library. I thought the string to be passed was a HTML string but looking into its code, it actually loads a file saved from file:///android_asset/
.
java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:206)
at com.izettle.html2bitmap.Html2Bitmap.getBitmap(Html2Bitmap.java:67)
at com.izettle.html2bitmap.Html2Bitmap.getBitmap(Html2Bitmap.java:92)
when using the following code, image html gets cut and image isn't showing the full page
val html2BitmapConfigurator: Html2BitmapConfigurator =
object : Html2BitmapConfigurator() {
override fun configureWebView(webview: WebView) {
webview.settings.loadWithOverviewMode = true
webview.settings.useWideViewPort = true
}
}
try {
URL url = new URL(unityURL);
Html2Bitmap html2Bitmap = new Html2Bitmap.Builder(UnityPlayer.currentActivity.getApplicationContext(),
WebViewContent.url(url))
.setTimeout(5)
.build();
Bitmap bitmap = html2Bitmap.getBitmap();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 90, outputStream);
try {
UnityPlayer.UnitySendMessage("WebController", "OnWebImageReceived",outputStream.toString("UTF-8"));
} catch (UnsupportedEncodingException i){
Log.e("yo", "Unsupported encoding: " + i);
}
} catch (MalformedURLException e) {
Log.e("yo", "MALFORMED URL: " + e);
}
I am passing in a url and getting a timeout exception every time, is this normal, or am I doing something wrong?
W/Adreno-EGLSUB: DequeueBuffer:726: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
W/Adreno-ES20: <core_glFinish:23>: GL_OUT_OF_MEMORY
E/OpenGLRenderer: GL error: Out of memory!
W/MessageQueue: Handler (com.izettle.html2bitmap.Html2BitmapWebView$2) {acc254f} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (com.izettle.html2bitmap.Html2BitmapWebView$2) {acc254f} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
at android.os.Handler.enqueueMessage(Handler.java:643)
at android.os.Handler.sendMessageAtTime(Handler.java:612)
at android.os.Handler.sendMessageDelayed(Handler.java:582)
at android.os.Handler.sendEmptyMessageDelayed(Handler.java:546)
at com.izettle.html2bitmap.Html2BitmapWebView$1.handleMessage(Html2BitmapWebView.java:81)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
GitHub Advanced Security has been enabled on this repository as part of our automatic phased rollout.
Secret Scanning is now active, which means that in the "Security" tab, you may now see identified secrets that needs to be handled.
Code Scanning is not automatically activated - see documentation for how to enable it.
Read more about GitHub Advanced Security and the rollout in on the tech-guidelines wiki
I have 1 question regarding the library.
Why in the class WebViewAssetContent on method loadResourceImpl you do getRemoteFile?
I think webview work without this method and I also think that it bypasses the webview cache policy?
GitHub Advanced Security has been enabled on this repository as part of our automatic phased rollout.
Secret Scanning is now active, which means that in the "Security" tab, you may now see identified secrets that needs to be handled.
Code Scanning is not automatically activated - see documentation for how to enable it.
Read more about GitHub Advanced Security and the rollout in on the tech-guidelines wiki
Hi,
I'm trying to generate bitmap using 1.10 version of the library, and when trying to use this html I'm getting timeout exception.
Bitmap bitmap = new Html2Bitmap.Builder()
.setContext(MainApp.getAppContext())
.setContent(WebViewContent.html(html))
.setBitmapWidth(576)
.build()
.getBitmap();
E/Html2Bitmap: []
java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:206)
at com.izettle.html2bitmap.Html2Bitmap.getBitmap(Html2Bitmap.java:67)
at com.izettle.html2bitmap.Html2Bitmap.getBitmap(Html2Bitmap.java:92)
Maybe this could be usefull
I/WebViewFactory: Loading com.android.chrome version 76.0.3809.132 (code 380913237)
I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 25-31)
I/chromium: [INFO:library_loader_hooks.cc(51)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "76.0.3809.132", actual native library version number "76.0.3809.132"
W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true
I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
W/ResourceType: Failure getting entry for 0x7f130532 (t=18 e=1330) (error -2147483647) type=1400 audit(0.0:87): avc: denied { read } for name="vmstat" dev="proc" ino=4026532356 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
W/VideoCapabilities: Unsupported mime video/divx
W/VideoCapabilities: Unsupported mime video/divx311
W/VideoCapabilities: Unsupported mime video/divx4
W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
V/FA: Connection attempt already in progress
W/VideoCapabilities: Unsupported mime video/x-ms-wmv
I/chatty: uid=10099() Chrome_InProcGp identical 1 line
W/VideoCapabilities: Unsupported mime video/x-ms-wmv
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
W/Utils: could not parse long range '175-174'
And the html put into the client
<HTML>
<HEAD>
<style>
body{
vertical-align: top;
font-family: "Roboto";
font-weight: bold;
font-size: 16pt;
line-height: 1.1;
margin:5px;
height: 2000px;
}
span.bold{
font-weight: bolder;
}
span.bigText{
font-size: 20pt;
display: block;
}
span.bigerText{
font-size: 28pt;
display: block;
}
span.smallText{
font-size: 12pt;
display: block;
}
span.smallerText{
font-size: 10pt;
display: block;
}
div.claimcheck{
position:absolute;
top: 20px;
height:385px; width:566px;
}
div.rackstub{
position:absolute;
top:410px;
height: 705px; width:566px;
display: block;
}
div.keystub{
display:table;
position:absolute;
top:1120px;
height: 300px; width:566px;
}
div.windowstub{
position: absolute;
top:1425px;
height: 150px; width: 566px;
}
div.backupclaimcheck{
position:absolute;
top:1580px;
height: 410px; width:566px;
}
div{
border-style: solid;
border-width: 1px;
}
div.title {
font-size: 20pt;
text-align:center;
}
div.center {
text-align:center;
}
div.note {
font-size:10pt;
text-align:center;
}
div.alignleft {
text-align:left;
}
div.left {
width:276px;
float: left;
text-align:left;
font-weight:bold;
}
div.right {
width:276px;
float: right;
text-align:right;
padding-right:10px;
}
</style>
</HEAD>
<BODY>
<!-- CLAIM CHECK -->
<div class="claimcheck">
<div class="note">***** THIS IS NOT A RECEIPT *****</div>
<br />
<div class="title">COMPANY NAME</div>
<div class="center">
COMPANY ST <br />
COMPANY ADDRESS2, AU 00000 <br />
LICENSE# XYZ12345 <br />
</div>
<br />
<div class="center">TICKET #202393</div>
<br />
<div class="alignleft">202393 WHITE LEXUS HJZ5567(NY) Damage: --</div>
<br />
<br />
<div class="left">IN:</div>
<div class="right">08/02/19 1:33 PM</div>
<div class="left">OUT:</div>
<div class="right">09/23/19 3:23 PM</div>
<div class="left">STAY:</div>
<div class="right">1 MTH, 21 DAYS, 1 HR, 50 MINS</div>
</div>
<!-- RACK STUB -->
<div class="rackstub">
<div class="left">RATE:</div>
<div class="right">1 @ $0.48</div>
<div class="left">CHARGE TOTAL:</div>
<div class="right">$0.48</div>
<div class="left">TAX Rate: 10.375%</div>
<div class="right">$0.05</div>
<div class="left">TOTAL</div>
<div class="right">$0.53</div>
<br />
<br />
<div class="center">cash PAYMENT </div>
<div class="left">AMOUNT TENDERED</div>
<div class="right">$0.53</div>
<div class="left">TOTAL PAYMENT</div>
<div class="right">$0.53</div>
<div class="left">CHANGE DUE</div>
<div class="right">$0.00</div>
<br />
<div class="note">MDC 09/23/19 3:23 PM 0333-0020-00001052</div>
<br />
<br />
<div class="center">
THANK YOU<br />
COMPANY NAME <br />
</div>
<br />
<div class="note" >***** THIS IS NOT A RECEIPT *****</div>
</div>
<!-- KEY STUB -->
<div class="keystub">
</div>
<!-- WINDOW STUB -->
<div class="windowstub">
</div>
<!-- BACKUP CLAIM CHECK -->
<div class="backupclaimcheck">
</div>
</BODY>
</HTML>
GitHub Advanced Security has been enabled on this repository as part of our automatic phased rollout.
Secret Scanning is now active, which means that in the "Security" tab, you may now see identified secrets that needs to be handled.
Code Scanning is not automatically activated - see documentation for how to enable it.
Read more about GitHub Advanced Security and the rollout in on the tech-guidelines wiki
Thank you for the awesome library
Are there any ways we could improve the bitmap generation time for local files. Currently, we are experiencing around 800ms delay. Could anyone give suggestions if there are any ways to achieve a lesser bitmap generation time?
Kudos
Getting the above error when try to integrate in my app which has couple of product flavours. For now used the following SO hack to fix. Can this be fixed, if so please let me know ready to contribute.
https://stackoverflow.com/questions/52518378/more-than-one-file-was-found-with-os-independent-path-meta-inf-proguard-android
GitHub Advanced Security has been enabled on this repository as part of our automatic phased rollout.
Secret Scanning is now active, which means that in the "Security" tab, you may now see identified secrets that needs to be handled.
Code Scanning is not automatically activated - see documentation for how to enable it.
Read more about GitHub Advanced Security and the rollout in on the tech-guidelines wiki
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.