cancel
Showing results for 
Search instead for 
Did you mean: 

Generating PDF in Web-Dynpro

Former Member
0 Kudos
742

Hello,

I have a problem with generating a PDF file with ABAP WebDynpro. I have an ALV and there I read a line. From this line I want to build a smartform which should be converted into PDF. I think my coding works. I have no syntax errors and when I debug the coding, everything looks good. I also get my popup that I want to have. But then I got an error: "File does not begin with '%PDF-'."

I look for this error here in SDN but I could not find a solution. I have also tried to do what is mentioned in note 1042424.

Can anybody helps me?

Regards, Markus

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sebastian,

I tried to open an external window and it works. Now I have to put the data from my first windwo to the second window. I have never done this before.

To open the PDF in a popin does not work. You were right.

Regards, Markus

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Now I have to put the data from my first windwo to the second window

The views within both windows share the same component - and therefore they share the same component controller context. Just structure you data there and then you can map your context into both views. Data is shared via reference - meaning that there is only one copy of the data in the component controller context and each view had immediate access to the latest version of the data.

Former Member
0 Kudos

Hi Thomas,

is that true. As I knew so far an external window opening a new browser window would have a new session.

I thought context mapping would just be able by having the new window within a pop in.

If I am wrong, is this new? Because I tried it, and the context was lost in a new window.

Regards

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi Thomas,

>

> is that true. As I knew so far an external window opening a new browser window would have a new session.

> I thought context mapping would just be able by having the new window within a pop in.

>

> If I am wrong, is this new? Because I tried it, and the context was lost in a new window.

>

> Regards

My fault for skimming the thread. I didn't catch that this was an external window. Yes as soon as you open in an external window, you would have a new session - no way around that. I suppose you would have to fall back to some old BSP tricks to pass the data between windows. You could use a Server Cookie (basically just an entry in the database - but with some nice administrative features to clean them up) to pass the data.

Former Member
0 Kudos

Thanks

I would prefer passing elementary parameters as URL parameter. For example:

component_url?parameter_name=value.

Therefore create Importing Parameter in HANDLE_DEFAULT:

paramter_name importing type string.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Thanks

>

> I would prefer passing elementary parameters as URL parameter. For example:

>

> component_url?parameter_name=value.

>

> Therefore create Importing Parameter in HANDLE_DEFAULT:

>

> paramter_name importing type string.

URL parameters are nice and work just fine from WDA as you have described. You just have to be cautious that you don't go beyond the max lenght of a URL (1024) and know that hyou can only pass simple elements - and they all have to be converted to character data type.

That is where Server Cookies can be nice. Like like to take entire internal tables or even classes and serialize them to XML. I can then just store the one byte string as a server cookie and pass the GUID key for the cookie as a URL parameter. That way you get around all the limitations.

Answers (13)

Answers (13)

Former Member
0 Kudos

Ok,

I look for help in SDN to use the parameters. But I have not understood what I have read. Can somebody explain me how to use these parameters step by step. Normally I don't do any web development and so I don't know how to use URL parameters.

I'm really new in web development.

Regards, Markus

Former Member
0 Kudos

How can I use these parameters?

I've never done this before.

No I have the problem, that I don't get the data from the selection into my PDF. The data from the context is empty because of the new session, I think.

Can you help me to get the data from the selection into the new browser window?

Regards, Markus

Former Member
0 Kudos

Generate the URL with one parameter as identifier.

Use it as inbound parameter of window default plug.

With this, you need to retrieve the data newly from the database, because as you said, the context is empty.

Other possibility, without reloading data from database, you need server side cookies.

In there you save the whole data as e.g. table. But therefore, check forum again, for examples.

Former Member
0 Kudos

Ok,

I tried to get the PDF in a new window in my application.

I have an own view for my PDF. This view is in an own window and this window will be started by an own web-dynpro-application.

It's all in one web dynpro project.

I have one URL to start my project with the data selection. When I select a data row from an ALV I push a button. Now a new window opens with a new URL (because of my second web-dynpro-application).

The windows and views use the same context and when I debug my coding, the needed PDF tables are filled. But my new browser window is still empty.

When I open my PDF in a sperate project, then I get my PDF-print.

What is wrong?

Former Member
0 Kudos

Thank you Sebastian,

I've found the mistake. I have written something wrong. A very very small mistake.

Now the PDF works.

But at the end I have another question. How I can get this PDF into a popup? You've said something about a new session.....

Thanks for your great help and your time you've spent for me.

Regards, Markus

Former Member
0 Kudos

Well,

you need to user create_external_window instead of create_window.

In this case you open a new browser window. The context in there has nothing to do with the context of the caller component.

Therefore you usually call another component.

Passing variables can only be done by URL parameters. Therefore you need to generate a new URL.

Variables can be read in the default plug of the window, as Importing Parameter.

Therefore create an inbound parameter in the default plug, give it same name as URL-parameter and define it as string.

But you can give it a try, opening it in a popin. It's just what SAP says. I have not tried it out yet.

For more details search the forum. I do not have an example on hand.

Former Member
0 Kudos

Ok Sebastian,

I tried what you have written. I did it in my Test WebDynpro that has only one view and no popup or anything else. In this Webdynpro I did everything like in the PDF "How to display a smartform as PDF document in Web Dynpro for ABAP".

But the result is always the same, nothing on the screen. I have now idea where the mistake can be.

Former Member
0 Kudos

I am sorry, I do not know how to help you further on.

But maybe you try it again as you did in your first example. Now you can generate the pdf properly. Maybe you will find another output option.

But one last question, you bind the xstring to pdfSource right? Make sure dataSource is not bound and templateSource is not bound.

Former Member
0 Kudos

One last thing I remember. It seems you have an old version of Webdynpro ABAP.

Do you have a javascript error in the left lower corner of your browser?

If so, check note 1096114.

Former Member
0 Kudos

Ok,

I have another WebDynpro Test-Application where I want to implement the PDF on only one view. It is the main view. But there I have the same problems. I see nothing on my screen.

In the application with the popup, I generate a seperate view and window.


*Popup für PDF öffnen
data:   l_cmp_api         type ref to if_wd_component,
        l_window_manager  type ref to if_wd_window_manager,
        M_PDF_POPUP_1     type ref to if_wd_window.


l_cmp_api         = wd_comp_controller->wd_get_api( ).
l_window_manager  = l_cmp_api->get_window_manager( ).

if M_PDF_POPUP_1 is initial.

M_PDF_POPUP_1 = l_window_manager->create_window(

window_name = 'PDF_POPUP' "
*PDF_POPUP is window containing the second view

).
endif.

M_PDF_POPUP_1->open( ).

Former Member
0 Kudos

Hi,

well create_window is not supported, because it generates a popin in the same browser window.

Display it in the same view, which is not a popin.

Configure InteractiveForm like this:

displayType: activeX

height: 700px

visible = true (just after pdf was generated)

with = 100%

pdfSource = contextField

Former Member
0 Kudos

Oh, I forgot.

I have a printer PDF1 with type PDF1. It is like in note 1042424.

Regards, Markus

Former Member
0 Kudos

Hi Sebastian,

thanks for your very good answer. I used some parameters but not all of them.

I have sy-subrc = after the "CALL FUNCTION fm_name".

But now I have some entries in the LT_OTF.

After "CALL FUNCTION 'CONVERT_OTF' " the PDF_DATA is filled, the PDF_SIZE has also a value and sy-subrc is still 0. But my popup is empty.

After "CALL FUNCTION 'CONVERT_OTF' " I have this code:


data:
        node_pdf     type ref to if_wd_context_node,
        elem_pdf     type ref to if_wd_context_element,
        stru_pdf     type        if_componentcontroller=>element_pdf ,
        item_source  like        stru_pdf-source.

* navigate from <CONTEXT> to <PDF> via lead selection
  node_pdf = wd_context->get_child_node( name = if_componentcontroller=>wdctx_changing ).
* get element via lead selection
  elem_pdf = node_pdf->get_element( ).
* set single attribute
  elem_pdf->set_attribute(
    exporting
*      name = `SOURCE`
      name = `PDF`
      value = pdf_data ).

Former Member
0 Kudos

Ok,

getting close. Now your smartform is being generated.

So another question. Do you really have a popup (that means a new window), or a popin (in the window, graying out the background).

Showing PDF files within popins is not supported.

Try first to integrate your InteractiveForm tag within the main view.

Showing the PDF in a real popup should be done by creating a new window. But this window will have a new session.

So start easily integrating it in the same window.

Former Member
0 Kudos

Hi Sebastian,

I've checked the lt_otf and it has no data. It's empty. I checked the "CALL FUNCTION fm_name" and in web gui and windows gui the ls_formdata-otfdata[] is empty. So lt_otf is also empty.

I also checked the pdf_data and it is also empty. The " data: pdf_data type xstring." code is direct in front of the function "CONVERT_OTF".

I tried to do my coding like this:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f0de1eb8-0b98-2910-7996-8a3c2fcf...

But if I do everything like in this PDF, I have the same problem. My Dynpro is still empty.

Thanks for your help.

Regards, Markus

Former Member
0 Kudos

Ok,

we are getting nearer. So first of all, has your user a printer assigned?

Take a look at SU01.

Secondly check sy-subrc after calling the function.

The call of SSF_FUNCTION_MODULE_NAME is neccessary as you did. Calling the smartform needs to be done with the function got by this function.

Additionally set the following parameters:

ls_control_pars-no_dialog = 'X'.
ls_control_pars-langu = sy-langu.
ls_control_pars-getotf = 'X'.

call function 'SSF_GET_DEVICE_TYPE'
 exporting
   i_language = ls_control_pars-langu
 importing
  e_devtype = l_devtype.

ls_output_options-tdprinter = l_devtype.

This needs to be done before calling the smartform.

Do not forget to hand ls_output_options to your smartform after control parameters.

Former Member
0 Kudos

Sebastian, thanks for your help, but I have used the funtions you have written.

I summarize my coding:


call function 'SSF_FUNCTION_MODULE_NAME'
    exporting
      formname                  = 'ZRPM_STECKBRIEF'
    importing
      fm_name                   = fm_name
    exceptions
      no_form                     = 1
      no_function_module    = 2
      others                        = 3.


CALL FUNCTION fm_name
        EXPORTING
          control_parameters =  ls_control_parameters
          is_attributes      =  ls_attributes
          lt_cap             = lt_cap_data
          iv_dateinr         = lv_dateinr
          iv_gate1           = lv_datgate1
          iv_chancen         = lv_chancen
*          IV_RISIKEN         =
*          IV_BEWERTUNG       =
          iv_ziel            = lv_short_texts
          it_fin             = lt_fin_data
          report_reason      = doc_type
        IMPORTING
          job_output_info    = ls_formdata
        TABLES
          it_nutzen          = lt_test3
        EXCEPTIONS
          formatting_error   =  1
          internal_error     =  2
          send_error         =  3
          user_canceled      =  4
          OTHERS             =  5.


lt_otf[] = ls_formdata-otfdata[].
  call function 'SSFCOMP_PDF_PREVIEW'
    exporting
      i_otf                    = lt_otf
    exceptions
      convert_otf_to_pdf_error = 1
      cntl_error               = 2
      others                   = 3.

CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format                = 'PDF'
*        max_linewidth         = 132
      IMPORTING
        bin_filesize          = pdf_size
        bin_file              = pdf_data
      TABLES
        otf                   = lt_otf   
        lines                 = lt_pdf   
      EXCEPTIONS
        err_max_linewidth     = 1
        err_format            = 2
        err_conv_not_possible = 3
        err_bad_otf           = 4
        OTHERS                = 5.


data:
        node_pdf     type ref to if_wd_context_node,
        elem_pdf     type ref to if_wd_context_element,
        stru_pdf     type        if_componentcontroller=>element_pdf ,
        item_source  like        stru_pdf-source.

* navigate from <CONTEXT> to <PDF> via lead selection
  node_pdf = wd_context->get_child_node( name = if_componentcontroller=>wdctx_changing ).
* get element via lead selection
  elem_pdf = node_pdf->get_element( ).
* set single attribute
  elem_pdf->set_attribute(
    exporting
*      name = `SOURCE`
      name = `PDF`
      value = pdf_data ).

Former Member
0 Kudos

In order to analyize that issue, please tell, if the pdf binary is created.

Does pdf_data have any value?

If not, does lt_otf any data.

That gives a hint, if webdynpro or smartform is the problem.

Former Member
0 Kudos

Hey,

thanks for your help!

@Naresh: I wrote this coding in a method in the COMPONENTCONTROLLER. Is that right?

The smartform I want to use is an old one. I used it in windows gui, so it is generated to a function.

In my coding I use function SSF_FUNCTION_MODULE_NAME instead of FUNCTION_MODULE_NAME. Is that a problem?

Has anybody an idea?

Regards, Markus

Former Member
0 Kudos

If you have a binary pdf (xstring), you can give an output via element "InteractiveForm".

This also supports display of common pdfs generated by smartforms.

Just unmark "enabled" in that element.

Thank you for your very quick reply.

In the view for the PDF I have the element "InteractiveForm" and I unmark "enabled".

Now I got no errors, but the popup is empty.

Here are my last rows of coding:


data: pdf_size type i,
        pdf_data type xstring,
        lt_otf      TYPE  tsfotf,
        lt_pdf     TYPE  STANDARD TABLE OF tline.


CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format                = 'PDF'
*        max_linewidth         = 132
      IMPORTING
        bin_filesize          = pdf_size
        bin_file              = pdf_data
      TABLES
        otf                   = lt_otf   
        lines                 = lt_pdf   
      EXCEPTIONS
        err_max_linewidth     = 1
        err_format            = 2
        err_conv_not_possible = 3
        err_bad_otf           = 4
        OTHERS                = 5.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  data:
        node_pdf     type ref to if_wd_context_node,
        elem_pdf     type ref to if_wd_context_element,
        stru_pdf     type        if_componentcontroller=>element_pdf ,
        item_source  like        stru_pdf-source.

* navigate from <CONTEXT> to <PDF> via lead selection
  node_pdf = wd_context->get_child_node( name = if_componentcontroller=>wdctx_changing ).
* get element via lead selection
  elem_pdf = node_pdf->get_element( ).
* set single attribute
  elem_pdf->set_attribute(
    exporting
      name = `PDF`
      value = pdf_data ).

Which fields/tables should be filled that I get results in the popup?

Thanks for your help.

Regards, Markus

Former Member
0 Kudos

Hi Markus

Where are you writing these lines of code ?

Regards

Naresh

Former Member
0 Kudos

Have you ever generated smartforms, before.

The OTF function needs the output of your smartform in order to generate a pdf.

You need to generate your smartform like this:



data ls_control_pars type ssfctrlop.
data ls_ouput_options type ssfcompop.
data ls_output type ssfcrescl.

call function 'FUNCTION_MODULE_NAME'
 exporting
   control_parameters = ls_control_pars
   outout_options       = ls_output_options
   user_settings         = false
   .
   .
importing
  job_outputinfo       = ls_output


then

call function 'CONVERT_OTF'
  exporting
    format = 'PDF'
  importing
   bin_filsize = l_file_size
   bin_file = l_xstring
 tables
  otf = ls_output-otfdata

 lines = lt_lines.

the element lt_lines can be defined as dummy.

But this is just pseudo code. You need to have know how in generating smartforms.

Regards

Edited by: Sebastian Menger on May 14, 2008 12:00 PM

Former Member
0 Kudos

If you have a binary pdf (xstring), you can give an output via element "InteractiveForm".

This also supports display of common pdfs generated by smartforms.

Just unmark "enabled" in that element.