Convert PDF format data to OTF format
Introduction: With SAP’s built-in standard function modules, such as “CONVERT OTF 2 PDF” or equivalent, we may convert OTF data to PDF format. However, despite extensive internet searches, I was unable to locate any FMs, blogs, or articles that addressed the reverse conversion—from PDF to OTF format.
I therefore considered sharing some code that will ultimately convert PDF data into OTF format. We can design a single module that will include a parameter for importing (PDF data) and a parameter for exporting (OTF data).
Importing Parameter: IV_PDF TYPE FPCONTENT (Form Processing: Content from XFT, XFD, PDF)
Exporting Parameter: ET_OTF_DATA TYPE TSFOTF (Smart Forms: Table OTF)
The OTF conversion code is straightforward but effective and useful for a variety of functionalities. In one business use case, the SAP CRM WEBUI screen has to display an Adobe form (CRM Actions in action profile under Post Processing Framework), which requires data conversion in OTF format.
Please check out below code snippet which accomplishes the required functionality.
DATA: lv_dummy TYPE c, lv_clen TYPE i, lv_line(72) TYPE c, lv_otf TYPE itcoo, lv_len TYPE i, lv_size TYPE i, lv_hex(144) TYPE x. FIELD-SYMBOLS: <l_fs> TYPE c. CLEAR: et_otf_data. DATA(lv_pdf) = iv_pdf. lv_size = 72. DESCRIBE FIELD lv_dummy LENGTH lv_clen IN BYTE MODE. lv_size = lv_size * lv_clen. lv_len = xstrlen( lv_pdf ). WHILE lv_len > lv_size. lv_hex(lv_size) = lv_pdf(lv_size). ASSIGN lv_hex(lv_size) TO <l_fs> CASTING. lv_line = <l_fs>. lv_otf = lv_line. APPEND lv_otf TO et_otf_data. SHIFT lv_pdf LEFT BY lv_size PLACES IN BYTE MODE. lv_len = xstrlen( lv_pdf ). ENDWHILE. IF lv_len > 0. CLEAR: lv_hex, lv_otf, lv_line. lv_hex = lv_pdf(lv_len). ASSIGN lv_hex(lv_size) TO <l_fs> CASTING. lv_line = <l_fs>. lv_otf = lv_line. APPEND lv_otf TO et_otf_data. ENDIF. CLEAR: lv_dummy, lv_clen, lv_line, lv_otf, lv_len, lv_size, lv_hex. UNASSIGN : <l_fs>.
Thank you for reading this article, and please feel free to offer any insightful comments or recommendations.
Lots of people are confusing these 2 notions:
You are talking about converting some data from the envelope of type FPCONTENT to the envelope of type TSFOTF:
You are NOT talking about converting the format PDF to the format OTF. Your code is NOT the reverse of the function module CONVERT_OTF_2_PDF.
If you look at CONVERT_OTF_2_PDF, you will see thousands of lines of code. It's very complex. Your code is only few lines of code, so obviously it's not the reverse algorithm.
I think your code is equivalent to the function module SCMS_XSTRING_TO_BINARY, where the input parameter is BUFFER and the output parameter is BINARY_TAB.
I hope it's clear.
Sandra, I appreciate you reading the post and leaving a comment. That's right, I'm talking about converting data from an envelope of type FPCONTENT to an envelope of type TSFOTF.
I have added one link for one of the business use cases, that I came across during development ( conversion of adobe form data to Smart form format to show in SAP CRM Webui screen).
Above mentioned code helped me to convert the same while other function module ( such as SCMS_XSTRING_TO_BINARY) didn't. In fact, this code is a bit different too from the function module.
In fact, SCMS_XSTRING_TO_BINARY does the same as your logic, but only with tables made of lines whose type is not structured OR structured but only on the first component. I guess in your case, ET_OTF_DATA is of type TSFOTF with 2 components TDPRINTCOM and TDPRINTPAR.
Workaround: we can define an internal table whose lines are not structured and length same as total length of ET_OTF_DATA, call SCMS_XSTRING_TO_BINARY, and transfer the resulting table into ET_OTF_DATA:
Of course, it's stupid code because here I complexify a lot because I do one code just to comply with another code, so yours is better.
If we hard code the length of 72 characters corresponding to the sum of ITCOO components, the code is much more simple: