Print Page | Close Window

LoadPDFFileAsBM - returns VB picture

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=498
Printed Date: 29 Apr 24 at 12:00AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: LoadPDFFileAsBM - returns VB picture
Posted By: faypj
Subject: LoadPDFFileAsBM - returns VB picture
Date Posted: 02 Sep 06 at 9:52AM

A newbie to isedquickpdf:

Had looked around most of the alternatives which either were inadequate for my needs or had a hefty royalty for redistribution

Found this forum helpful so I thought I'd put a brief sample code back.

LoadPDFFileAsBM returns a VB picture containing the 1st page of a PDF file. Syntax is very similar to the VB LoadPicture function but has an optional quality setting. There probably is a slightly faster way using setdibits rather than writing to filebut below code works reliably and not too slow.

Usage:

PictureBox1= LoadPDFFileAsBM("MyPDFFile.pdf")

Public Function LoadPDFFileAsBM(FN As String, Optional PDFQuality As Integer = 72) As StdPicture
Dim QP As iSED.QuickPDF
Dim TempFN As String
Dim TempFN1 As String
TempFN = "pdf2bmp.bmp"
TempFN1 = "pdf2bmp1.bmp"
Dim succ As Long
Dim i As Integer
On Error GoTo handler:
Set QP = CreateObject("iSED.QuickPDF")
If Not IsObject(QP) Then
    MsgBox "Could not load isedquickpdf.dll"
Else
    With QP
        If .UnlockKey(PDFKey) <> 1 Then
            MsgBox "Could not unlock isedquickpdf.dll"
        Else
            Screen.MousePointer = vbHourglass
            If ThisFileExists(TempFN1) Then Kill TempFN1
            succ = .LoadFromFile(FN)
            .Unencrypt
            succ = .RenderDocumentToFile(PDFQuality, 1, 1, 0, TempFN)
           
            For i = 0 To 100
                DoEvents
                If ThisFileExists(TempFN1) Then Exit For
            Next
           
            If ThisFileExists(TempFN1) Then
               
                Set LoadPDFFileAsBM = LoadPicture(TempFN1)
                Kill TempFN1
            End If
        End If
    End With
    Set QP = Nothing
    Screen.MousePointer = vbDefault
End If
Exit Function
handler:
Select Case MsgBox("Error " & Err.Number & vbCrLf & _
Err.Description, vbAbortRetryIgnore, "Error LoadPDFFileAsBM")
Case vbRetry: Resume
Case vbIgnore: Resume Next
End Select
Set QP = Nothing
Screen.MousePointer = vbDefault
End Function

Public Function ThisFileExists(ThisFile As String) As Boolean

On Error GoTo handler:
ThisFileExists = False
GetAttr ThisFile
ThisFileExists = True
Exit Function
handler:
End Function




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