I am working on the printing custom file of Android, and I have some doubts in developer website of PrintedPdfDocument
// open a new document
PrintedPdfDocument document = new PrintedPdfDocument(context,
printAttributes);
// start a page
Page page = document.startPage(0);
// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);
. . .
What does the getContentView mean? I think I need to write the function body by myself, but I am not sure what is view mean? Can anyone help?
Yeah. This method needs to be written unless you're working within a PopupWindow or GuidedActionsStylist.ViewHolder. These two has their own getContentView method supplied.
Basically, what this method does or intending to do is to provide you the root(or content) view of window.
Refer to this if you're writing this code under an Activity and implement your getContentView accordingly. Refer to this if you're using Fragment.
Related
Case: User should be able to view and print pdf
My solution: I am opening PDF inside Webview with the help of docs.google.com/gview. Below is my code
Set up Webview
string url = "http://www.africau.edu/images/default/sample.pdf";
string gview = $"https://docs.google.com/gview?embedded=true&url={url}";
mWebView.LoadUrl(gview);
Print PDF
var printMgr = (PrintManager)GetSystemService(PrintService);
printMgr.Print("print", mWebView.CreatePrintDocumentAdapter("print"), null);
Below is the screenshot. As you can see PDF loads just fine
Problem
When I want to print PDF, all the PDF pages are printed in one paper which you can see below
I would appreciate any suggestion, including different library for displaying/printing pdf or suggestion in Java or Kotlin, I can convert them to C#.
I would not print the web page but print the PDF directly as when printing the web page it just sees it as a longer web page and knows nothing about the content.
Use a custom print adapter instead, but instead of drawing a PDF to print you can just use the existing PDF you already have.
See for details https://developer.android.com/training/printing/custom-docs.html
I'm creating an android app with the ultimate goal of being able to generate a PDF from the data collected from the user. Where is a good place to start my research? Is there an API or studio plugin that I should be researching?
Thanks and have a great weekend!
You need android.graphics.pdf library reference page is https://developer.android.com/reference/android/graphics/pdf/package-summary.html
and u can use below codes
// create a new document
PdfDocument mydocument = new PdfDocument();
// crate a page description
PageInfo mypageInfo = new PageInfo.Builder(new Rect(0, 0, 100, 100), 1).create();
// start a page
Page mypage = mydocument.startPage(mypageInfo);
// draw something on the page
View content = getContentView();
content.draw(mypage.getCanvas());
// finish the page
mydocument.finishPage(mypage);
. . .
// add more pages
. . .
// write the document content
mydocument.writeTo(getOutputStream());
// close the document
mydocument.close();
So i have a textView and sometimes my textView contains links, currently when i click in this link an intent with a list of downloaded browsers opens. now what i want is, i wanna open this link inside the current app, say in a WebView. how can i do this?
we do have multiple articles/questions on same topic but i have no idea what this articles/questions are really about.
like this one https://gist.github.com/ksoichiro/3394338 gave me an ClassCastException
android.text.style.URLSpan cannot be cast to pb.myPackage.LinkUtils$SensibleUrlSpan
or this one handle textview link click in my android app
is there's any straight simple way to achieve this? please let me know.
You could use Chrome Custom Tabs, this is faster than a webview in loading webpages and is pretty simple to customize.
First include the Library:
dependencies {
...
compile 'com.android.support:customtabs:25.1.1'
}
Then in your Activity when you call the method to open a browser add these lines of java:
String url = ¨https://google.com/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent intent = builder.build();
intent.launchUrl(this, Uri.parse(url));
Refer to it's docs for more customization at:
https://developer.chrome.com/multidevice/android/customtabs
I have create an app of payroll system in android and it needs to be save the salary slip in PDF format that's why i need to create pdf of using content from SalarySlip.java.
Thanks.
For devices with API level 19 or more you can use the built in PrintedPdfDocument.
This class is a helper for creating a PDF file for given print attributes. It is useful for implementing printing via the native Android graphics APIs.
// open a new document
PrintedPdfDocument document = new PrintedPdfDocument(context,printAttributes);
// start a page
Page page = document.startPage(0);
// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);
. . .
// add more pages
. . .
// write the document content
document.writeTo(getOutputStream());
//close the document
document.close();
For more advance Features use iText
i am new with android and i try to create Epub reader.
i already read Epub Files in Android Webview and now i am taring create find functionality
i use this code for find any text in webview it works fine but wane i am go to next page
in my app stile my webview display find items .
code :
int i = webViewRead.findAll(text);
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webViewRead, true);
So, my problem is how to hide the result.
I already try to create new instants of my Webview( and Relode Webview Like webViewRead.reload(); ) but its not work for me.
is any anther way to do it.??
(my content witch i display in webview is xhtml pages).
And one More Thing with this method find text is highlighted with Green color
is their any way to display find text in Red color.
Why not use:
webViewRead.clearMatches();
?
Greg