Display a pdf-file in a report? (1 Viewer)

Ole

Registered User.
Local time
Today, 03:17
Joined
Apr 15, 2012
Messages
34
Hi
I have a table containing different kind of data including attachment.
When I generate a report I can’t display the attached pdf-file. If I change it to a J-peg it’s no problem.
Does anyone knows how to display the pdf-file in a report?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:17
Joined
Feb 19, 2013
Messages
16,762
Assuming the file is in a directory and not an attachment, use a web control using the path as the controlsource.
 
  • Like
Reactions: Ole

Ole

Registered User.
Local time
Today, 03:17
Joined
Apr 15, 2012
Messages
34
Assuming the file is in a directory and not an attachment, use a web control using the path as the controlsource.
It’s an attachment
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:17
Joined
Feb 19, 2013
Messages
16,762
In that case, don’t think you can. You could try setting a web control control source to the attachment but doubt it would work

only way would be to export the file to a folder and have the web control reference that per my first post
 
  • Like
Reactions: Ole

jdelano

New member
Local time
Yesterday, 21:17
Joined
Mar 22, 2024
Messages
9
Maybe overkill for what you're looking to do but, you could write VBA to launch a console app written in .net (vb or c#) that you pass in some parameters, it executes the report to PDF, saves the attachment as a file and merges the PDFs, then deletes the PDF it created from the attachment file. There is a NuGet package called FreeSpire.PDF that could be used to merge PDF files.
 
  • Like
Reactions: Ole

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:17
Joined
May 21, 2018
Messages
8,705
Even if in attachment. The code
1. Saves to local folder
2. Displays in browser
3. Kills file when done.
 
Local time
Today, 03:17
Joined
Feb 27, 2023
Messages
47
To display a pdf you can convert the pdf to a displayable format (bitmap, jpg, ...) and display the images. That allows usage of print preview with the contents of the pdf(s) shown.

On Report_Open I use IrfanView via shell command to extract from pdf and wscriptshell.run with waitOnReturn = true as argument, to ensure that the command is executed before the rest of vba code, then a table (bound to the report) is filled with the jpg(s) path(s) to display them in an image control:
Code:
Private Sub Report_Open(Cancel As Integer)

Dim rs As DAO.Recordset
Dim sql As String

Dim db As DAO.Database
Set db = CurrentDb
  
sql = "SELECT pathToPDF FROM TableWithPathToPDF WHERE getType(pathToPDF) = 'pdf';"
Debug.Print sql

Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

If rs.RecordCount > 0 Then
    Dim wsh As Object
    Set wsh = CreateObject("WScript.Shell")

    Do Until rs.EOF
        Dim wShellCmd As String
        wShellCmd = """\Path\to\irfanview\i_view32.exe"" """ & rs.Fields("pathToPDF") & """ /extract=(\Path\to\extract\to,jpg) /cmdexit"
        Debug.Print wShellCmd
        Dim ret As Variant
        ret = wsh.Run(wShellCmd, 0, True)
        rs.MoveNext
    Loop
    Set wsh = Nothing
   
    Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Dim oFile As Object
   
    For Each oFile In oFSO.GetFolder("\Path\to\extract\to").Files
        db.Execute "INSERT INTO TableWithPathToExtractedJPGS (pathToExtractedJPGs) VALUES ('" & oFile.Path & "');",dbFailOnError
    Next oFile
    Set oFSO = Nothing
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
btw: you are aware of size limits in Access backends (2GB). Only one reason not to use the Attachment-Field type, as files can be huge. Instead save the files to a share and only save the path to file in share in db.
 
Last edited:
  • Like
Reactions: Ole

Users who are viewing this thread

Top Bottom