wxPdfDocument links not resolving Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
tessman
Earned some good credits
Earned some good credits
Posts: 109
Joined: Tue Oct 06, 2009 5:25 pm

wxPdfDocument links not resolving

Post 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?
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument links not resolving

Post 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
tessman
Earned some good credits
Earned some good credits
Posts: 109
Joined: Tue Oct 06, 2009 5:25 pm

Re: wxPdfDocument links not resolving

Post 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.
Post Reply