Underline annotation not working correctly cross-platform

75 views
Skip to first unread message

Dhaya Benmessaoud

unread,
Jun 20, 2017, 11:49:42 AM6/20/17
to PDFTron WebViewer
Hi, I'm getting a weird behavior with the "underline" annotation type.

For context, we are developing a cross-platform way of viewing and annotating PDFs using your SDK. The versions currently in use are the following:
- Mobile: 6.715321
- Web: 2.2.2 

When a user annotates a document in the mobile app, the XFDF of it gets saved to a database, so the same user can open the document in the web application and retrieves it with his other annotations. If it's an "Underline" annotation, it gets displayed with a vertical offset (it looks like an "Overline" annotation, as seen in the following image).


We tried looking at differences between the XFDF generated by the mobile and the web, and in this case we have those (line returns are added for legibility):

<!-- Mobile -->
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<annots>
        <underline
            style="solid" width="1"
            color="#FF0000" opacity="1"
            creationdate="D:20170619130841Z00'00'" flags="print" date="D:20170619130841Z00'00'"
            name="wGkcqjttXJJEjqdHunYXLx6wZW0wsAFkhtSW" page="0"
            coords="352.400000,718.418750,538.610000,718.418750,538.610000,730.890430,352.400000,730.890430"
            rect="351.900000,717.918750,539.110000,730.890430" />
    </annots>
    <pages>
        <defmtx matrix="1.333333,0.000000,0.000000,-1.333333,0.000000,1122.666667" />
    </pages>
    <pdf-info version="2" xmlns="http://www.pdftron.com/pdfinfo" />
</xfdf>

<!-- Web -->
<?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<annots>
        <underline
            xmlns="http://ns.adobe.com/xfdf/" subject="Souligner"
            color="#FF0000" opacity="1"
            creationdate="D:20170620095214+02'00'" flags="print" date="D:20170620095216+02'00'"
            name="cde53021-5e29-c12e-4849-bcce2dd978dd" page="0"
            title="nicolas"
            coords="352.4,730.89,538.61,730.89,352.4,718.42,538.61,718.42"
            rect="352.4,718.41875,538.61,730.89043">
            <contents-richtext>
                <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:spec="2.0.2" xfa:APIVersion="Acrobat:10.1.3">
                    <p dir="ltr">
                        <span dir="ltr" style="font-size:10.0pt;text-align:left;color:#000000;font-weight:normal;font-style:normal">Structurer un document</span>
                    </p>
                </body>
            </contents-richtext>
            <contents>Structurer un document</contents>
        </underline>
    </annots>
</xfdf>

Do you know how we can fix the vertical offset that happens with the underline annotation? Please note that this only happens when the we import an annotation from the mobile to the web, it displays correctly the other way around.

Justin Jung

unread,
Jun 20, 2017, 7:01:15 PM6/20/17
to PDFTron WebViewer on behalf of Dhaya Benmessaoud
Hello Dhaya,

We are having trouble reproducing the issue.
Could you send us the pdf document that includes the underline that is displayed upside down in web, but right side up in mobile?

Justin Jung
Software Developer
PDFTron Systems Inc.

Dhaya Benmessaoud

unread,
Jun 21, 2017, 12:11:29 PM6/21/17
to PDFTron WebViewer
Hi Justin,

Using a PDF with inline annotations won't show the exact same problem I have. You can try to replicate the issue by using the unmarked document (in the attachments) and calling annotationsManager.importAnnotations() with XFDF for the annotation generated on mobile (seen on the first post).

I also attached two documents with inline annotations. One generated by the mobile SDK, and another generated by the Web SDK. I opened them in various desktop readers and here are some interesting behaviors:

doc-inline-annot-ios.pdf opened in :
- Preview : OK, underline
- Quicklook : NOK, overline
- Acrobat Reader : NOK, overline
- Chrome Reader (pdfium?) : NOK, overline

doc-inline-annot-web.pdf opened in :
- same clients : OK, underline

What we found with the iOS developer, is that the coords attribute in the generated XFDF are not the same on iOS and Web. Let's imagine the following bounding rectangle :

 A ----------- B
 |             |
 D ----------- C

The coords on iOS follow this pattern: A - B - C - D, while Webviewer will generate the following pattern: D - C - A - B. 
When I take an XFDF annotation from iOS, re-organize the coords points, and import it with the Web SDK, it works as expected.
doc-inline-annot-ios.pdf
doc-inline-annot-web.pdf
doc-unmarked.pdf

Ryan - PDFNet Developer

unread,
Jun 21, 2017, 6:33:30 PM6/21/17
to PDFTron WebViewer
To have iOS match the ordering of WebViewer, please make the following change in TextMarkupCreate.m createTextMarkupAnnot.

from this
for( int i=0; i < num_quads; ++i )
{
PTQuadPoint* quad = [quads get:i];
[mktp SetQuadPoint:i qp:quad];
}
to this
for( int i=0; i < num_quads; ++i )
{
PTQuadPoint* spec_quad = [quads get:i];
PTQuadPoint* quad = [[PTQuadPoint alloc] initWithP11:[spec_quad getP3] y1:[spec_quad getP4] x2:[spec_quad getP2] y2:[spec_quad getP1]];
[mktp SetQuadPoint:i qp:quad];
}
If you are on Xamarin, then you will need to regenerate the Tools.dll, see this for more info if you have not done that before.



Dhaya Benmessaoud

unread,
Jun 28, 2017, 1:02:44 PM6/28/17
to PDFTron WebViewer
Hi, we were able to resolve the issue thanks to your code snippet.
Will it be integrated in a next version of the iOS SDK or are we going to have to replicate the changes when updating to a newer version?

Regards,
Dhaya

Ryan - PDFNet Developer

unread,
Sep 7, 2017, 4:42:09 PM9/7/17
to PDFTron WebViewer
Yes new versions of PDFNet iOS SDK will have the tools updated to create the quads in the more common non-ISO(PDF) way. 
Reply all
Reply to author
Forward
0 new messages