| Author |
Message |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 30/11/2010 10:21:54
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Hi again.
As I mentioned here and here I was in the middle of writing a FreeTextAnnotation and now I solved almost of the problems with it. I must say I'm not very happy with my solution to the rendering problem (is more like a hack than a solution) but at least it works...
If you want to include it in ICEpdf I can contribute it, but of course it needs some integration work, and it actually only supports some functionalities:
- I had to extend the AnnotationFactory
- I had to extend the AnnotationComponent
- I extended the MyAnnotationCallback (wich is normal)
- it does not support the actual edition of the text, only the rendering (because in my case is my app that sets the text), but probably it won't be too difficult to do it
- also missing are things like define if the annotation is movable/resizable
Is this OK?
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 30/11/2010 15:34:02
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1150
Offline
|
We would be very interested in the code contribution for free text. As you mentioned a bit of work is still needed but that OK with me. I can't say for sure if I'll have time to get it into the next release but I will try.
I need to you to email for fax a contributor's agreement to head office. You can get it here, http://www.icepdf.org/community/contribute.html .
Once you've singed off on the legal you can attach it to this issue number, http://jira.icefaces.org/browse/PDF-235. At that point I can put it in the queue and see if we can't get it cut into the next release.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 01/12/2010 03:57:36
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Well, that's complicated I guess, to sign that. I have to forward the issue to my bosses at least... However, is not the first time I contribute code in one way or another to other projects and I never had to sign this kind of agreements. What is the license of ICEpdf? Note that I personally have no problem with that, but I have to ask my boss.
However, now I have a much bigger issue with this. My FreeTextAnnotation is now doing what I want so I move out to the saving issue, wich I did by using the core classes as you've mentioned elsewhere
controller.getDocument().saveToOutputStream(out);
and then I went to open the saved pdf with Acrobat Viewer and all my annotations appear as expected, with the text inside it, very nice...
But then I went to reopen it with the ICEpdf Viewer and nothing appears!!! No annotations at all!!! I was not expecting this and this is a real blocker to my application. I don;t understand what is happening and not quite sure where to look for. Any sugestions?
I did tried some variants, like instead of
FreeTextAnnotation extends Annotation
I used
FreeTextAnnotation extends LinkAnnotation
hopping the Viewer will recognise it but no success. I also tried several things by working directly with the Viewer in stand-alone mode but with mixed results...
This is really a no-go for my project, if you have any pointer at all please let me know.
Cheers.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 01/12/2010 06:03:45
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1150
Offline
|
ICEpdf is licensed under Mozilla Public License (MPL).
Do you know if you can save the file with ICEpdf and then open the file again with ICEpdf and still see the annotations you created. I'm curious if Acrobate is touching up the file or if there is something in the ICEpdf write that is preventing it from finding the new annotation?
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 01/12/2010 07:05:33
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Yes, I tried that and it's what I was calling "mixed" results. First time I tried, no annotation appeared on the Viewer. I then tried again with some breakpoints for debugging and - just like that - the annotations appeared but with only a black border in it (my FTAnnotations have text and a red border).
This issue of then only appearing while I debug is clearly a threading issue but I don;t have a clue how to solve it.
Anyway, while debugging I did see that all the annotations are there, with the correct sub-type "FreeText", so I went up to change the Annotation creation:
Code:
if (subtype != null) {
if (subtype.equals(SUBTYPE_LINK))
annot = new LinkAnnotation(library, hashTable);
if (subtype.equals(SUBTYPE_FREETEXT))
annot = new FreeTextAnnotation(library, hashTable);
}
I did step into the code and saw that the correct FreeTextAnnotation is being created, but otherwise everithing stays the same, no annotation running normally and a black annotation if I stop in a breakpoint...
Note that in Acrobat everything is OK, the text appears in the correct location and the box is red. And I didn;t save the pdf in Acrobat.
I'll try to do some more testing.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 01/12/2010 07:18:29
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1150
Offline
|
Can you take a close look at public AnnotationComponent addAnnotationComponent(Annotation annotation) in the AnnotationHandler. I'm curious if the component are getting created as expected.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 02/12/2010 04:41:52
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Well, there were a lot of different problems here, I identified all of them but for some I don't know how to solve.
1) threading problem
there is a problem if I try to do something on my code immediately after I open a document, for example:
Code:
controller.openDocument(filePath);
Annotation[] ann = getAnnotations();
in my code, ann is null even if there are annotations on the doc. However, if I put a BP in that line and step over it, then I will get all annotations alrigth. This is afaict a sync problem, there should be something like a
controller.openDocument(String path, boolean wait);
2) disappearing annotations
it is a consequence of 1), in fact my code was setting the annotations to null in the getAnnotation() method and when the ICEpdf code reached the rendering phase they were already setted to null....
3) rendering without text
my fault, my FreeTextAnnotation was wrongly setting the text to a default value ("") even when there was already text in it...
4) border as black instead of red
this seems to be a different behaviour of the spec between annotation types. My FreeTextAnnotation is using only the DA dictionary entry, where I specified the red color. That is enough for Adobe Reader that paints both the text and the box border in red.
ICEpdf, however, relies only on the "C" entry, and since I was not setting it, it paints in the default black. But if I do set "C" in FreeTextAnnotation then it renders OK in ICEpdf but in Adobe Reader it will paint all the box red, not only the borders.
I actually didn't have the time to loock at the "AP" entry, wich takes precedence over "DA" in FreeTextAnnotations, maybe if I set it it will behave OK in both. But since "DA" is required and I assume the "C" is behaving correctly for LinkAnnotations, I'll just override the corresponding methods in my FreeTextAnnotation.
So, of all of these only the 1) is behind me, I don;t know what to do in that situation. Do you know how to easily implement that kind of sync, and by easily I mean not changing the ICEpdf code, or at least doing only minor changes?
Thanks again.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 06/12/2010 10:30:04
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Hi again Patrick.
I still have no luck with what I described in 1), and unfortunately I can't do without it, any pointers at all?
Cheers.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 06/12/2010 10:34:23
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1150
Offline
|
Right after openDocument what kind of annotation work are you doing? The page initialization happens on different thread in the RI as you suspected.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 06/12/2010 10:46:02
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Well, basically I need to get a handle to all the annotations on the document (both to set the UI in my app and to handle the navigation from my app, i.e. Go To Ann #3).
What I'm doing is to loop all the pages from the doc, get the annotations and store in a array in my app.
But when I do that after opening the document I allways get null. Unless I put some wait() or sleep() for a few seconds... but of course that is a very bad practice...
I was hoping that the document had some flag to instruct a open-and-wait method, or some kind of global document property isFullyLoaded, or a event triggered when the asynchronous loading is done. But could find nothing of the like.
Any pointers?
Cheers.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 06/12/2010 11:10:17
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
I just tried to override focusGained() in SwingController but the flow never gets there. Strangely, I had a BP in focusGained() and in focusLost() and it never stops there!!
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 06/12/2010 12:29:22
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Another way is for ICEpdf to expose a handle to the thread that does the initialization so I can inspect it or join with mine.
For now I just sleep 2 seconds and it works on my machine, but I can't ship my machine with the app... :)
I'll try something else tomorrow.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 07/12/2010 07:32:22
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1150
Offline
|
When you make a call to SwingController.openDocument it should be happening on the AWT event thread. The openDoucment method doesn't kick off any new threads. There are only two threads accessed through a thread pool that are used by the PageComponent when the become visible in the viewer ri.
When you iterate over all of a documents pages and annotations you are likely fighting the memory manager class. Consider that it is possible to get the first pages annotations and store them locally but as you read further into the document the memory manager will likely clear the first pages resources (including the annotations) if it needs more memory to keep reading though the document. The memory manager uses a fifo linked list to manage viewed pages.
I would recommend you thing about your current application functionality and see if you can't do the annotation grab in a lazy fashion. The only way to guarantee that a page won't get reclaimed by the memory manager is to the the following construct:
Page page = document.getPageTree().getPage(pageIndex, objectLock);
....
page.getPageTree().releasePage(page, objectLock);
A Proxy or Facade construct might help you display some annotation information and differ any page locking until a users generates some UI event.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 07/12/2010 09:40:18
|
amsmota
Joined: 01/11/2010 05:48:28
Messages: 64
Offline
|
Hi, thanks for your help. However, I tried
Code:
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
getAllAnnotations();
}
});
but the variant invokeAndWait and checking isDispatchThread, but nothing works.
What bothers me is that a simple Thread.sleep(2000) will do, but of course I can't rely on that...
I'm going to check your other pointers now...
Cheers.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 05/07/2011 16:50:13
|
patrick.corless
Joined: 26/10/2004 00:00:00
Messages: 1150
Offline
|
Have you given any more thought to submitting your code to the project?
|
|
|
 |
|
|