Wednesday 29 May 2019

How PDF Links works the same way of WebSite Links using ABCPDF Library?

Hi Readers,

Scenario: Read any web site/Page using AddImageUrl function in Abcpdf library but Page/Site has links. How in website links perform the same way in PDF also should work.

Solution: The below code performs the same.

Key Points:

1. If we are not using the below two lines then PDF Links are like normal Text.
  doc.HtmlOptions.AddLinks = true;
  doc.HtmlOptions.LinkPages();

2. An important point to remember is order and the place where to add,

   Either add before the following line like below,
   doc.HtmlOptions.AddLinks = true;
   doc.HtmlOptions.LinkPages();
   int theID = doc.AddImageUrl("https://techinuthan.blogspot.com/"); 
   
     Or the other option is the below sample code,

Sample Code:


using System;
using System.IO;
using WebSupergoo.ABCpdf11; namespace Demos_on_abcpdf {     class Program     {         static void Main(string[] args)         {             string theBasePath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
            string outputFolder = theBasePath + @"\Output\";

            // This Doc class is coming from WebSupergoo.ABCpdf11 namespace.
            Doc doc = new Doc(); 
  
            #region Demo 1 Starts -  Multiple Pages inside single PDF With Links action Perform
            doc.HtmlOptions.AddLinks = true;
            // Converts web page to multiple Images in PDF
            int theID = doc.AddImageUrl("https://techinuthan.blogspot.com/"); 
            while (true)
            {
                if (!doc.Chainable(theID))
                    break;
                doc.Page = doc.AddPage();
                doc.AddImageToChain(theID);
            }
 
            doc.HtmlOptions.LinkPages();
            doc.Save(outputFolder + "ConvertWebPageToMultiplePagesWithLinks.pdf");
            #endregion Demo 1 Ends - Multiple Pages inside single PDF With Links action Perform
 
 
            Console.WriteLine("PDF Generated Successfully");
            Console.ReadLine();
        }
    }
}

Output: 
Check output for this code from this GitHub URL : Multiple WebPages In Single PDF With Link Actions

Happy Coding:)

No comments:

Post a Comment