Application Development and Automation 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: 
Read only

Error in Base64 string decoding from .Net

Former Member
0 Likes
2,660

Hi experts,

I have a report for creating the payslip in PDF format. It is working fine, first I get the output in OTF format and later with the FM CONVERT_OTF_2_PDF I save it into PDF file.

Now I have created a Function Module to publish as a Web Service and I want return the output of the FM CONVERT_OTF_2_PDF in Base64 format to consume this web service from a .Net application.

The problem is, after generating the PDF encoding as Base64 string format, it is not decoded well in the .net application.

I have done another test from the .net enviroment, I have encoded the PDF file created before from Sap/abap as a base64 string with the .net, and after this I have decoded and saved it as a PDF and all the steps have worked fine.

Later I have compared the base64 strings: One generated from ABAP and another generated from .Net. The begining of the strings are the same until the position 12320, from this point the characters change until the end of the string.

How should I create the base64 string in abap to create the correct string and decode lately in a .Net application to show the PDF file?

I attached the files generated from abap and the other one generated from .Net.

The One generated from Abap after decoding doesn't show the PDF file correctly but the other one created created from the .Net application It shows correctly.

Thanks for your help.

Kind regards,

Julian.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,995

You can try converting OTF (pdf_t_cust_otf) directly to xstring using function module CONVERT_OTF.

In this snippet, pdf xstring data will come to variable p_cust_xpdf.

If bin_file parameter is not passed, p_pdftab gets filled.

* convert OTF data to pdf xstring

  call function 'CONVERT_OTF'

    exporting

      format                = 'PDF'

    importing

      bin_filesize          = p_cust_xpdf_size

      bin_file              = p_cust_xpdf

    tables

      otf                   = p_t_cust_otf

      lines                 = p_pdftab

    exceptions

      err_max_linewidth     = 1

      err_format            = 2

      err_conv_not_possible = 3

      err_bad_otf           = 4

      others                = 5.

9 REPLIES 9
Read only

Former Member
0 Likes
1,997

You can try converting OTF (pdf_t_cust_otf) directly to xstring using function module CONVERT_OTF.

In this snippet, pdf xstring data will come to variable p_cust_xpdf.

If bin_file parameter is not passed, p_pdftab gets filled.

* convert OTF data to pdf xstring

  call function 'CONVERT_OTF'

    exporting

      format                = 'PDF'

    importing

      bin_filesize          = p_cust_xpdf_size

      bin_file              = p_cust_xpdf

    tables

      otf                   = p_t_cust_otf

      lines                 = p_pdftab

    exceptions

      err_max_linewidth     = 1

      err_format            = 2

      err_conv_not_possible = 3

      err_bad_otf           = 4

      others                = 5.

Read only

0 Likes
1,995

Thanks Manish,

Using the FM CONVERT_OTF how should I pass to .Net the PDF?

As a xstring? or also I should change it to base64?

Kind regards,

Julian.

Read only

0 Likes
1,995

I would say pass base64 encoded string.

In ABAP Debugger, the content of xstring and equivalent string look same, only type differs.

Not sure of data type in .NET which will store the base64 string. (probably string type)

Read only

0 Likes
1,995

Thanks,

Following your comments it's working right.

Kind regards,

Julian.

Read only

arindam_m
Active Contributor
0 Likes
1,995

Hi,

Are you using FM SCMS_BASE64_ENCODE_STR to encode?

Cheers,

Arindam

Read only

Former Member
0 Likes
1,995

Hello Arindam,

Yes, I'm using the scms_base64_encode_str.

Kind regards,

Julian.

Read only

Former Member
0 Likes
1,995

Julian,

What did you do on the .NET side to but the BASE64 into the response?  Are you decoding and then just "Response.Write" or something different?  I can't seem to get the data to actually become a "real" PDF.

Read only

Former Member
0 Likes
1,995

This calls for a detailed blog post or document.

Read only

Former Member
0 Likes
1,995

Hello,

I have something similar to:

---

           local.emaya.emades012.ZhrEssReciboNomResponse salida = new WindowsFormsApplication1.local.emaya.emades012.ZhrEssReciboNomResponse();
            local.emaya.emades012.ZhrEssReciboNom entrada = new WindowsFormsApplication1.local.emaya.emades012.ZhrEssReciboNom();

            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("SAP-USER", "*************");
            local.emaya.emades012.ZWS_ESS_RECIBO_NOM ws = new local.emaya.emades012.ZWS_ESS_RECIBO_NOM();

            ws.Credentials = credentials;
            entrada.pernr = "101800";

            salida = ws.ZhrEssReciboNom(entrada);

            int i;
            i = salida.Pdfbase64.Length;

            byte[] bytes = Convert.FromBase64String(salida.Pdfbase64);
          
            System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output_file_PDF.pdf", System.IO.FileMode.CreateNew);
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            writer.Write(bytes, 0, bytes.Length);
            writer.Close();

---

Kind regards,

Julian.