PDF annotations in Java - java

Actually, still now I have not got the exact way to add different types of annotation/lines/boxes/highlights using the mouse directly on PDF.
I have tried different API (pdfbox, icepdf, iText, aspose) and successfully able to add text, text annotation, box annotation, images, but for each one i have some issue like:
when i add object, it add in a new page
when i add object it remove the old data
i want use the existing ICEPDF viewer to add text, but it does not allow it. and if i try to mix other API with ICEPDF, then I am not able to get the mouse click position where need to add.
There is only one API (ICE PDF) which allow to add box annotation direct on GUI by mouse but it does allow other things.
If not possible in pdf viewer then is there any class which will allow to do this?
I'm also open for any commercial library/class with a one time fee to do that.

I think BFO have added quite a few annotation tools. Have you looked at their tool?

Related

Is there a way to set page orientation to landscape when a specific element is found in OpenHtmlToPDF (or another HTML to PDF converter)?

The functionality for the project that I am currently working is to get data from a WYSIWYG editor and convert all the input to a PDF document. The problem is sometimes there is necessary to add wider tables and this produces a truncated visualization of them.
To solve this problem, I added to the editor (specifically, CKEditor) a HR button but I renamed it to "Change page orientation", so users can click that before inserting a table. In Java, I used iText 7 to detect this element (<hr>) and change the page orientation. This works like a charm.
Example using iText with a simple table
Now, requirements changed and for license purposes we need to replace iText for another HTML to PDF converter, but we need to keep this functionality.
I found OpenHTMLToPdf and I liked it, but I didn't find the way to replicate this page orientation when a hr (or another specific element) is found.
How can I solve that? I can use whatever library as long as they are open source.

Dynamic CSS editing in Vaadin 7

I want to edit the css of an embedded image dynamically and using push, the intention is to build a web browser game and I don't want a 'tool explosion', I'm using Hibernate+JPA, Vaadin, ivy and a tool for server-push.
I don't want to use GWT, partly because the only part of it that I want is the canvas drawing, which seems to be really overkill, GWT is massive and I don't want to learn it at this stage simply so I can draw 2D pictures and move them around smoothly.
Here's how I'm loading an image.
Embedded embedded_1;
....
embedded_1.setSource(new FileResource(
new File(VaadinService.getCurrent().getBaseDirectory().getAbsolutePath()
+"/WEB-INF/images/sun.gif")));
....
mainLayout = new AbsoluteLayout();
mainLayout.addComponent(embedded_1, "top:0.0px;left:0.0px:");
Inside Absolute layout there's a field I want to access.
LinkedHashMap<Component, ComponentPosition> componentToCoordinates ...
I looked at the other methods that get called when I do
mainLayout.addComponent(embedded_1, "top:0.0px;left:0.0px:");
and they don't do anything special, (ie access non-java files or use any dynamically generated code), there's a method that cleans up and validates the CSS, its wrapped into a ComponentPosition object and then it is put unceremoniously into the HashMap.
Why can't I access this HashMap and do edits on the values already mapped by a key without changing the key itself. I want to take an embedded object and change it's css position dynamically, to do that all I would need to do is execute code
componentToCoordinates.get(reference).setString("top:10.0px;left:0.0px;");
and I could generate the string dynamically etc.
Is there a 'proper' way of doing this or is it something I have to create my own solution for?
I found what I was looking for though it wasn't in the form I expected.
There's a method in the layout API called getPosition(Component c) that will return the css string.
You can then change the string and put it back into the Map using setPosition(Component c ComponentPosition cp)

Drag and Drop Drawing in Web

The problem is to create a dynamic label printing where in I will present to the user the fields that are available (ex. Name, ID No, Address etc) and I will let them draw their own label.
It is something like on the left side, there are the available fields, and on the right side is a big field where I let them drag and drop the fields and draw boxes and grids.
The system should be able to save the drawing (in any format as long as it can be saved in the database) that they created and the fields in that drawing can be called in the backend.
The saving part is important because if the user created so many labels, I want them to be able to choose which drawing they can use to Print their labels.
I would like to integrate this with my existing web Maven Spring 3.x system.
If anybody could point to where to look, either in the drawing creation or in the saving it would be great.
I did that drawing/saving stuff in a webapp some time ago using Javascript. Use the HTML canvas element to define a place users can draw on.
Guess there are several js/jquery libraries for that (It is also possible to do everything on your own)
There are also exporting functionalities (I do not remember exactly) but it is possible to convert the drawing to a data-url and upload it with a hidden text field. Of course it can be directly stored on the user's computer as well.
Start by having a look at introduction to canvas drawing on w3cschools.com

Use iText to produce formatted TextFields?

Is there any way in iText to format a TextField's input? I want to have a TextField accept a phone number "(###)###-####", but I don't want the user to have to format it when they enter it. Pdf supports masks on form fields, is there any way to do this in iText?
My current solution is to create the pdf in Acrobat, then populate known fields through iText. But that isn't ideal for this deployment. Ideally I'll have iText generate the entire form.
Thanks for all assistance in advance.
You can add JavaScript to your form that changes the content of fields. See for instance the Calculator example for a fun PDF that acts as a Calculator (obviously this app only works in a PDF viewer that supports JavaScript).
When you create a text field, you need to add an additional action with the setAdditionalActions() method. You can choose between different events: K for keystroke (e.g. useful if you want to change every character to uppercase when somebody fills out a form), Bl for blurred (useful to process the content of a field as soon as the focus is lost), etc.
You can write your own document-level JavaScript to format the fields. See calculator.js for the JavaScript used in the Calculator example. Or you can use one of the many AF methods that are predefined Adobe Reader, such as AFNumber_Format (I don't find an overview of the available methods right now).

Selenium WebDriver and Highchart testing

I know this question has been asked before on S.O. and other websites but I haven't found a definite answer -- most of them say its not easily done but I wanted to make sure that was the final verdict.
Here's my situation:
I'm testing a website that is using Highcharts (http://www.highcharts.com) using Selenium WebDriver (Java).
I basically want to grab the information that is displayed in a small tooltip pop-up that appears when you hover your mouse over each datapoint on the Highchart's line graph.
Looking at the web page's HTML code, I noticed there is <g class="highcharts-tooltip".... I also noticed that, as you move your mouse, the (X,Y) values in ...transform="translate(X,Y)"> change, which then changes the information displayed in the tool tip.
Knowing this, my approach would be to somehow grab all the (X,Y) values and plug them into the transform fields and grab the tooltip data. But I don't know how to programmatically grab all the (X,Y) values through Selenium.
Has anyone tackles this issue in the past or has a better way to grab the necessary information?
I started creating a library to work with HighCharts, what I currently have is available here:
https://github.com/Ardesco/Powder-Monkey/tree/master/src/main/java/com/lazerycode/selenium/graphs
It's quite hard to provide a generic library that deals with HighCharts as the customisation options on the individual charts can modify the SVG markup quite a bit. Hopefully the above will help to a degree.
As I do more it will be updated.
The Line Charts have to have a background to work. If the chart is created with .setBackgroundColour(null), then the "rect" is not added to the html.
I was able to to add the background colour back in set to the body background colour. However I'll try and figure out a way of doing it without the "rect".

Categories