wxPdfDocument links not resolving  [SOLVED]

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
tessman
Experienced Solver
Experienced Solver
Posts: 86
Joined: Tue Oct 06, 2009 5:25 pm

wxPdfDocument links not resolving

Postby tessman » Sat Nov 08, 2014 3:23 pm

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: 737
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument links not resolving  [SOLVED]

Postby utelle » Sat Nov 08, 2014 10:37 pm

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
Experienced Solver
Experienced Solver
Posts: 86
Joined: Tue Oct 06, 2009 5:25 pm

Re: wxPdfDocument links not resolving

Postby tessman » Sun Nov 09, 2014 5:53 am

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.


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 2 guests