cancel
Showing results for 
Search instead for 
Did you mean: 

Convert xstring of xlsx file to PDF

0 Kudos

Hello, is it possible to save xstring which I recieved from xlsx file as pdf file on local pc? I have xstring of xlsx file and than use this FM 'SCMS_XSTRING_TO_BINARY' to convert it to binary format and than call FM 'GUI_DOWNLOAD'

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING
buffer = lv_content
append_to_table = abap_true
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_data1.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = lv_length
filename = 'D:ExcelToPDF.pdf'
filetype = 'BIN'
TABLES
data_tab = lt_data1.

But after that i can't open this file on my pc and getting this error

Is it possible to use xstring which i recieved from xlsx file to convert it into pdf or i totaly wrong?

PascalBremer
Advisor
Advisor

Hi Aleksei,
I think you might have a logic error.
You can of course convert xstring data to binary and reverse this again.

The problem if you want to convert between file formats (xlsx => pdf) you need a dedicated converter.
The reader gives you this error because the file you want to load is an excel file and does not conform to the pdf standard that is expected.

Here was an example how another user converted excel to pdf by calling Microsoft Excel natively from the SAPGUI (using windows ole): https://answers.sap.com/questions/12967544/convert-excel-to-pdf-with-abap-code.html (disclaimer: I did not test it). Alternatively you could load the spreadsheet in abap and render the data with a form template designed by you.

Best regards
Pascal

0 Kudos

Hi Pascal, thanks for the quick response, actually i was trying to speed up pdf generation after getting request from FIORI side, and decided to do it by generation excel file with template which is similar to pdf layout( because excel creation is more faster than adobe forms ) in background process( i did it and got the excel xstring ), maybe i will find some solution how to convert this xlsx xstring to pdf xstring.

Accepted Solutions (0)

Answers (1)

Answers (1)

Tukutupap
Participant

In theory, what you are trying to do would be as if you took a xls on your desktop and changed the extension to .pdf and opened it. Basically you are getting a string that contains the guts of an excel and just changing the extension upon download, so that is why it doesn't work.

Granted I have never done this, but I would think you'd need to do some digging around how to open that excel, read the contents in an internal table and then that use that to build your PDF.

Like I said, I've never done this and I don't have a code snippet I can share with you, but a quick search returned these. I hope they point you in the right direction.

Also following for other ideas!

1. Convert Excel to PDF file

2. Convert Excel to PDF with ABAP Code

3. How to save a EXCEL as PDF by ole coding

4. Export EXCEL Workbook as PDF through SAP

0 Kudos

Hi Vicente, thanks for the quick response, actually i was trying to speed up pdf generation after getting request from FIORI side, and decided to do it by generation excel file with template which is similar to pdf layout( because excel creation is more faster than adobe forms ) in background process( i did it and got the excel xstring ), maybe i will find some solution how to convert this xlsx xstring to pdf xstring.

Tukutupap
Participant
0 Kudos

Good luck, and please share your progress!