Print Page | Close Window

Add Link To Embedded File

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1430
Printed Date: 23 Jun 25 at 9:55AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Add Link To Embedded File
Posted By: syntax3k
Subject: Add Link To Embedded File
Date Posted: 29 Apr 10 at 8:17AM
Hi,

I am new to Quick ODF and currently evaluating it. This is the last bit that I need to do, and it looks like I hit a roadblock.

Situation is this: the pdf is created. There is a certain text in the pdf, and also, there is a st of files. What I need to do is;

1. embed the files
2. find the certain text, create a hotspot to link to the embedded file

The embedding is smooth; however, the AddLinkToEmbeddedFile function always returns zero. I am not sure what I am doing wrong, I hope that someone can help me here, so I can finish this and go and purchase this library.

Here is the part of the code.

qp.LoadFromFile(destinationFile);
                    foreach (KeyValuePair<int, string> file in sourceFiles)
                    {
                        string textToSearch = "Open " + file.Key;
                        int pageCount = qp.PageCount();
                        int pageNumber = 1;
                        int matchesFound = 0;
                        bool fileLinked = false;
                        int fileId = 0;

                        while (pageNumber <= pageCount)
                        {
                            qp.SelectPage(pageNumber);
                            string pageText = qp.GetPageText(3);
                            string[] lines = pageText.Split('\n');
                            string[][] grid = new string[pageText.Length][];

                            for (int i = 0; i < lines.Length; i++)
                            {
                                grid = lines.Split(',');
                            }

                            foreach (string[] line in grid)
                            {
                                if (line == null || line.Length < 12) continue;
                                string findMatch = line[11];

                                if (findMatch.Contains(textToSearch))
                                {
                                    string title = file.Key.ToString() + ".pdf";
                                    if (!fileLinked)
                                    {
                                        fileId = qp.EmbedFile(title, file.Value, "application / pdf");                                                                     fileLinked = true;
                                    }

                                    qp.DrawBox(Convert.ToDouble(line[3]), Convert.ToDouble(line[8]), 100, 20, 0);
                                    int result = qp.AddLinkToEmbeddedFile(Convert.ToDouble(line[3]), Convert.ToDouble(line[8]), 100, 20, fileId, title, 1);
                                }
                            }
                            pageNumber++;
                        }
                    }
qp.SaveToFile(destinationFile);

Everything works just fine, even the box is drawn (I put there to test), however the result variable is always zero (0), suggesting that the link is not added. And fair enough, after everything is done, I open the Pdf file and attachments are embedded, the box is drawn but the link is not created. 

Is there something that I am doing wrong? I even tried to save the document right after embedding but that did not make a difference.

Also, the fileId is always 1. Does that mean it is returning a success code instead of the EmbeddedFileID? If so, how can I get the embedded File ID frmthat function?

Any help would be appreciated.



Replies:
Posted By: Ingo
Date Posted: 29 Apr 10 at 10:46AM
Hi Syntax ;-)

EmbedFile is an old (the wrong one) function if you want to get a file-id.
Try AddEmbeddedFile:
http://www.quickpdflibrary.com/help/quickpdf/AddEmbeddedFile.php

Cheers and welcome here,
Ingo




Posted By: syntax3k
Date Posted: 29 Apr 10 at 11:10AM
Hi Ingo,

Thank you so much. Worked like a charm.

For those, who would need this functionality, here is the revised code:

replace this code:

Quote fileId = qp.EmbedFile(title, file.Value, "application / pdf");      

with this:

Quote fileId = qp.AddEmbeddedFile(file.Value, "application / pdf");    

If QuickPDF guys are reading these forums, may I also suggest using the [Obsolete] tag on the EmbedFile function? I think it would help greatly.

Once again, thank you Ingo.


Posted By: syntax3k
Date Posted: 29 Apr 10 at 1:33PM
I do have another question Ingo (if you don't mind):

I added the link box after adding a new layer, as I found out that, if I do not do that, the link does not go over the "Open xxx" text at all. But even though my box's wodth is set to be 300, it still does not cover the whole "Open xxx" text for some reason. Since the link creating code is the same as above, is that not the right way to do so?

And also (ok, second question), the link always have an icon. Is it possible to not have an icon, or at least have a custom one?

Thank you once again for all your help.


Posted By: Ingo
Date Posted: 29 Apr 10 at 2:50PM
Hi!

'cause of your box:
Perhaps it has to do with different value bases (pixels, mm, inches)?
...Perhaps with different orientations?
Perhaps for the box you can only use pixel and for the rest you've made settings for inches?
You should have a look in this direction.

If you read here:
http://www.quickpdflibrary.com/help/quickpdf/AddLinkToEmbeddedFile.php
You see that there's the standard icon (0) or the disk icon (1).
Perhaps you can try "2"? ...Try it.

Cheers, Ingo




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk