Page 1 of 1

wxPdfDocument links not resolving

Posted: Sat Nov 08, 2014 3:23 pm
by tessman
Hello,

I'm running into an issue when trying to create clickable links within a PDF generated with wxPdfDocument. The problem is that, during generation of a page, I'll do something like:

Code: Select all

int linknum = m_pdf->AddLink();
wxPdfLink page_link(linknum);
page_link.SetLink(page, y);
m_pdf->Link(x, y, width, height, page_link);
which works fine in that it creates a clickable link — but an issue arises if I'm generating this on page 1 and trying to link to something on page 2, the link is invalid. I think this is because the links are added when closing the page, but since no object reference yet exists for page 2, it can't resolve it properly.

Has anyone done anything like this and gotten it to work?

Re: wxPdfDocument links not resolving

Posted: Sat Nov 08, 2014 10:37 pm
by utelle
tessman wrote:I'm running into an issue when trying to create clickable links within a PDF generated with wxPdfDocument. The problem is that, during generation of a page, I'll do something like:

Code: Select all

int linknum = m_pdf->AddLink();
wxPdfLink page_link(linknum);
page_link.SetLink(page, y);
m_pdf->Link(x, y, width, height, page_link);
which works fine in that it creates a clickable link — but an issue arises if I'm generating this on page 1 and trying to link to something on page 2, the link is invalid. I think this is because the links are added when closing the page, but since no object reference yet exists for page 2, it can't resolve it properly.

Has anyone done anything like this and gotten it to work?
For example, take a look at the sample "tutorial 6" coming with wxPdfDocument. It demonstrates how to link from page 1 to page 2.

For internal link references you always have to use method AddLink first to get the link reference number, which you then use on setting the active link area and on setting the link target (using method SetLink). If you know the link target in advance, you can use method SetLink of the class wxPdfLink. Alternatively you can use method SetLink of class wxPdfDocument when you process the page on which the target of the link is located.

Method SetLink of class wxPdfDocument can be used to set the link target as long as you haven't called method Close, or SaveAsFile, or CloseAndGetBuffer, that is, as long as you haven't finished producing PDF page content.

If it still doesn't work for you, show some source code exposing the problem.

Regards,

Ulrich

Re: wxPdfDocument links not resolving

Posted: Sun Nov 09, 2014 5:53 am
by tessman
Thank you. Changing it to use wxPdfDocument::SetLink() instead of wxPdfLink::SetLink() seems to have done it:

Code: Select all

int linkid = m_pdf->AddLink();
wxPdfLink page_link(linkid);
//page_link.SetLink(page, y);
m_pdf->SetLink(linkid, y, page);
m_pdf->Link(x, y, width, height, page_link);
Thanks again.