Print Page | Close Window

Using C# and the DLL edition of Quick PDF Library

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1110
Printed Date: 22 Nov 24 at 6:32PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Using C# and the DLL edition of Quick PDF Library
Posted By: Rowan
Subject: Using C# and the DLL edition of Quick PDF Library
Date Posted: 15 Jun 09 at 10:27AM
This is a short demo of how to use the DLL edition of Quick PDF Library with C#.

// Add the namespaces (first you'll need to. You will need to add a reference to the
// C# import file for the DLL edition.

using System.IO;
using QuickPDFDLL0714;

// Put a button onto the form and add this code to the Click event:

       private void button1_Click(object sender, EventArgs e)
       {
           // Create an instance of the class and give it the path to the DLL
           PDFLibrary qp = new PDFLibrary("...path where the DLL is stored... \\QuickPDFDLL0714.dll");

           // Check if the DLL was loaded successfully
           if (qp.LibraryLoaded())
           {
               // Check the license key
               if (qp.UnlockKey(" ...license key here... ") == 1)
               {
// Draw some text on the PDF
                 qp.DrawText(100, 500, "Hello world from C#");

// Save the new document to disk
                 qp.SaveToFile("c:\\HelloCSharpDLLWorldWorld.pdf");
               }
           }
       }



Replies:
Posted By: vijayan
Date Posted: 27 Oct 09 at 5:51PM
Hi,
 
In the example, it says to add a reference to the DLL; however, within Visual Studio 2008 when I do this, I get the error:
 
"A reference to 'C:\Program Files\Quick PDF Library\DLl\QuickPDFDLL0716.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."
 
How do I get around this?
 
Even so, in the example the path to the DLL seems to be required:
 
PDFLibrary qp = new PDFLibrary("...path where the DLL is stored... \\QuickPDFDLL0714.dll");
 
Is it possible to get a PDFLibrary instance without knowing the path to the DLL? (Assuming of course it is present in the BIN directory of the Windows or ASP.NET application, as normal with other DLL components.)
 
Thanks,
/vijayan
 


Posted By: Ingo
Date Posted: 27 Oct 09 at 8:19PM
Hi!

It's possible to use a normal dll with C#, too...
But perhaps it's better if you try the activeX-version of the dll (don't forget the wrapper-file!).
The other thing: It's okay putting the dll into the system32-directory or into your app-directory and then it's not necessary to know the complete file-path.
It's not possible to register the dll 'cause there's no entry-point (that's normal for many dlls out there).

Cheers, Ingo

Here's the basically content of a form1.cs (from C# 3.5).
A "normal" dll was used...

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

namespace H_PDFtext
{
    public partial class Form1 : Form
    {

        [DllImport(@"your_dll.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "your_functionname")]
        public static extern UInt32 your_functionname(your_parameter_type your_parameter);

        [DllImport(@"your_dll.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "your_next_functionname")]
        public static extern IntPtr your_next_functionname(your_parameter_type your_parameter, ...);

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            nothing = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        // . . .
        
            textBox1.Text = Marshal.PtrToStringAnsi(your_next_functionname(your_parameter, ...));
        }

        private void button2_Click(object sender, EventArgs e)
        {

        // . . .
        
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = Convert.ToString(your_functionname(your_parameter));
        }
    }
}



Posted By: mkinsel
Date Posted: 18 Nov 09 at 2:17AM
Can you use the same approach with VB 2005?  Can you show me a Visual Basic example?



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk