1

I am new in MS Access. I have pdf file location in textbox. I want when access report load then specific pdf file preview in that report (pdf read from file location). How can I achieve it? Please help?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Hunzla Ali
  • 383
  • 2
  • 5
  • 22

2 Answers2

1

You can display PDF in Report by converting its pages to images and display them. Withwsh.Runyou can extract duringReport_Loadevent, then store the pages paths in a temporary table.

  1. Have Irfanview with PDF-Plugin installed.
  2. In Front-End, create a table namedTmpExtractedPageswith oneShort-Textfield namedPathto store the paths of the extracted pages.
  3. Create a report with Record-Source.
SELECT TmpExtractedPages.Path FROM TmpExtractedPages;
  1. Add a Picture-Control in Detail-Section (no Header/Footer-Section), that fits to the page and bind it toPath
  2. Put the following code inReport_Loadevent
Private Sub Report_Load()
Dim TempPath As String
TempPath = CurrentProject.Path & "\TempPdf"

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FolderExists(TempPath) Then
    fso.DeleteFolder TempPath
End If
fso.CreateFolder TempPath

Dim PdfFile As String
PdfFile = Me.OpenArgs

Const PathToIrfanView As String = "C:\Program Files (x86)\IrfanView\i_view32.exe"

Dim CmdArgs As String
CmdArgs = Chr(34) & PdfFile & Chr(34) & " /extract=(" & Chr(34) & TempPath & Chr(34) & ",jpg) /cmdexit" 'see i_options.txt in IrfanView folder for command line options

Dim ShellCmd As String
ShellCmd = Chr(34) & PathToIrfanView & Chr(34) & " " & CmdArgs
Debug.Print ShellCmd

Dim wsh As Object
Set wsh = CreateObject("WScript.Shell")

Const WaitOnReturn As Boolean = True
Const WindowStyle As Long = 0

wsh.Run ShellCmd, WindowStyle, WaitOnReturn

With CurrentDb
    .Execute "Delete * From TmpExtractedPages", dbFailOnError

    Dim f As Object
    For Each f In fso.GetFolder(TempPath).Files
        .Execute "Insert Into TmpExtractedPages (Path) Values ('" & Replace(f.Path, "'", "''")  & "');", dbFailOnError
    Next f
End With

Set fso = Nothing
Set wsh = Nothing
End Sub

You provide the path to the PDF to display asOpenArgsargument on open report:

DoCmd.OpenReport "rpt_pdf", acViewPreview, , , , "path\to\pdf"

Keep in mind that adding, then deleting records to the temp table, will bloat your database if you don't compact it later (or just deploy a fresh Front-End copy on start, as I do).

ComputerVersteher
  • 2,638
  • 1
  • 10
  • 20
0

If you just need to display the pdf file, you could create a button next to the textbox and in its on click event:

Private Sub cmdView_Click()
    If Nz(Me.txtPdfLocation) <> "" Then
       Application.FollowHyperlink Me.txtPdfLocation
    End If
End Sub
Jim B
  • 420
  • 3
  • 10