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?
Asked
Active
Viewed 2,870 times
1
-
AFAIK, only way to view PDF in Access is with WebBrowser control on form. Review https://www.pcreview.co.uk/threads/embedding-pdf-file-in-report.3261155/ – June7 Oct 03 '19 at 19:56
-
But i need to view PDF in report. Is that possible? WebBrowser control is not supported in report. – Hunzla Ali Oct 04 '19 at 05:35
-
Not that I am aware of. – June7 Oct 04 '19 at 05:56
-
Even you can't display PDFs, you can convert them. I use`Irfan View`to extract PDF's to JPG's on`Report_Open`and then I display the extracted pages in report. I can share code if this fits your needs. – ComputerVersteher Oct 08 '19 at 10:09
-
yes please @ComputerVersteher – Hunzla Ali Oct 08 '19 at 13:08
-
@ComputerVersteher can you please share code? – Hunzla Ali Oct 09 '19 at 06:30
-
Sorry, I was too busy the last weeks to share the code, as it needs to be beautified for public. Maybe I can do it this weekend. – ComputerVersteher Oct 25 '19 at 00:46
2 Answers
1
You can display PDF in Report by converting its pages to images and display them. Withwsh.Run
you can extract duringReport_Load
event, then store the pages paths in a temporary table.
- Have Irfanview with PDF-Plugin installed.
- In Front-End, create a table named
TmpExtractedPages
with oneShort-Text
field namedPath
to store the paths of the extracted pages. - Create a report with Record-Source.
SELECT TmpExtractedPages.Path FROM TmpExtractedPages;
- Add a Picture-Control in Detail-Section (no Header/Footer-Section), that fits to the page and bind it to
Path
- Put the following code in
Report_Load
event
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 asOpenArgs
argument 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