Home
Company
Developer Tools
WinI2C/DDC
WiFi-Manager
Advanced PDF Viewer
Overview
Download
Order
Online Help
License Agreement
N-Manager
Utilities
Order
Articles
Contacts
Press
Site map
Member zone


Latest news:
September 2, 2010

Advanced WiFi-Manager v4.6 released!


June 18, 2010

Advanced WiFi-Manager v4.5 released!


June 9, 2010

WinI2C/DDC v3.71 released!









 Advanced PDF Viewer: Developer's Guide


Advanced PDF Viewer consists from one file only: PDFViewer.dll. This file must be located under "<windows>\system32" or any other directory available for the running application. If you want to use Advanced PDF Viewer as COM object then this file must be registered through regsvr32.exe before using.


Advanced PDF Viewer can be used via DLL API functions or as COM object, also it has TPDFViewer class for Delphi (see PDFViewer.pas). To create the most simple application with using Advanced PDF Viwer you must call only three functions: LoadFile , GetPageBmpSize and DrawPageToCanvas. Also it's a good idea to call CheckAcrobatReader firstly to check if Acrobat Reader v9.0 or higher is installed and configured as viewer for PDF files.

Delphi: Create new application, place TImage on the form, set its "Align" property to "AlClient" and create the following event handlers for OnShow and OnClose form events:

...
uses "PDFViewer.pas"
...

var pdf:TPDFView;

procedure TForm1.FormShow(Sender: TObject);
var w, h:integer;
      bmp:tbitmap;
begin
      pdf:=TPDFView.Create(self); //create Advanced PDF Viewer object
      if pdf.LoadFile('c:\Sample_PDF_File.pdf') >ERROR_OFFSET then //load pdf file
      begin
           Showmessage('Some error!');
           exit;
      end;
      pdf.GetPageBmpSize(w, h); //get bitmap size of pdf page
      bmp:=tbitmap.Create; //create temporary bitmap
      bmp.Width:=w; //set its size enough to draw pdf page
      bmp.Height:=h;
      pdf.DrawPageToCanvas(bmp.Canvas.Handle, 0, 0); //draw pdf page to bitmap
      Image1.Picture.Assign(bmp); //copy bitmap to TImage object
      bmp.Free; //free temporary bitmap
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
      pdf.FreeAllResources; //do not forget to call this function before closing application!
end;



C#: Create new Windows application, place on the form PictureBox component and increase its size as much as you can. Use "Project / Add reference" command to add "Advanced PDF Viewer" COM object to the project. Then create the following event handle for "Load" and "FormClosed" form events:

namespace WindowsApplication1
{
      public partial class Form1 : Form
      {
            public PDFViewer.COMPDFView pdf = new PDFViewer.COMPDFView(); //instance of Advanced PDF Viewer
            public Form1()
            {
                  InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                  if (pdf.LoadFile("c:\\Sample_PDF_File.pdf") != 0) //load pdf file
                  {
                        System.Windows.Forms.MessageBox.Show("Some error!");
                        return;
                  }
                  int w, h;
                  pdf.GetPageBmpSize(out w, out h); //get pdf page bitmap size
                  Graphics gr = pictureBox1.CreateGraphics(); //create graphic object
                  Image i = new Bitmap(w, h, gr); //create temporary bitmap
                  Graphics gr2 = Graphics.FromImage(i); //create another graphic object
                  IntPtr dc = gr2.GetHdc(); //get device context (DC) handle for graphic object
                  pdf.DrawPageToCanvas((int)dc, 0, 0); //draw page to graphic object gr2
                  gr2.ReleaseHdc(dc); //release device context handle
                  pictureBox1.Image = i; //copy image to pictureBox object
                  GC.Collect(); //release unecessary memory (you can remove this line)
            }

            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                  pdf.FreeAllResources(); //do not forget to call this function before closing application!
            }
      }
}



You must call FreeAllResources function when Advanced PDF Viewer library is not necessary anymore, this function will release all allocated memory and resources.

Advanced PDF Viewer package contains demo projects for various programming languages (C++, Delphi, VB.NET, C#), see "Samples" directory for details.




   Copyright ©2002-2010, Nicomsoft Ltd. All Right Reserved.  Privacy Policy  |  Terms of Use