Add annotation to pdf android - android

I want to display pdf in android for that i have user some libraries like vudroid,pdfreader but all these libraries show pdf pages as image i want to implement such functionality that user can view pdf and select text from pdf change background color of text using color picker and save the existing pdf, i have referred some of libraries but they doesn't provide such functionality,please give some idea if such library is available
I have used following libraries
Android PDF Viewer
APDFViewer
droidreader
Thanks

Disclaimer: I'm a developer on the PSPDFKit team
PSPDFKit for Android was recently released as version 2.0 including annotation editing support. We've spent a lot of time in making annotation editing easy – both for developers integrating PDFs in their apps, as for end users. Here is an example of how to create a NoteAnnotation with PSPDFKit:
PSPDFDocument document = ...
// Create the annotation.
final int pageNum = 3;
final RectF pagePosition = new RectF(10, 10, 30, 30);
final NoteAnnotation annotation = new NoteAnnotation(pageNum, pagePosition, "This is a note with cross icon!", CROSS);
// Attach the annotation to the document.
document.getAnnotationProvider().addAnnotationToPage(annotation);
There's also a bunch of ready-to-use UI components for annotation creation and editing. PSPDFKit is a commercial product, but we offer demo versions which can be requested on our website.

Related

Xamarin Forms WebView in Android: Can't open PDF link in HTML inside WebView

I am loading an html page from a web server into a Xamarin Forms WebView. This html page contains links to a PDF file.
In iOS, when the user clicks the link, the PDF file is downloaded and opened.
In Android, when the user clicks the link, nothing happens. Note that several PDF-Viewers are installed on the Android device.
Is there any configuration necessary for make this work in Android:
Here is the code:
if (dict.ContainsKey("url")){
string url = dict["url"];
if (Uri.IsWellFormedUriString(url, UriKind.Absolute)){
NotifWebView.Source = url;
} else {
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = #"<html><body><h1>Fehler!</h1><p>Ungültige oder keine URL oder ungültiges HTML.</p></body></html>";
NotifWebView.Source = htmlSource;
}
}
Thanks for your help!
You can use
https://github.com/xamarin/recipes/tree/master/Recipes/xamarin-forms/Controls/display-pdf
The WebView control can display PDF files on the iOS platform, but not on the Android and Windows Phone platforms due to lack of platform support.You need to create a custom renderer to acheve it in android platform.The process for doing this is as follows:
Create a Xamarin.Forms custom control
Consume the custom control from Xamarin.Forms.
Create the custom renderer for the control on each platform.
If you're willing to spend some money, it looks like Syncfusion has a solution for viewing and editing PDF files.
http://www.syncfusion.com/products/xamarin

Draw contents of a PDF file to a Canvas

My Android app is generating multi-page PDF files programmatically using PdfDocument:
public byte[] buildPDF() {
int pageWidth = Math.round(8.5f * 72f);
int pageHeight = Math.round(11.0f * 72f);
int margin = Math.round(.5f * 72f);
int fontSize = 12;
TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(Color.BLACK);
textPaint.setTextSize(fontSize);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
PdfDocument document = new PdfDocument();
PdfDocument.Page page = null;
Canvas canvas = null;
for (int i=0; i<10; i++) {
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(pageWidth, pageHeight, document.getPages().size()).create();
page = document.startPage(pageInfo);
canvas = page.getCanvas();
String content = "Content for page " + (i + 1);
canvas.drawText(content, margin, margin + fontSize, textPaint);
document.finishPage(page);
}
byte[] output = new byte[0];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
document.writeTo(outputStream);
} catch (Exception e) {
Log.d("buildPDF", "error writing PDF output");
return output;
}
output = outputStream.toByteArray();
document.close();
return output;
}
In some cases, I want to place an existing PDF file from the local device into this series of pages. The easiest workflow would be to somehow open the PDF file as data, then write it to the canvas. Is there any way to do this with the Android SDK?
This is easy in iOS using CGPDFDocumentRef and CGContextDrawPDFPage, but I haven't found an equivalent for Android.
If there's no built-in way, then it seems like the multipdf package in Apache PDFBox might to the job. However, I need the data in memory as shown above, so I think that would require writing the generated data to a temp file, performing operations on the temp file and then reading the data back into memory.
My Android app is generating multi-page PDF files programmatically using PdfDocument:
Note that PdfDocument is designed for use with printing, not for creating arbitrary PDF files.
The easiest workflow would be to somehow open the PDF file as data, then write it to the canvas. Is there any way to do this with the Android SDK?
No, sorry.
CommonsWare answered my specific question (the SDK can't do this), but here's some more info about third-party tools that can:
I tried Apache PDFBox, then realized it's not compatible with Android. Then I found PdfBox-Android and tried installing that, but ran into a series of build problems starting with "The number of Dex files cannot exceed 64,000...." I spent a few hours trying to get that to build before it felt like I was on a wild goose chase and I moved on.
iTextG comes up a lot in situations like this, but I've always followed the rule that if a software company doesn't list its prices on its website, I can't afford it. I did go ahead and send a price request, but they forwarded my request to a reseller, and then the reseller's response went into my spam folder and I didn't see it until it was too late. Their cost was not as high as I feared, but still not very feasible given the relatively small role PDFs play in my app.
I'm already using Radaee PDF as a PDF viewer in my app, and I realized that it includes some document editing and merging functions. I couldn't get this to work with the older library version I was using, but with some help from their tech support I was able to update my project for the current version, and that worked. This requires a Premium license, but they offer a flat fee pricing structure that wasn't out of reach for my project.
So, I spent most of a week dealing with third-party libraries and working out compatibility issues, but once this was running it only took 14 lines of code to get the functionality I wanted. That's a great example of why software development times are so hard to estimate ... LOL.

Use drawable resources for Gboard sticker pack

Is it possible to use drawable resources bundled in your app instead of hosted images for adding stickers to Gboard?
Google provides the following code snippet here to show how to add a sticker to Gboard and it looks like the only way is to reference a hosted image:
new Indexable.Builder("Sticker")
.setName("Bye")
// add url for sticker asset
.setImage("http://www.snoopysticker.com?id=1234")
// see: Support links to your app content section
.setUrl("http://sticker/canonical/image/bye")
// Set the accessibility label for the sticker.
.setDescription("A sticker for Bye")
// Add search keywords.
.put("keywords", "bye", "snoopy", "see ya", "good bye")
.put("isPartOf",
new Indexable.Builder("StickerPack")
.setName("Snoopy Pack")
.build())
.build())};
All help is greatly appreciated!
String drawableResourceUri = Uri.parse("android.resource://your.package.name/drawable/yourfilenamewithoutextension").toString());
Add this string to your setUrl() method.
Google's AppIndexing sample project has an example of the files being generated at run time. This isn't exactly a Drawable resource but the same strategy can likely be used.

How to integrate a interactive pdf viewer with in the android application

I am unable to read PDF file from assets folder. how could i read a PDF in a single page with integrating all controls available for a PDF viewer. I don't want to open a default pdf viewer available in the phone. Please suggest me the right way to achieve interactive PDF viewer with in the android application which can read the pdf from assets/raw folder from the android resource components. Thanks in advance
You can use Intent to load your PDF in external application.
File file = //Load your file from assets here
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
You can load file from assets using InputStream. See this post.
Good luck!
It helped for me:
Barteksc Android Pdf SDK Library
Android PdfViewer AndroidPdfViewer 1.x is available on the
AndroidPdfViewerV1 repo, where can be developed independently. Version
1.x uses a different engine for drawing documents on canvas, so if you don't like the 2.x version, try 1.x.
Library for displaying PDF documents on Android, with animations,
gestures, zoom, and double-tap support. It is based on PdfiumAndroid
for decoding PDF files. Works on API 11 (Android 3.0) and higher.
Licensed under Apache License 2.0.
Which supports Android devices from Android 4.4.4 (KitKat)
Installation
Add to build.gradle:
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
or if you want to use more stable version:
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
Add this into your layout file:
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/your_pdf_id"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
You can Load a PDF file like this:
pdfView.fromUri(Uri)
or
pdfView.fromFile(File)
or
pdfView.fromBytes(byte[])
or
pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
or
pdfView.fromSource(DocumentSource)
or
pdfView.fromAsset(String)
.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
.enableSwipe(true) // allows to block changing pages using swipe
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
// allows to draw something on the current page, usually visible in the middle of the screen
.onDraw(onDrawListener)
// allows to draw something on all pages, separately for every page. Called only for visible pages
.onDrawAll(onDrawListener)
.onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
.onPageChange(onPageChangeListener)
.onPageScroll(onPageScrollListener)
.onError(onErrorListener)
.onPageError(onPageErrorListener)
.onRender(onRenderListener) // called after document is rendered for the first time
// called on single tap, return true if handled, false to toggle scroll handle visibility
.onTap(onTapListener)
.onLongPress(onLongPressListener)
.enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
.password(null)
.scrollHandle(null)
.enableAntialiasing(true) // improve rendering a little bit on low-res screens
// spacing between pages in dp. To define spacing color, set view background
.spacing(0)
.autoSpacing(false) // add dynamic spacing to fit each page on its own on the screen
.linkHandler(DefaultLinkHandler)
.pageFitPolicy(FitPolicy.WIDTH) // mode to fit pages in the view
.fitEachPage(false) // fit each page to the view, else smaller pages are scaled relative to largest page.
.pageSnap(false) // snap pages to screen boundaries
.pageFling(false) // make a fling change only a single page like ViewPager
.nightMode(false) // toggle night mode
.load();
For More Information Github: Barteksc Android Pdf Viewer
I Hope, it Helps!

How to get the link coordinates in EBookDroid of Android for opening the links programmatically

I'm developing a EBookreading application, EBookDroid is a library which we are using for the PDF reading. If we have any links in the PDF like www.stackoverflow.com, when the user clicks on it, it supposed to open the link, for that i need to find out the coordinates of that link in the Document.
I am writing like the below.
final RectF linkRect = page.getLinkSourceRect(pageBounds, link);
But it's always giving the null back.
Try this may be use full
THIS EXAMPLE

Categories

Resources