We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using PDF Generator- trying to make hyperlinks open in new tab

So I’m generating a PDF with the help of the Aspose.Pdf.Generator namespace.


Trying to get hyperlinks to open up in a new tab(or atleast window) with the help of the following code:


var sourceUrlLinkSegment = new Segment(“View this source”);
sourceUrlLinkSegment.Hyperlink.LinkType = HyperlinkType.Web;
sourceUrlLinkSegment.Hyperlink.Url = clipReportItemDto.SourceUrl;
sourceUrlLinkSegment.Hyperlink.IsLinkToNewWindow = true;
sourceUrlLinkSegment.TextInfo.Color = new Color(52, 120, 183);
sourceUrlLinkSegment.TextInfo.FontSize = valueTextInfo.FontSize;
sourceUrlLinkSegment.TextInfo.FontName = valueTextInfo.FontName;
sourceUrlText.Segments.Add(sourceUrlLinkSegment);

It’s then being added into a table cell if that has anything to do with it.

I assumed IsLinkToNewWindow is the property to use here but it’s not working. As of now we upload the PDF and we open it from the browser. When clicking the link it still opens up the link in the same tab as the PDF(CHROME)

Hi Joakim,


Thanks for contacting support.

In order to accomplish your requirement, please try using Window.open() method to open document in new browser window. Please check following code snippet for the purpose. You can create a new aspx page and add desired code in Page_Load method of that page, later pass that page to Window.open().

<input id=“Button1” type=“button” onclick=“window.open(‘NewWindow.aspx’, ‘pmgw’, ‘toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=750,height=700,top=0’)” Value=“Button” /><o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

protected void Page_Load(object sender, EventArgs e)<o:p></o:p>

{<o:p></o:p>

Pdf pdf = new Pdf();

pdf.Sections.Add();

Aspose.Pdf.Generator.Text sourceUrlText = new Aspose.Pdf.Generator.Text();

var sourceUrlLinkSegment = new Segment("View this source");

sourceUrlLinkSegment.Hyperlink.LinkType = HyperlinkType.Web;

sourceUrlLinkSegment.Hyperlink.Url = "www.google.com";

sourceUrlLinkSegment.Hyperlink.IsLinkToNewWindow = true;

sourceUrlLinkSegment.TextInfo.Color = new Aspose.Pdf.Generator.Color(52, 120, 183);

sourceUrlLinkSegment.TextInfo.FontSize = 14;

sourceUrlLinkSegment.TextInfo.FontName = "Arial";

sourceUrlText.Segments.Add(sourceUrlLinkSegment);

pdf.Sections[0].Paragraphs.Add(sourceUrlText);

pdf.Save(finalStream);

byte[] downloadBytes = finalStream.ToArray();

HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

//HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + documentTitle + ".pdf");

HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + documentTitle + ".pdf");

HttpContext.Current.Response.BinaryWrite(downloadBytes);

HttpContext.Current.Response.End();

}


In case you still face the same problem, please share your sample application.

I think we've had a misunderstanding.

The issue isn't opening the PDF itself in a new window.

The issue is the links inside the pdf opens up in the same tab as the PDF when opening the PDF in the browser.

We have alot of links inside our generated PDF document that the user might want to checkout without loosing their PDF document and having to navigate back all the time and loosing wherever they were in the PDF.
rostigcykel:
I think we've had a misunderstanding.

The issue isn't opening the PDF itself in a new window.

The issue is the links inside the pdf opens up in the same tab as the PDF when opening the PDF in the browser.

We have alot of links inside our generated PDF document that the user might want to checkout without loosing their PDF document and having to navigate back all the time and loosing wherever they were in the PDF.
Hi Joakim,

Thanks for sharing the details.

I am afraid the requested feature is currently not supported but for the sake of implementation, I have logged this requirement in our issue tracking system under New Features list as PDFNEWNET-37320. We will further investigate this requirement in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan