Custom font in pdfjet android - java

Hi I recently downloaded the open source version of pdfjet that is offered on their website I extracted the downloaded zip and copied the java files found in the com\pdfjet folder to android studio next to my MainActivity.java. I tried a couple of examples that uses some of the corefonts and it works flawlessly but When I want to embed a custom font for the text it won't work on android studio.
I searched on the Internet for a solution but the only solution I found is this:
Font f2 = new Font(pdf,
new BufferedInputStream(getClass().getResourceAsStream(
"fonts/DroidFonts/DroidSerif-Italic.ttf")),
CodePage.UNICODE,
Embed.YES);
From:
http://pdfjet.com/java/examples/example-07.html
But android studio output an error
like in this image:
https://i.stack.imgur.com/W3SPG.png
Any possible solution?
Note: I am using the open source version and I want to use it in Android application
Thanks in advance :-)

They did change their constructor. Just remove "CodePage.UNICODE" part.
protected final Font getFont(String fontName, PDF thePdf) throws Exception {
InputStream fontStream = context.getAssets().open(TypefaceContainer.getFontPathFromName(fontName));
Font result = new Font(thePdf, fontStream, Embed.YES);
return result;
}

Related

JAVA-OpenCV: Video Writer not opening

I want to save the video I'm capturing with opencv in Android and I've chosen to use the openCV VideoWriter class (if there's a better way for Android please let me know).
The problem is that I'm not being capable of opening the object.
This is what I'm trying
videoWriter = new VideoWriter("saved_video.avi", VideoWriter.fourcc('M','J','P','G'),
25.0D, new Size(mOpenCvCameraView.getWidth(),mOpenCvCameraView.getHeight()));
videoWriter.open("saved_video.avi", VideoWriter.fourcc('M','J','P','G'),
25.0D, new Size(mOpenCvCameraView.getWidth(),mOpenCvCameraView.getHeight()));
I keep getting videoWriter.isOpened()=false when it should be true.
Does anyone know what I'm doing wrong? Thanks in advance
The problem was the video path! It should be fully stated, like:
pathSavedVideoFolder = getExternalFilesDir(null).getPath();
filenameRawVideo = pathSavedVideoFolder + "/SavedVideo.avi";
After this you just need to refresh in order to see the file inside "Android/data/YOUR PROJECT/files" folder.

Bold textStyle attribute of textview in xml is not working after applying custom fonts in app Android

Bold textStyle attribute of textview in xml is not working after applying custom fonts in app
I have completed developement of an android app. Now I have to change font family for whole app. I have used baskerville-old-face.ttf fonts and used Calligraphy library to apply these fonts into my app.
Following is dependency I have used:
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
Following is the code to initilize Calligraphy library:
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/baskerville.ttf").setFontAttrId(R.attr.fontPath).build());
And following is the code I have used in each Avtivity to use custom fonts:
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
It is working fine and all fonts are changed but there is only one problem that text style (bold) is not working with xml attribute. I don't want to change each textview attribute programmatically (Using JAVA code) because there are more than 100 text views in my whole app.
I am not getting what I am doing wrong or what I am missing. Please help !
Your help will be highly appreciated. Thank you.
I am not sure that this is the best answer but I was seen same problem. you can use the baskervilleBold.ttf font in your code instead of baskerville.ttf if there is exist.

Fonts are not recognized at Android Studio

My Android Studio doesn't recognize fonts in .ttf or .otf format.
I searched for them at File--> Settings -->File Types , but there i can't find a category which recognizes this formats...
Am I alone with this problem?
Because of my new Membership I can't upload any pics, so here a link to a picture of my problem
It is common for android studio (even in latest version) . I also have "?" mark in project explorer, however it is not problem in programming.
You can use your custom fonts directly in java.
First get a reference to the TextView displaying the text that you want to apply your custom font to. Then call the TypeFace class’s createFromAsset() method to create a new type face using your custom font. You pass an instance of the app's AssetManager as the first parameter by calling getAssets(). This enables you to access the custom font asset file which you pass as the second parameter.
Finally, call setTypeFace() to apply your custom font to the text.
TextView textViewCustom= (TextView)findViewById(R.id.textCustomViewFont);
Typeface custom_font = Typeface.createFromAsset(getAssets(),"fonts/xyz.ttf");
textViewCustom.setTypeface(custom_font);
Android custom fonts tutorial TypeFace java
Create a new TypeFace using your custom font, xyz.ttf which is saved in the assets/fonts folder. You can do it in XML also.

how can I create a thumbnail of a video url in android?

I have a problem, I can only create thumbnails of local video files but not of a remote url, here is my code:
bmThumbnail = ThumbnailUtils.extractThumbnail(ThumbnailUtils.createVideoThumbnail("http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", MediaStore.Video.Thumbnails.MINI_KIND), 50, 50);
I hope you can help me,
regards
christian
I suppose there is no easy way to build the thumbnail without actually downloading the video locally.
So if your question is 'Can I get a thumbnail without having to download the full video?', I'd say...no.
Otherwise, once you have downloaded the video locally, then I guess you can perfectly use ThumbnailUtils.createVideoThumbnail(...) by giving the path to the downloaded file.
I also have the same problem - but what can I say from my tests:
The problem occurs only on android >2.3
in android 2.0 -> 2.3 You can use just
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( videoUrl, MediaStore.Video.Thumbnails.MINI_KIND);
I hope someone explain what change is on android 4. it doesn't work
I have no problem generating thumbnails from remote videos with the following code:
final Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( videoUrl, MediaStore.Video.Thumbnails.MINI_KIND );
You don't have to wrap an extractThumbnail() call around it

Problems with loading local html pages in android 4+

I have a problem with loading local html pages to webView in android 4. Before, I tested it for android 2.3 and it was ok. I load the page like this webView.loadUrl(file:///android_asset/drawable/test.html) I read a lot of information about bug with loading local pages, but I have not solution of this problem. Can you explain me why it doesn't load pages and write that "Web page not avaliable" . May be problems with "file:///" or "android_asset". Please give me real advice how I can load my html pages to webview in android 4. I really need. Thank you.
P.S I am sure that the file exists in that folder.
I resolved my problem. I used:
private final int boundaryApiValue = 10;
/**Function set root directory for current api version.*/
private void setRootPathForCurrentVersionOfAndroid() {
if (Build.VERSION.SDK_INT >= boundaryApiValue)
rootPath = "file:///android_res/drawable/";
else {
rootPath = "file:///android_asset/res/drawable/";
}
}
If u have a version lower than Android HoneyComb than u should load html files for webview from "file:///android_asset/res/drawable/" if u have HoneyComb and later than use "file:///android_res/drawable/" It's works for me fine.

Categories

Resources