Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Printing PDF attachment

former_member369006
Participant
0 Kudos

Hello.

I'd like to print pdf document that is stored in SAP database as attachment to material record.

I am able to successfully read content of attachment thanks to FM SO_DOCUMENT_READ_API1

CALL FUNCTION 'SO_DOCUMENT_READ_API1'
       EXPORTING
         document_id                = lv_docid
       IMPORTING
         document_data              = ls_foldinfo
       TABLES
         object_header              = lt_objhead
         object_content             = lt_objcontent
         contents_hex               = lt_content
       EXCEPTIONS
         document_id_not_exist      = 1
         operation_no_authorization = 2
         x_error                    = 3
         OTHERS                     = 4.


I guess above function returns the content of pdf document in lt_content variable (DATA lt_content TYPE TABLE OF solix).

How can I send the content to spool?


Best regards,

Pawel


16 REPLIES 16

archanapawar
Contributor
0 Kudos

Hi Pawel,

You can download this internal table using GUI_DOWNLOAD on presentation server, then,

you can print the document using method ‘CL_GUI_FRONTEND_SERVICES=>EXECUTE’ passing document path and ‘Print’ command.

ipravir
Active Contributor
0 Kudos

Hi Pawel,

Not clear with your requirement.

Make me clear if I am wrong,  through the Function Module, you are able to fetch the Attachment of any of the Material Document.

After that you want to display the document

or

Want to create a spool for the same, where through SP02, you can see the document based on the Material No.

Regards.

Praveer.

0 Kudos

Hi Praveer.

Yes, I am able to fetch attachment which is a pdf document.

In the next step I would like to create a spool in order to print pdf document.

I would like to make print out as a background process, because we'd like pdf document is printed  automatically during the execution of other SAP transaction.


Regards,

Pawel

ipravir
Active Contributor
0 Kudos

Hi Pawel,

I am not sure, how it could happen, but you can try the below step, may be it will full fill your requirement.

You can create a individual program with one single screen, and through the CL_GUI_HTML_VIEWER you can display the PDF in SAP screen. (Use Full Screen as Container)

Now, inside your main program you have to call the above created program and pass the Material Document as input and execute the Program as Background Job.

You can use below Function Module for Back-Ground Job

Function Module:   JOB_OPEN

and through SUBMIT statement you have to execute the program and pass the Back ground Job number.

Since your Submit program displaying the information, so a spool will generate based on the executed Program

Regards.

Praveer.


0 Kudos

Hi Praveer.

Thank you for your suggestion but I'd rather not to create an program with user interface. I'd prefer to create abap procedure that can be executed in background.

Is there a possibilty to create spool using function modules avoiding user interaction?


Regards,

Pawel

ipravir
Active Contributor
0 Kudos

Hi Pawel,

you can use the below FM to create Spool.

RSPO_OPEN_SPOOLREQUEST.

but to send the information in spool, you have to call a program to store the output in spool.

Regards.

Praveer.

0 Kudos

Hi Praveer.

That's helpful. But do you know what function should I use in order to send binary content to spool.

I suppose I should also convert binary content in pdf format to sth understandable like postscript. Should I use FM SCMS_BINARY_TO_XSTRING?


Regards,

Pawel

ipravir
Active Contributor
0 Kudos

Hi Pawel,

You can use the SCMS_XSTRING_TO_BINARY function module to change the PDF information to Binary Format,

After that, you have to use the CL_GUI_HTML_VIEWER to display the Information in SAP Screen.

Regards.

Praveer.

Former Member
0 Kudos

Hi Pawel ,

                If the data is in internal table , first display the content using grid display(reuse_alv_grid_display) or list display(reuse_alv_list_display)  and in the output use menu option list-->print to take the print out .

Regards ,

Rocky

0 Kudos

Hi Rocky.

As I mentioned I'd like to create program that can be called in background with no user interface.

Do you know wheter print option can be executed by calling ABAP Function Module?

Regards,

Pawel

Clemenss
Active Contributor
0 Kudos

[found on scn]SAP provides a function module ADS_CREATE_PDF_SPOOLJOB, that can put an PDF in the SAP spool system. Example program is FP_TEST_SAVE_PDF_TO_SPOOL.

If not available, check note 0001855522.

Regards Clemens

ipravir
Active Contributor
0 Kudos

Hi Clemens,

I was looking at the program FP_TEST_SAVE+PDF_TO_SPOOL.

Inside the program the same FM called, but my Question in If System in not having the ADS server, will is work?

Because, initially it's checking the ADS server is available or not.

Regards.

Praveer

former_member369006
Participant
0 Kudos

Does anybody have any other suggestions?

I cannot follow Clemens advice because ADS package is not available in my case.


As I mentioned I am able to get binary content of PDF file using function SO_DOCUMENT_READ_API1.

Afterwards applying one of the functions operating with the spool seems to be the right solution.

I tested three of them:

RSPO_SR_TABLE_WRITE_BINARY

RSPO_SR_WRITE_BINARY

RSPO_WRITE_SPOOLREQUEST

but with no success.

Likely due to the fact that binary content of PDF file must be converted to data understandable by printer.


Does anybody know how to achieve that goal?

0 Kudos

Hi Pawel,

when I read your initial question it came to my mind that SAP almost never was a friend of pdf. As you know, it is easy to convert anything to pdf, using 3rd-party tools or using SAP to convert spool output. The other way round is pretty diffficult.

In SAP a precondition for pdf is the installation of Adobe document server ADS. As far as I know this is included in maintenance costs, so basis has to install it to get your task done.

I'd hope there is any better solution but I don't expect too much.

Best regards

Clemens

former_member197132
Participant
0 Kudos

Hello Pawel

i think you 1st you are using  smartform FM for Calling Smartform then other Fm that is  otf To Pdf and then  so_document_Read_Api1...

In above case you will not get print directrly because in 1st FM you are using getoft = 'X'.

use Smartform FM twice and in 1st dont check getotf = 'X'. because when u check getotf -'X' that mens " Return of OTF table. No printing, display, or faxing "

0 Kudos

Hello.

I don't use smartform at all. I have got file attachment to material record that I can get using SO_DOCUMENT_READ_API1 function. Should I convert contents_hex table of SO_DOCUMENT_READ_API1 function in order to print?


Regards,

Pawel