Convert PDF Format Data To OTF Format
Convert PDF Format Data To OTF Format
yashoratna
Participant
01-24-2023 7:22 AM
2 Kudos
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)
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.
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.
https://community.sap.com/t5/technology-blogs-by-members/convert-pdf-format-data-to-otf-format/ba-p/13551953 1/4
10/6/24, 7:53 Convert PDF format data to OTF format - SAP Community
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.
3 Comments
Sandra_Rossi
Active Contributor
01-24-2023 12:34 PM
6 Kudos
a format/formatted data (like JSON, XML, CSV, PDF, XLSX, XSLT, etc.)
the type of the "envelope" which conveys this formatted data (like FPCONTENT, TSFOTF).
You are talking about converting some data from the envelope of type FPCONTENT to the envelope of type
TSFOTF:
https://community.sap.com/t5/technology-blogs-by-members/convert-pdf-format-data-to-otf-format/ba-p/13551953 2/4
10/6/24, 7:53 Convert PDF format data to OTF format - SAP Community
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.
yashoratna
Participant
01-29-2023 10:30 PM
1 Kudo
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.
Sandra_Rossi
Active Contributor
01-30-2023 12:52 PM
0 Kudos
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:
et_otf_data = <table>.
ENDMETHOD.
ENDCLASS.
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:
You must be a registered user to add a comment. If you've already registered, sign in.
Otherwise, register and sign in.
Comment
https://community.sap.com/t5/technology-blogs-by-members/convert-pdf-format-data-to-otf-format/ba-p/13551953 4/4