Foxit Quick PDF Library

Can I use Foxit Quick PDF Library with Microsoft Access to generate PDF reports?

Yes, you can use Foxit Quick PDF Library to generate PDF files from Microsoft Access. Below you can find sample C# code which demonstrates how this can be done. The sample demonstrates how to generate a PDF using data obtained from a Microsoft Access database. The C# sample project for this code can be downloaded from the sample projects page on the Foxit website.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DebenuPDFLibraryDLL1312; 
// Copy the "DebenuPDFLibraryDLL1312.cs" file from "C:\Program Files (x86)\Debenu\PDF Library\DLL\Import" to the same folder as Program.cs
namespace Generate_PDF_report_from_Microsoft_Access
{
    class Program
    {
        static void Main(string[] args)
        {
            // Copy full path of *.mdb file here or copy/paste the Books.mdb file into \bin\Debug or \bin\Release
            DBHandling db = new DBHandling(@"Books.mdb");
            //Output file name will be QLPBooks.pdf
            db.WriteBooksRecordsToPDF("DQPLBooks.pdf");
        }

        class DBHandling
        {	// If you want to use the ActiveX edition of the library, swap
            // the two lines of code below.
            // DebenuPDFLibraryAX1312.PDFLibrary pdf = new DebenuPDFLibraryAX1312.PDFLibrary();

            // Copy the "DebenuPDFLibraryDLL1312.dll" file from "C:\Program Files (x86)\Debenu\PDF Library\DLL\" file into \bin\Debug or \bin\Release folders

            PDFLibrary DPL = new PDFLibrary("DebenuPDFLibraryDLL1312.dll");

            OleDbConnection OldeDbcon;
            int YPos;

            public DBHandling(string FilePath)
            {
                string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + FilePath + "\";Persist Security Info=True";
                OldeDbcon = new OleDbConnection(ConStr);
            }

            public void WriteBooksRecordsToPDF(string PdfFileName)
            {
                DPL.UnlockKey("..."); // Insert your license key here!
                int Id = DPL.NewDocument();

                string Query = "SELECT * FROM Books";

                OleDbCommand cmd = new OleDbCommand(Query, OldeDbcon);

                if (OldeDbcon.State != ConnectionState.Open) OldeDbcon.Open();
                OleDbDataReader rdr;
                try
                {
                    rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        YPos = 750;
                        WriteRecord(Convert.ToInt32(rdr["ID"]), Convert.ToString(rdr["Title"]), Convert.ToString(rdr["Author"]),
                        Convert.ToString(rdr["Publisher"]), Convert.ToDouble(rdr["Price"]), Convert.ToString(rdr["ISBN"]));
                        DPL.NewPage();
                    }
                    DPL.SaveToFile(PdfFileName);

                }
                catch (Exception Ex)
                {
                    Console.WriteLine(Ex.ToString());
                    Console.ReadLine();
                }
                OldeDbcon.Close();
            }

            public void WriteRecord(int Id, string Title, string Author, string Publisher, double Price, string ISBN)
            {
                WriteBookTitle(Title); YPos -= 20;
                WriteBookAuthor(Author); WriteBookPrice(Price); YPos -= 20;
                WriteBookPublisher(Publisher); YPos -= 20;
                WriteBookISBN(ISBN);
            }

            public void WriteBookTitle(string Title)
            {
                DPL.AddStandardFont(8);
                DPL.SelectFont(8);
                string FontName = DPL.FontName();
                DPL.SetTextSize(20);
                DPL.DrawText(225, YPos, "Book Title " + Title);
            }

            public void WriteBookAuthor(string Author)
            {
                DPL.AddStandardFont(0);
                DPL.SelectFont(0);
                string FontName = DPL.FontName();
                DPL.SetTextSize(16);
                DPL.DrawText(10, YPos, "Author Name: " + Author);
            }

            public void WriteBookPublisher(string Publisher)
            {
                DPL.AddStandardFont(3);
                DPL.SelectFont(3);
                string FontName = DPL.FontName();
                DPL.SetTextSize(16);
                DPL.DrawText(10, YPos, "Publisher  : " + Publisher);
            }

            public void WriteBookPrice(double Price)
            {
                DPL.AddStandardFont(3);
                DPL.SelectFont(3);
                string FontName = DPL.FontName();
                DPL.SetTextSize(16);
                DPL.DrawText(350, YPos, "Price: " + Price.ToString() + "$");
            }

            public void WriteBookISBN(string ISBN)
            {
                DPL.AddStandardFont(3);
                DPL.SelectFont(3);
                string FontName = DPL.FontName();
                DPL.SetTextSize(16);
                DPL.DrawText(10, YPos, "ISIN   : " + ISBN);
            }
        }
    }
}

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: