Forum Stats

  • 3,853,680 Users
  • 2,264,253 Discussions
  • 7,905,427 Comments

Discussions

APEX emails empty report (pdf) as attachment

newjack
newjack Member Posts: 10 Red Ribbon
edited Dec 16, 2019 3:50PM in APEX Discussions

I have attempted to email a pdf report (shared components BI Publisher rtf template) as an attachment. The email is generated but a blank pdf is attached that cannot be opened. When trying to open document, the popup says the file type is wrong or corrupted. My APEX process calls the 3 below procedures to attach the report.

APEX_UTIL.DOWNLOAD_PRINT_DOCUMENT...  (also tried APEX_UTIL.GET_PRINT_DOCUMENT)

APEX_MAIL.SEND...

APEX_MAIL.ADD_ATTACHMENT...

I don't have much experience with the apex_uitl print procedures. Any thoughts of why the pdf is failing?

newjack

Best Answer

  • Mike Kutz
    Mike Kutz Member Posts: 6,199 Silver Crown
    edited Dec 16, 2019 1:57PM Answer ✓
    newjack wrote:The email is generated but a blank pdf is attached that cannot be opened. When trying to open document, the popup says the file type is wrong or corrupted. 

    If you open the file in a HEX editor, the first few bytes should be "PDF%".  If not, then, what was sent was NOT a PDF.  (hence : "wrong type" error)

    99% of the time, what was sent was actually an HTML Error page.  To verify, save the file, change the extension to HTML, and open it  up in Firefox/other.

    From there, the most common problem is ACL.  (The HTML page should show what the actual error is.)

    PROPER FUNCTION CALL

    You should be using APEX_UTIL.GET_PRINT_DOCUMENT().

    This is the only one that will allow you to store and use the generated PDF.  Note: This overloaded function does not work with the print server set to "ORDS (APEX Listener)"

    TODO

    Take a look at what was sent and report your findings.

    REMINDER

    Do not email uncommited data.

    Personally, I'd queue the request to "generate and email report". so that it can be done on committed data in the background.

    MK

    newjacknewjack

Answers

  • Mike Kutz
    Mike Kutz Member Posts: 6,199 Silver Crown
    edited Dec 16, 2019 1:57PM Answer ✓
    newjack wrote:The email is generated but a blank pdf is attached that cannot be opened. When trying to open document, the popup says the file type is wrong or corrupted. 

    If you open the file in a HEX editor, the first few bytes should be "PDF%".  If not, then, what was sent was NOT a PDF.  (hence : "wrong type" error)

    99% of the time, what was sent was actually an HTML Error page.  To verify, save the file, change the extension to HTML, and open it  up in Firefox/other.

    From there, the most common problem is ACL.  (The HTML page should show what the actual error is.)

    PROPER FUNCTION CALL

    You should be using APEX_UTIL.GET_PRINT_DOCUMENT().

    This is the only one that will allow you to store and use the generated PDF.  Note: This overloaded function does not work with the print server set to "ORDS (APEX Listener)"

    TODO

    Take a look at what was sent and report your findings.

    REMINDER

    Do not email uncommited data.

    Personally, I'd queue the request to "generate and email report". so that it can be done on committed data in the background.

    MK

    newjacknewjack
  • newjack
    newjack Member Posts: 10 Red Ribbon
    edited Dec 16, 2019 3:48PM

    Indeed I was only sending html as an attachment.  I was able to successfully generate using get_print_document(). Thanks for your tips!