#1 2017-12-06 15:39:25

Registered: 2016-01-21
Posts: 35

How to add a simple hyperlink in a PDF document?


I'm trying to add a simple hyperlink in a PDF document. When clicking on it, I want to be redirected on a website, or open a local file, depending of the link content.

I noticed that the TPdfDocument class contains several functions that seems useful to do that, but I'm absolutely unable to use them. Just nothing appear on my document. And I cannot find any info that explain how to use them.

Here is the code I wrote

    std::auto_ptr<TPdfDocumentGDI> pPdfDoc(new TPdfDocumentGDI(false, 0, false, NULL));

    pPdfDoc->Info->Author       = L"Tester";
    pPdfDoc->Info->CreationDate = ::Now();
    pPdfDoc->Info->Creator      = L"Tester";
    pPdfDoc->DefaultPaperSize   = Synpdf::psA4;
    pPdfDoc->UseUniscribe       = true;
    TPdfPage* pPage             = pPdfDoc->AddPage();

    TPdfRect rect;
    rect.Left   = 0;
    rect.Top    = 0;
    rect.Right  = 50;
    rect.Bottom = 50;

    pPdfDoc->CreateHyperLink(rect, "http://www.google.com");


I just get a perfectly blank page when I open the test.pdf file.

I also tried the following variants (based on the few info I found on the internet) :

    TPdfDictionary* pDictionary = pPdfDoc->CreateLink(rect, "http://www.google.com");
    pDictionary->AddItem("S", "URI");
    pDictionary->AddItem("F", "(http://www.google.com)");
    pPdfDoc->VCLCanvas->MoveTo(10, 10);
    ::GDICommentBookmark(pPdfDoc->VCLCanvas->Handle, "http://www.google.com");
    ::GDICommentOutline(pPdfDoc->VCLCanvas->Handle, "http://www.google.com", 0);
    ::GDICommentLink(pPdfDoc->VCLCanvas->Handle, "http://www.google.com", rect, false);

But no way. So if somebody could post a simple example that show how to add a hyperlink in a PDF document, I would be really grateful.


Last edited by jeanmilost (2017-12-06 15:43:39)


#2 2023-07-10 22:59:09

Registered: 2023-06-25
Posts: 7

Re: How to add a simple hyperlink in a PDF document?

The problem is in rect.Top > rect.Bottom if you put

    TPdfRect rect;
    rect.Left   = 0;
    rect.Top    = 50;
    rect.Right  = 50;
    rect.Bottom = 0;

On PdfCanvas, 0 is bottom and 852 is top


Board footer

Powered by FluxBB