I'm writing an iPad app where the user will open PDF documents.
I want to substitute some unique texts with clickable buttons.
ie. if there is a text: "Please click a button" I want to put a button instead (or over) the word "button".
What is the right way to do this?
Thanks!
There is not a straight forward solution to it. What you need to do is following :
1) Search for text 'button'. PDF document text extraction needs to happen before this. Performace depends on how you do this. Some PDF parsers create a marker and while rendering the PDF it indexes the text data of PDF. So searching becomes faster. There can be many more approaches :)
2) Get the bounding box coordinates of the text in screen space.
2) Now draw a platform widget on this coordinate.
Related
I am putting together a simple form for a friend and they want when a button is selected to change from amber, too green.
I have attached PDF to give an idea of what I am looking for. Much like a data validation on excel, but for the life of me I cannot figure out how to do it.
Default: Amber
when clicked: Green
It is certainly possible with PDFs to do that since the appearance of a form field is defined by arbitrary drawing instructions.
However, whether you can do that with a PDF editor wholely depends on the capabilities of the PDF editor.
I would like to make a hybrid app using Flutter. One particular kind of component I'm looking at sounds something like this:
A Chinese character like 家 (which means home) is shown
When an user clicks on the character, it can display its pronunciation (jia)
The user also has the option to click to play the pronunciation
The user can also choose to open a window where an animation of how the character is being written is played.
So for a sentence like: 蓝天是白云的家(literally translated as: The blue sky is the home of the white clouds), each of these 7 characters can be individually clicked and users can choose to display / play pronunciation / show how they are written.
Normal static text won't be rich enough to display all these information. My current idea is to make every character a customized widget with such data embedded within.
This task can be quite huge if each Chinese character (there are approximately 5000 characters that are commonly used) has its own rich data format.
Any suggestions on how to approach this problem in an efficient manner in Flutter?
Thanks in advance!
There are a few ways to do this. Using widgets could definitely be an option, but that's probably going to cause you issues in the long run.
Let's break this into two parts:
1: Displaying the text
Instead of using widgets, I'd suggest using a RichText with many TextSpan children. You could create a custom class that accepts the string, splits it into characters, and puts each character in its own TextSpan. By using TextSpan.recognizer. You could then either use a TapGestureRecognizer with onTap to show the information when tapped if you don't need the position at which it was tapped, or onTapDown/onTapUp if you do (for example if you want to show a popup right where the click happened as opposed to something like a bottom sheet that comes up).
2: Showing the information
Because you're wanting to deal with a large amount of characters, I'd suggest not doing it all in code but instead handling the characters in some other sort of format that can easily be manipulated, for example JSON. That way you can do things like splitting the data it into blocks and loading them as needed, and/or getting them from a web server.
Your data could look something like:
{
"家": {
"pronunciation": "jia",
"audio": "path/to/sound.m4a",
"animation": "path/to/animation.gif"
},
...
}
You could theoretically even do things like start loading the pronunciation files when the character is first shown or when they click on it.
When the character is tapped, you could:
check if data in cache
load the data if needed from network/disk
open bottom sheet or popup displaying the pronunciation info + buttons for audio & drawing animation
I have PDF template with a large text-box. Based on the size of the content, the textbox comes-up with a vertical scroll bar. But issue comes up when I flatten the PDF using PDFStamper, the text box does not have the scroll bar and user see only half of the content.
Is there way to allow scroll bar in the text box after flatten the pdf?
Please note that while designing the textbox in the template we have enabled scroll bar option.
No. Flattening a PDF effectively disables interactivity. What your printer kicks out is what you see on screen. One work around is to drop the font size on the field for long items. Another option is to make the PDF read-only instead flattening it. See this post from the office iText mailing list for more.
I'm developing a book app.My client has provided all the contents of pdf.
I have already implemented all the contents of pdf to book.
But he wanted to highlight a text in that pdf.
The user would like the text to allow for highlighting (like if you're reading a paper book).
Is this possible? Can anyone help me on this, please?
Thanks in advance.
Theoretically yes.. depends on a bit hacking and other things, for example fonts used in the PDF. Have a look at PdfKitten, their demo project can find text in a PDF and highlight it. That should give you a first pointer on how to highlight. If you want to the user to highlight with the touches you would need to be able to transform locations of touches into the PDF to determine where exactly the user touched, but it should be possible.
Can anybody tell me if it is necessary to select the text in a PDF file loaded within a UIWebView, or is it selected on its own?
If it's not selected, how can we implement the selection of text within such a PDF?
The UIWebView actually draws the PDF pages as images so you don't have access to individual items (textfields, images etc.)
Highlighting isn't by far a trivial task. One solution would be to use the CGPDFScanner to parse the page's stream and figure out how to concatenate the transformations for the text operators (TJ, Tj, Tm, Tc, Tw etc.) in order to get the individual glyph positions. If you succeed in doing that the rest should be pretty straight forward.