itext PDF link doesn't work in Microsoft Edge












1















I'm adding a link to a file from a pdf document (created with itext)
this way:



Chunk chunk = new Chunk(fileName, font);
chunk.SetAnchor("./relative/path/to/file");


Link works great if I open document in Google Chrome or Adobe reader.
But it doesn't work if I open my PDF in Microsoft Edge.



Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge? If yes, then how?










share|improve this question

























  • I just tested around a bit. It appears that Edge does not accept relative URIs here, only complete, absolute ones including the protocol, e.g. "file:///C:/Users/mkl/Documents/test.png"

    – mkl
    Nov 19 '18 at 17:46
















1















I'm adding a link to a file from a pdf document (created with itext)
this way:



Chunk chunk = new Chunk(fileName, font);
chunk.SetAnchor("./relative/path/to/file");


Link works great if I open document in Google Chrome or Adobe reader.
But it doesn't work if I open my PDF in Microsoft Edge.



Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge? If yes, then how?










share|improve this question

























  • I just tested around a bit. It appears that Edge does not accept relative URIs here, only complete, absolute ones including the protocol, e.g. "file:///C:/Users/mkl/Documents/test.png"

    – mkl
    Nov 19 '18 at 17:46














1












1








1








I'm adding a link to a file from a pdf document (created with itext)
this way:



Chunk chunk = new Chunk(fileName, font);
chunk.SetAnchor("./relative/path/to/file");


Link works great if I open document in Google Chrome or Adobe reader.
But it doesn't work if I open my PDF in Microsoft Edge.



Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge? If yes, then how?










share|improve this question
















I'm adding a link to a file from a pdf document (created with itext)
this way:



Chunk chunk = new Chunk(fileName, font);
chunk.SetAnchor("./relative/path/to/file");


Link works great if I open document in Google Chrome or Adobe reader.
But it doesn't work if I open my PDF in Microsoft Edge.



Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge? If yes, then how?







c# pdf hyperlink itext microsoft-edge






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 9:56







Olja Muravjova

















asked Nov 15 '18 at 15:02









Olja MuravjovaOlja Muravjova

104




104













  • I just tested around a bit. It appears that Edge does not accept relative URIs here, only complete, absolute ones including the protocol, e.g. "file:///C:/Users/mkl/Documents/test.png"

    – mkl
    Nov 19 '18 at 17:46



















  • I just tested around a bit. It appears that Edge does not accept relative URIs here, only complete, absolute ones including the protocol, e.g. "file:///C:/Users/mkl/Documents/test.png"

    – mkl
    Nov 19 '18 at 17:46

















I just tested around a bit. It appears that Edge does not accept relative URIs here, only complete, absolute ones including the protocol, e.g. "file:///C:/Users/mkl/Documents/test.png"

– mkl
Nov 19 '18 at 17:46





I just tested around a bit. It appears that Edge does not accept relative URIs here, only complete, absolute ones including the protocol, e.g. "file:///C:/Users/mkl/Documents/test.png"

– mkl
Nov 19 '18 at 17:46












1 Answer
1






active

oldest

votes


















2





+50










Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge?



If yes, then how?




Having done some tests it appears that Edge does not support relative links in PDF documents.



It does support absolute links, though, given the full URI, e.g.



chunk = new Chunk("Only ASCII chars in target. Full path.");
chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Attachments/1.png");
doc.Add(new Paragraph(chunk));


In contrast to other PDF viewers (Adobe Reader, Chrome, cf. your previous question in this context) it does not support URL encoding of special characters like Cyrillic ones:



chunk = new Chunk("Cyrillic chars in target. URL-encoded. Full path. NOT WORKING");
chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/" + WebUtility.UrlEncode("Вложения") + "/1.png");
doc.Add(new Paragraph(chunk));


But it does support the special characters in UTF-8 encoding. As UTF-8 PdfString encoding is a PDF-2.0 feature and iText 5 does not support PDF-2.0, one has to cheat a bit to inject strings in UTF-8 encoding here:



chunk = new Chunk("Cyrillic chars in target. Action manipulated. Full path.");
chunk.SetAnchor("XXX");
action = (PdfAction)chunk.Attributes[Chunk.ACTION];
action.Put(PdfName.URI, new PdfString(new UTF8Encoding().GetBytes("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Вложения/1.png")));
doc.Add(new Paragraph(chunk));


Tested with Edge 41.16299.666.0






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322274%2fitext-pdf-link-doesnt-work-in-microsoft-edge%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2





    +50










    Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge?



    If yes, then how?




    Having done some tests it appears that Edge does not support relative links in PDF documents.



    It does support absolute links, though, given the full URI, e.g.



    chunk = new Chunk("Only ASCII chars in target. Full path.");
    chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Attachments/1.png");
    doc.Add(new Paragraph(chunk));


    In contrast to other PDF viewers (Adobe Reader, Chrome, cf. your previous question in this context) it does not support URL encoding of special characters like Cyrillic ones:



    chunk = new Chunk("Cyrillic chars in target. URL-encoded. Full path. NOT WORKING");
    chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/" + WebUtility.UrlEncode("Вложения") + "/1.png");
    doc.Add(new Paragraph(chunk));


    But it does support the special characters in UTF-8 encoding. As UTF-8 PdfString encoding is a PDF-2.0 feature and iText 5 does not support PDF-2.0, one has to cheat a bit to inject strings in UTF-8 encoding here:



    chunk = new Chunk("Cyrillic chars in target. Action manipulated. Full path.");
    chunk.SetAnchor("XXX");
    action = (PdfAction)chunk.Attributes[Chunk.ACTION];
    action.Put(PdfName.URI, new PdfString(new UTF8Encoding().GetBytes("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Вложения/1.png")));
    doc.Add(new Paragraph(chunk));


    Tested with Edge 41.16299.666.0






    share|improve this answer






























      2





      +50










      Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge?



      If yes, then how?




      Having done some tests it appears that Edge does not support relative links in PDF documents.



      It does support absolute links, though, given the full URI, e.g.



      chunk = new Chunk("Only ASCII chars in target. Full path.");
      chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Attachments/1.png");
      doc.Add(new Paragraph(chunk));


      In contrast to other PDF viewers (Adobe Reader, Chrome, cf. your previous question in this context) it does not support URL encoding of special characters like Cyrillic ones:



      chunk = new Chunk("Cyrillic chars in target. URL-encoded. Full path. NOT WORKING");
      chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/" + WebUtility.UrlEncode("Вложения") + "/1.png");
      doc.Add(new Paragraph(chunk));


      But it does support the special characters in UTF-8 encoding. As UTF-8 PdfString encoding is a PDF-2.0 feature and iText 5 does not support PDF-2.0, one has to cheat a bit to inject strings in UTF-8 encoding here:



      chunk = new Chunk("Cyrillic chars in target. Action manipulated. Full path.");
      chunk.SetAnchor("XXX");
      action = (PdfAction)chunk.Attributes[Chunk.ACTION];
      action.Put(PdfName.URI, new PdfString(new UTF8Encoding().GetBytes("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Вложения/1.png")));
      doc.Add(new Paragraph(chunk));


      Tested with Edge 41.16299.666.0






      share|improve this answer




























        2





        +50







        2





        +50



        2




        +50






        Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge?



        If yes, then how?




        Having done some tests it appears that Edge does not support relative links in PDF documents.



        It does support absolute links, though, given the full URI, e.g.



        chunk = new Chunk("Only ASCII chars in target. Full path.");
        chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Attachments/1.png");
        doc.Add(new Paragraph(chunk));


        In contrast to other PDF viewers (Adobe Reader, Chrome, cf. your previous question in this context) it does not support URL encoding of special characters like Cyrillic ones:



        chunk = new Chunk("Cyrillic chars in target. URL-encoded. Full path. NOT WORKING");
        chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/" + WebUtility.UrlEncode("Вложения") + "/1.png");
        doc.Add(new Paragraph(chunk));


        But it does support the special characters in UTF-8 encoding. As UTF-8 PdfString encoding is a PDF-2.0 feature and iText 5 does not support PDF-2.0, one has to cheat a bit to inject strings in UTF-8 encoding here:



        chunk = new Chunk("Cyrillic chars in target. Action manipulated. Full path.");
        chunk.SetAnchor("XXX");
        action = (PdfAction)chunk.Attributes[Chunk.ACTION];
        action.Put(PdfName.URI, new PdfString(new UTF8Encoding().GetBytes("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Вложения/1.png")));
        doc.Add(new Paragraph(chunk));


        Tested with Edge 41.16299.666.0






        share|improve this answer
















        Is it even possible to create a file link inside pdf with itext that will work in Microsoft Edge?



        If yes, then how?




        Having done some tests it appears that Edge does not support relative links in PDF documents.



        It does support absolute links, though, given the full URI, e.g.



        chunk = new Chunk("Only ASCII chars in target. Full path.");
        chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Attachments/1.png");
        doc.Add(new Paragraph(chunk));


        In contrast to other PDF viewers (Adobe Reader, Chrome, cf. your previous question in this context) it does not support URL encoding of special characters like Cyrillic ones:



        chunk = new Chunk("Cyrillic chars in target. URL-encoded. Full path. NOT WORKING");
        chunk.SetAnchor("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/" + WebUtility.UrlEncode("Вложения") + "/1.png");
        doc.Add(new Paragraph(chunk));


        But it does support the special characters in UTF-8 encoding. As UTF-8 PdfString encoding is a PDF-2.0 feature and iText 5 does not support PDF-2.0, one has to cheat a bit to inject strings in UTF-8 encoding here:



        chunk = new Chunk("Cyrillic chars in target. Action manipulated. Full path.");
        chunk.SetAnchor("XXX");
        action = (PdfAction)chunk.Attributes[Chunk.ACTION];
        action.Put(PdfName.URI, new PdfString(new UTF8Encoding().GetBytes("file:///C:/Repo/GitHub/testarea/itext5/target/test-outputs/annotate/Вложения/1.png")));
        doc.Add(new Paragraph(chunk));


        Tested with Edge 41.16299.666.0







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 10:09

























        answered Nov 19 '18 at 18:01









        mklmkl

        54.9k1169149




        54.9k1169149
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322274%2fitext-pdf-link-doesnt-work-in-microsoft-edge%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python