Do we have some clear guide on how to generate pdf in android which includes tabular data too, with custom fonts like devnagri etc? I have tried itext pdf but text other than English shows blank. Any free or paid library will be helpful.
If you can draw it on screen then you can draw it to a pdf with the built in PdfDocument Class as you can use any laid out view (either got from what is already on screen or manually laying it out yourself) and then use the View's draw method to draw it to the PDF.
So for the tabular data you can use a TableLayout or other methods and the standard fonts available to your app.
Note the Pdf is a bitmap of the contents (e.g. the text is not editable)
Related
would someone provide me with the code to read an epub book and display as webView , I have tried my best to get the needed code but never got it so i wish if someone would post it for me, I need a step by step procedure as i am a beginner i am using eclipse thanks in advance
You can try CoolReader here, and FBReader here.
1.epub (non-DRM), fb2, txt, rtf, html, chm, tcr, doc, pdb formats supported
2.Pages or scroll view
3.Table of contents
4.Bookmarks
5.Text search
6.Hyphenation dictionaries
7.Most complete FB2 format support: styles, tables, footnotes
8.Additional fonts support (.ttf)
9.Can read books from zip archives
10.Automatic reformatting of .txt files (autodetect headings etc.)
11.Styles can be customised in wide range using external CSS
Android specific
Page flipping animation.
Built-in file browser, quick recent books access
Day and night profiles (two sets of colors, background, backlight levels)
Brightness adjustments by flick on left edge of screen
Background texture (stretched or tiled) or solid color
Paperbook-like page turning animation or "sliding page" animation
Dictionary support (ColorDict, Fora Dictionary, Aard dictionary)
Customizable tap zone and key actions
Place additional textures to /sdcard/.cr3/textures/ -- to be used as tiled page backgrounds
Place additional textures to /sdcard/.cr3/backgrounds/ -- to be used as stretched page backgrounds (/cr3/ directory can also be used instead of /.cr3/, and internal SD or internal storage instead of /sdcard/)
TTS (text-to-speech) support
Select text using double tap (optional)
I would like knowing if it's possible to obtain the preview image (thumbnail) of any text file in Android, like PDF, DOC, TXT, PPT, PPTX, RSS or HTML.
If the response is positive, how do I can make it?
I have the preview images of video and image files, and I want to obtain the same result for text files.
Thanks for your attention, greetings.
This can be quite a problem since you need to handle every file type individually.
TXT, RSS and HTML are simple enough, you can just read them all like a text file and display the text on the screen (first X characters, for instance, either with a TextView or by manually drawing it in the onDraw method. However, if you want to render the HTML, look at this question.
PDF is another story, you need some sort of rendering endine for that, you might want to look at MuPDF.
RSS and HTML Can work the same way as a normal TXT file.
PPT, PPTX and DOC will also need a custom renderer, you might want to look at this question.
After finding Display SVG Image in image view in android on Google and going to Having issue on Real Device using vector image in android. SVG-android, I find that "You need a 3rd-party JAR to do it" is a bit of overkill. Is there any way to render an SVG without using 3rd-party libraries?
I managed to display an SVG using a WebView, since that is more than capable of rendering an SVG:
webView.loadUrl("file:///android_res/drawable/file.svg"); // point it to the SVG
webView.setBackgroundColor(0x00000000); // set the background to transparent
This makes it render much like a transparent PNG would in an ImageView. The only caveat is that the SVG must use the viewBox attribute and not use the height or width attributes, to ensure it resizes properly.
Using custom fonts actually works really well in Android.
You can use the free icomoon web application to convert SVGs to custom .ttf font characters.
If you are using it for imagePicker sort of feature then,
webView.loadURl(selectedFileLocation.toString)
else if it is to display a .svg image from web,
webView.loadURl(/*url for the .svg file*/)
It's been three days I'm looking for (and test) libs which can perform a generation of an image from textual content. I develop an app on Android with the Augmented Reality Metaio SDK. To apply a texture with text and image embed, I must generate a PNG file. So I need a method :
Compatible with Android
On the Android client : not generating the PNG on a server
With the right way like html/css, svg or Android layout for example : ie not having to make justify text and box positionning from scratch, I'm sure you understand why x)
Which can perform a generation in external thread (ie without the user have to see the layout)
I tested a lot of solutions, but nothing works.
Using WebView
Some topics about this :
Generate bitmap from HTML in Android
How to use onDraw(Canvas) to obtain [...]
Convert HTML to image (any format) on Android
Capturing android webview image and saving to png/jpeg
Which can replace capturePicture function
Capture picture from WebView
Ultimately, onPageFinished is not enough and we must implement :
webView.setPictureListener(new PictureListener()
{
#Override
public void onNewPicture(WebView view, Picture picture)
{
[...]
It works, but it's deprecated and the WebView must be visible if I want to generate a png, and it does not suit me.
Using Android Layout
Some topics about this :
How do I convert a RelativeLayout [...]
Converting a view to Bitmap without displaying it in Android?
Android Problems Converting ViewGroup with Children into Bitmap
convert view into bitmap [duplicate]
Once again, I must have a visible View to generate a PNG from it.
Using svg-android
Some topics about this :
SVG to Bitmap at runtime Conversion in Android
It works, but there are only basic functions : include text, image or data-uri image don't work.
Using Batik
SVG Rasterizer and its use.
It works, but not on Android.
Conversion to Dalvik format failed with error 1
I finally succeeded in using a WebView without having to see the view. I set the width to 0.1dp and switch visible/invisible quickly.
I use a WebView because the layout engine is more complete. But warning : as mentioned higher, the method onNewPicture is deprecated.
I implemented a class containing a GenerationProcess which perform all Thread treatments (on the UI Thread or on a backgroud Thread) and a GenerationQueue which perform a Thread ordering. So this class is totally independent and you can use it without having to think about the Thread you are.
With the Android Layout engine, we don't have to use all these Thread because there is no callback function like onPageFinished and onNewPicture : make your choice !
Github Project - WebView2Img
You can take a look at :
./src containing the Activity example and the class Page
./res/layout containing the layout example
./assets containing all html example
Then you can extends Page to manipulate the DOM (with jdom for example) to dynamicaly set content and save the html file.
EDIT : here an example of extends Page with dom manipulation before generation
I wonder how whatsapp gives support for that. I could use emojis on iPhone because it is natively supported. I'm not developing for bb neither android but I need to help a coder with this stuff.
The bb guy told me that he can add a font as a project resource (ttf), but since emojis are colored graphics, I'm not sure if i can create a ttf. I do not know anything about fonts either.
As you can see, my unknowledge is huge on this. I just need some tips that point me to the right way to research.
Thanks!
On Android you can make a BitMap font with the tutorial i found here. Then you can embed all your Emoji into that font.
For making this on the BlackBerry you can use the FontFamily class. Here is a tutorial that explains how this works.
Have fun! :-)
From my experience most emoticons (emoji) do not use a font, but are rather bitmap graphics (e.g. emoticons in the default Android text editor). There are several downsides to using a font:
Suppose you made the characters a, b, c, d etc into emoticons - the user would then be unable to read/send messages with those characters in without them turning to emoticons.
Fonts are generally quite large as they contain a lot of information for displaying the text at different sizes/styles
Using bitmap graphics will allow you to easily use the same emoticons across a wide range of devices, whilst using standard device fonts the text around the emoticons.
You will have to parse the string that you are displaying, find the emoticons, and replace them with images.
On Android for instance you would accomplish this with:
Search the string for all emoticon occurences (regex can do this easily enough)
Replace all emoticons with the string <img src="emoticon.png" /> (althugh change emoticon.png based on the type of emoticon)
Convert the String to HTML with String myHtmlString = Html.fromHtml(myEmoticonString, myImageGetter, null);
Display the string in a TextView myTextView.setText(myHtmlString)
In step 3 myImageGetter needs to be an instance of Html.ImageGetter which returns a graphic (drawable) based on the src attribute of the images in the string (ie it converts a string file name to an actual graphic)
The steps on other platforms would be different but you should be able to use the same basic method (parse string, replace emoticons with images).
Let me tell what I know, I dont know emoji, but googling it had me thinking it is a set of emoticons, primarily Japanese in origin. If that is true I would like to point out that it is common to create custom fonts using a font file (shown here). And in that font file you should be able to embed these emoticons and use them.
The link I provided above, is for J2ME, but the logic and design should be similar. Hope this helps.