Samples

Sample List

Samples written in several programming languages, which show how to use LitePDF ActiveX Control.
They can be found in the folder LITEPDF/demos/ . Here's a samples list:

Hello World sample

The following javascript codes show how to use LitePDF to create a hello world PDF document.
Click HERE to see the generated PDF document.
     var litepdf = new ActiveXObject("LitePDF.PDFDocument");    // Create an instance of LitePDF
     litepdf.SetRegInfo("regname", "regcode");                  // Set reg codes
     litepdf.Open("helloworld.pdf");                            // Open the document
     var page = litepdf.NewPage(600, 800);                      // Create a page of 600x800
     page.DrawText(100, 100, "Hello World.");                   // Draw text
     page.Close();                                              // Close the page
     litepdf.Close();                                           // Close the document

Image sample

The following javascript codes show how to use LitePDF to create PDF document containing an image.
Click HERE to see the generated PDF document.
     var litepdf = new ActiveXObject("LitePDF.PDFDocument");    // Create an instance of LitePDF
     litepdf.SetRegInfo("regname", "regcode");                  // Set reg codes
     litepdf.Open("image.pdf");                                 // Open the document
     var page = litepdf.NewPage(600, 800);                      // Create a page of 600x800
     page.DrawImage(100, 100, "test.jpg");                      // Draw image
     page.Close();                                              // Close the page
     litepdf.Close();                                           // Close the document

Path sample

The following javascript codes show how to draw graphics paths.
Click HERE to see the generated PDF document.
     var litepdf = new ActiveXObject("LitePDF.PDFDocument");    // Create an instance of LitePDF
     litepdf.SetRegInfo("regname", "regcode");                  // Set reg codes
     litepdf.Open("path.pdf");                                  // Open the document
     var page = litepdf.NewPage(600, 800);                      // Create a page of 600x800
     
     //Path 1: Using PDFPath functions
     var path1 = page.NewPath();                                // Create a graphics path
     path1.MoveTo(100, 100);
     path1.LineTo(200, 100);                                    // Add a line
     path1.MoveTo(250, 100);
     path1.CurveTo(300, -50, 300, 250, 350, 100);               // Add a bezier
     path1.MoveTo(400, 100);
     path1.ArcTo(100, 200, 0, 0, 1, 500, 100);                  // Add an elliptical arc 
     path1.SetLineWidth(4); 
     
     // Path2: Add paths using SVG like path string  
     var path2 = page.NewPath();                                
     path2.AddPath("M100,250 L200,250 M250,250 C300,100,300,400,350,250 M400,250 A100,200,0,0,1,500,250"); 
     path2.SetLineWidth(4);
     path2.SetStrokeColor(0, 0, 255);                           // Set stroke color to blue
     
     //Path 3: A complicated path
     var path3 = page.NewPath();
     path3.AddCircle(300, 450, 100); 
     path3.AddPath("M230,420 a50,80,0,0,1,60,0");
     path3.AddPath("M310,420 a50,80,0,0,1,60,0");
     path3.AddPath("M245,480 A100,200,0,0,0,355,480");
     path3.SetLineWidth(4);
     path3.SetStrokeColor(255, 0, 0);                           // Set stroke color to red
     
     page.DrawPath(path1);                                      // Draw the graphics paths
     page.DrawPath(path2); 
     page.DrawPath(path3);                                      
     page.Close();                                              // Close the page
     litepdf.Close();                                           // Close the document

Encryption sample

The following javascript codes show how to encrypt PDF document.
Click HERE to see the generated PDF document.
     var litepdf = new ActiveXObject("LitePDF.PDFDocument");    // Create an instance of LitePDF
     litepdf.SetRegInfo("regname", "regcode");                  // Set reg codes
     litepdf.SetEncryptionMode(2);                              // Set encryption mode to RC4 with 40 bits key.
     litepdf.SetPermission("owner", "user", "R");               // Set permission to allow reading.
     litepdf.Open("encryption.pdf");                            // Open the document
     var page = litepdf.NewPage(600, 800);                      // Create a page of 600x800
     page.DrawText(100, 100, "This document is encrypted.");    // Draw text
     page.Close();                                              // Close the page
     litepdf.Close();                                           // Close the document

Infos sample

The following javascript codes show how to set infos.
Click HERE to see the generated PDF document.
     var litepdf = new ActiveXObject("LitePDF.PDFDocument");    // Create an instance of LitePDF
     litepdf.SetRegInfo("regname", "regcode");                  // Set reg codes
     litepdf.Open("info.pdf");                                  // Open the document
     litepdf.SetTitle("Info Sample");                           // Set document title
     litepdf.SetSubject("Javascript Sample");                   // Set document subject
     litepdf.SetCreator("info.js");                             // Set document creator
     litepdf.SetAuthor("Jack");                                 // Set document author
     litepdf.SetKeywords("PDF, LitePDF, ActiveX, Javascript");  // Set document author
     
     var page = litepdf.NewPage(600, 800);                      // Create a page of 600x800
     page.DrawText(100, 100, "This document shows how to set infos.");    // Draw text
     page.Close();                                              // Close the page
     litepdf.Close();                                           // Close the document

Text sample

The following javascript codes show how to draw text.
Click HERE to see the generated PDF document.
     var litepdf = new ActiveXObject("LitePDF.PDFDocument");    // Create an instance of LitePDF
     litepdf.SetRegInfo("regname", "regcode");                  // Set reg codes
     litepdf.Open("text.pdf");                                  // Open the document
     var page = litepdf.NewPage(600, 800);                      // Create a page of 600x800
     
     var str1 = "LitePDF ActiveX Control is desgined for generating PDF files programmatically. ";
     str1 += "No third party software or plug-ins is needed! ";
     str1 += "Unicode characters, encryptions, paths and images are fully supported. \n";
     
     var str2 = "Rich samples written in all kinds of common languages are given ";
     str2 += "to help you start creating your own projects immediately. ";
     str2 += "These languages include Visual C++, C#, Visual Basic, Delphi, ";
     str2 += "C++ Builder, JScript, Perl, VBScript, ASP, ASP.net and PHP, etc. ";
     
     page.SetLineSpacing(0.6);
     page.DrawTextInBox(100, 100, 400, 100, str1, false);       // Draw text
     page.SetItalic(true);
     page.DrawTextInBox(100, 165, 400, 100, str2, false);       // Draw text
     
     // Determine whether a string could be fit in a rectangle
     page.SetFontColor(0, 0, 255);
     page.SetItalic(false);
     page.SetUnderline(true);
     var nCharsLeft = page.DrawTextInBox(0, 0, 100, 100, str1, true);
     if(nCharsLeft > 0)
         page.DrawText(100, 250, "Str1 could not fit in rectangle [0,0,100,100].");
     
     page.Close();                                              // Close the page
     litepdf.Close();                                           // Close the document





Try LitePDF for FREE!

Get LitePDF now for ONLY $99.95.



Prev Page      Next Page






Generated on Sun Mar 18 15:55:35 2007 for LitePDF by  doxygen 1.5.1-p1