Hyperlink Text

DynamicPDF Generator for .NET (v3 and older) Forum

 Oct 26 2007 3:44 PM
Cete,
I have successfully created PDF documents via VB.net with hyperlinks, but when I try to use a shorter 'text' rather than the entire URL the PDF document doesn't recognize it as a link. Sample code snippets;
 
strLink = "http://www.ecliptek.com/SpecSheetGenerator/specific.aspx?PartNumber=EP13E7E2H-25.000MTR"

strText = "EP13E7E2H-25.000MTR"

The following line displays the entire link and the link works;
strPageText = strlinktest

The following line displays just the strText('EP13E7E2H-25.000MTR') as desired, but it is not recognized as a link;
strPageText = "<a href=""" + strlink + """>" + strText + "</a>"

Thanks for your help.
 Oct 26 2007 5:14 PM
Posted by a ceTe Software moderator
Please show us the lines of code you are using to add the action and the label to the page.  From your desciption I can not tell exactly where you are going wrong. 

Also, there is a very simple example in the help documantation that demonstrates just how to add a link (and the associated text) directly to the page.  This example can be found on the following page, hyperlink example.

Thanks,
ceTe Software Support Team
 Oct 26 2007 5:16 PM
Thank you for the quick reply,

Before send you more code I'd like to try to resolve the issue using the help you referenced, however the link you included in your message does not appear to work - 'page not found'  :-)

 Oct 26 2007 5:17 PM
Link works now. Thanks.
 Oct 26 2007 5:30 PM
OK, I understand the example and I think I can make it work. I notice that your imports include;

Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements

my imports include;

Imports System
Imports DynamicPDF.Generator.Developer
Imports DynamicPDF.Merger.Developer

Thus the classes 'Link' 'Label' etc. aren't recognized? We're using V3. I've been thrown into the middle of this project without any prior experience with your product so I apologize in advance for my rudimentary questions.


 Oct 26 2007 5:46 PM
Sorry about the running dialog here, but I'm learning this as we go. I have all of the issues resolved, and the link now works as desired. The last issue is that the link needs to be added to the end of a sentence(s) without any fixed coordinates. How do I just let it flow with the rest of the text and not fix the position of the label/link.?
 Oct 26 2007 6:34 PM
Posted by a ceTe Software moderator
Great, glad you got it figured out.

Every link page element that you add to a page will have an associated X, Y location.  In your case to add a link element to the end of a sentence you will just need to dynamically calculate that X and Y location.  This can be done by keeping track of the width of each character for the string of text within the label.  Additionally you will need to logically determine when words will go to a new line so that your Y coordinate is also valid.  Following the points from letter to letter and line to line you will be able to get the location of the last word in the sentence and add the link element at the associated area of that last word.

Right now we do not have any particular example that demonstrates this functionality.  This is however likely something that we could but together and probably post sometime next week.  Let us know if you would be interested in seeing this behavior demonstrated and we will work on it.

Thanks,
ceTe Software Support Team
 Oct 26 2007 6:46 PM
Thank you again for your help. I've been able to create a pretty dynamic and complicated PDF document by just using the help docs and your assistance with this issue. That is a testiment to the excellent quality of your software and support.

I would love to see an example of what we're discussing. Our document is created by a VB.net program and the contents of the document vary depending on the information requested by our customers. If it would help I can email you an example so that you can see what the document looks like in it's current version (using a full URL string).
 Oct 29 2007 1:36 PM
Posted by a ceTe Software moderator
Hello,

You can get the character width by using the GetGlyphWidth method of the Font class. You will have to add the width's of all the characters to font out the X position for the link. The width returned by this method is in short and you will have to convert it into float. Following is some sample code for this.

        Document doc = new Document();
        Page page = new Page();
        string str = "ceTe Software Support Team";
        Label label = new Label(str, 0, 10, 500, 20, Font.Helvetica, 12);

        //Split using the " " space character to find the last word
        string[] array = str.Split(new char[]{' '});
        string last = array.GetValue(array.Length - 1).ToString();

        float tot1 = 0;
        float tot2 = 0;

        //Find the total width of the string
        for(int i=0; i<str.Length - 1; i++)
        {
                tot1 += Font.Helvetica.GetGlyphWidth(str[i]);
        }

        //Width of the last word
        for(int i=0; i<last.Length - 1; i++)
        {
                tot2 += Font.Helvetica.GetGlyphWidth(last[i]);
        }

        //Subtract the width of the last word from the total width
        tot1 = tot1 - tot2;

        UrlAction act = new UrlAction(@"http://www.DynamicPDF.com");
       
        //width*fontsize/1000+0.001f , this is used to convert the width into float value
        Link lnk = new Link(tot1*12/1000+0.001f, 10, Font.Helvetica.GetTextWidth(last, 12), 20, act);

        page.Elements.Add(label);
        page.Elements.Add(lnk);

        doc.Pages.Add(page);
        doc.DrawToWeb();

Thanks,
ceTe Software Support Team.
 Nov 07 2007 3:59 PM
ceTe,

I have adapted your sample code, and have used it to dynamically place links and other elements within a page. Thank you very much.

I would like to try and come up with a temporary solution to our need for a link within a table cell. If I build a table with a cell that is 'empty', could I use this method to 'overwrite' the cell area with a link label & text that is sized to fit within the cell boundaries? Would there be any performance or other problems?

Thanks for your help,

Pat

 Nov 07 2007 5:24 PM
Posted by a ceTe Software moderator
Hello Pat,

You can create a table with empty cell and add static labels or text to it without any problem. Can you please explain the temporary solution you mentioned in little more detail so that I can provide you with the correct answer?

Thanks,
ceTe Software Support Team
 Jul 16 2018 8:56 AM
Hi,

The above example was very useful, but I was trying to get the location of Y. In my case the text span to 3 or 4 lines and how do I get the link added to any text inside that textarea?

Your example only works for if there is only one line. Can you pls give me an example of text having multiple lines?

Thanks
Jameel
 Jul 18 2018 10:18 AM
Posted by a ceTe Software moderator
Hello,
 
You can  get the Y and X position of the last word in the TextArea using latest DynamicPDF Generator for .NET product. Please note that you can get the last word in the visible contents of the TextArea. Below is the code sample.
 
Please note that it is not possible to get the X and Y positions of the WORD (which is in between the text) within the lines of TextArea. Also the DynamicPDF product does not supports retrieving individual line text from the TextArea.
 
            String text = " ceTe Software Support Team. This is to test. This is test multiline text added to the PDF.";
            Font fontObj = Font.Helvetica;
            string[] arr = text.Split(new Char[] { ' ' });
            string last = arr.GetValue(arr.Length - 1).ToString();
 
            TextArea area = new TextArea(text, 0, 0, 200, 30);
            area.Height = area.GetRequiredHeight();
 
 
            int lineCount = area.GetVisibleLineCount();
            float lastLineTextWidth = area.GetLineTextWidth(lineCount - 1);
            float oneTextLineHeight = area.GetTextHeight() / lineCount;
            float Yposition = area.Y + (area.GetTextHeight() - oneTextLineHeight);
 
            float latWordXPosition = lastLineTextWidth - fontObj.GetTextWidth(last, 12);
 
            UrlAction act = new UrlAction(@"http://www.DynamicPDF.com");
            Link lnk = new Link(latWordXPosition, Yposition, fontObj.GetTextWidth(last, 12), oneTextLineHeight, act);
 
            Document document = new Document();
            Page page = new Page();
            document.Pages.Add(page);
 
            page.Elements.Add(area);
            page.Elements.Add(lnk);
            document.Draw(@"C:\Temp\MyLinkPDF.pdf");
 
Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 7:54 PM.