Tuesday 28 May 2019

How to generate a pdf with multiple pages using AddImageUrl function in abcpdf library?

Hi Readers,

In this article, using abcpdf AddImageUrl function, generates a pdf with multiple pages.

If Url has multiple pages then PDF has multiple or else only single page PDF will create.

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
            // 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.Save(outputFolder + "ConvertWebPageToMultiplePages.pdf");
            #endregion Demo 1 Ends - Multiple Pages inside single PDF
 
            Console.WriteLine("PDF Generated Successfully");
            Console.ReadLine();
        }
    }
}

Note: Chainable checks whether any page is associated with the currentID in document. 
If Yes then create a new page or else break it and comeout from the code.


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


Happy Coding:)

No comments:

Post a Comment