Convert tline into pdf file document in Java

Dear ALL,
     I built a RFC FM to convert smartform into tline which including PDF data.
the Code:
   Converting to PDF Format
  DATA l_lines TYPE TABLE OF tline WITH HEADER LINE.
*  DATA l_lines1 TYPE TABLE OF solix_tab WITH HEADER LINE.
  DATA l_docs TYPE TABLE OF docs.
  DATA len TYPE i.
  CALL FUNCTION 'CONVERT_OTF_2_PDF'
    IMPORTING
      bin_filesize           = len
    TABLES
      otf                    = job_output_info-otfdata[]
      doctab_archive         = l_docs[]
      lines                  = l_lines[]                          "this inner table include pdf file data
    EXCEPTIONS
      err_conv_not_possible? = 1
      err_otf_mc_noendmarker = 2
      OTHERS                 = 3.
  *CALL METHOD cl_gui_frontend_services=>gui_download
  *  EXPORTING
  *   bin_filesize = len
  *    filename     = 'c:\pdf.pdf'
  *    filetype     = 'BIN'
  *   CHANGING
  *    data_tab     = l_lines[]"i_objbin[]
  *  EXCEPTIONS
  *    OTHERS       = 1.
"If i want to save it in my PC ,call this FM CALL METHOD cl_gui_frontend_services=>gui_download.
But i dont want to do it.I want to pass the parameter l_lines[] to java(web) by RFC, and convert to pdf file and show in java(web).
thanks
Freddy

Hi,
Update:
I have tested this and here is some code:
SAP:(I got the OTF from CALL FUNCTION 'PRINT_TEXT')
FORM get_pdf_data
  USING
    tdname TYPE thead-tdname
  CHANGING
    it_tline TYPE text_line_tab
    bin_file TYPE xstring .
  DATA: st_thead TYPE thead .
  DATA: it_lines TYPE tline_tab .
  st_thead-tdobject = 'TEXT' .
  st_thead-tdname   = tdname .
  st_thead-tdid     = 'ST' .
  st_thead-tdspras  = 'E'  .
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                      = st_thead-tdid
      language                = st_thead-tdspras
      name                    = st_thead-tdname
      object                  = st_thead-tdobject
    IMPORTING
      header                  = st_thead
    TABLES
      lines                   = it_lines
    EXCEPTIONS
      id                      = 1
      language                = 2
      name                    = 3
      not_found               = 4
      object                  = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.
  IF sy-subrc NE 0 .
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
  ENDIF.
  DATA: it_otfdata TYPE otf_t_itcoo .
  DATA: st_options TYPE itcpo.
  st_options-tdgetotf = abap_true .
  CALL FUNCTION 'PRINT_TEXT'
    EXPORTING
      dialog                   = abap_false
      header                   = st_thead
      OPTIONS                  = st_options
    TABLES
      lines                    = it_lines
      otfdata                  = it_otfdata
    EXCEPTIONS
      canceled                 = 1
      device                   = 2
      form                     = 3
      OPTIONS                  = 4
      unclosed                 = 5
      unknown                  = 6
      format                   = 7
      textformat               = 8
      communication            = 9
      bad_pageformat_for_print = 10
      OTHERS                   = 11.
  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: it_otfdata_m TYPE otf_t_itcoo .
* "Merge pdf output demo"
  APPEND LINES OF it_otfdata TO it_otfdata_m .
* DATA: bin_file TYPE xstring .
  DATA: it_lines_dummy TYPE tline_tab .
  DATA: bin_filesize TYPE i .
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_file              = bin_file
      bin_filesize          = bin_filesize
    TABLES
      otf                   = it_otfdata_m
      lines                 = it_lines_dummy
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4
      OTHERS                = 5.
ENDFORM.                    " GET_PDF_DATA
Java:
final byte[] byteArray = function.getExportParameterList().getByteArray("BIN_FILE");
final Path path = Paths.get("My.pdf");
Files.write(path, byteArray, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
regards.
Another update:
Using in HttpServlet:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoRepository;
import com.sap.conn.jco.ext.Environment;
import destinations.MyDestination;
public class MyServlet extends HttpServlet {
@Override
protected void doGet(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws ServletException, IOException {
  httpServletResponse.setContentType("application/pdf");
  httpServletResponse.setStatus(HttpServletResponse.SC_OK);
  final ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
  servletOutputStream.write(getPDF());
  servletOutputStream.flush();
  servletOutputStream.close();
private byte[] getPDF() {
  try {
   Environment.registerDestinationDataProvider(new MyDestination());
   final JCoDestination destination = JCoDestinationManager.getDestination(destinations.Id.sapdev2.name());
   final JCoRepository repository = destination.getRepository();
   final JCoFunction function = repository.getFunction("Y_R_EITAN_TESTS_03");
   function.execute(destination);
   final byte[] byteArray = function.getExportParameterList().getByteArray("BIN_FILE");
   return byteArray;
  } catch (final JCoException exception) {
   exception.printStackTrace();
   return null;

Similar Messages

  • Converting pictures into PDF files

    How do I convert pictures into PDF files, is this possible?

    If you want to use acrobat reader, you have to pay for it.
    So, I use other free or cheap apps to do so =>
    * powerpdf
    * dragonprinter (draakprinter in dutch)
    * writepdf
    * scanapp (to convert parts of a picture)
    I even think that almost every scan-app can convert pictures into pdf's.

  • How can i convert image into pdf  file

    Hi Friends,
    I want to convert image file(i.e. jpeg,bmp,gif) into pdf file using java apis OR is there any tool which can convert it & which we can integrate into our java application
    Thanks in adva.

    Is there any solution to this case.....?

  • Urgent: Error while uploading into pdf file

    Hi ,
    I got a requirement that converting smartform into pdf file and sending into application server, And uploading the that pdf file into presentation server once a day am geting error when uploading into pdf format from application server .
    Error : There was an  error while tryinging to parse an image.
    Please help me out its urgent.
    Thanks in advance
    Regards
    krishna
    Edited by: krishna rao on Feb 13, 2008 12:05 PM

    U can use this code
    Reward if useful
    REPORT  ZMN_PDF_UPLOAD.
    data: begin of itab occurs 0,
    field(256),
    end of itab.
    data: dsn(100) value '\usr\sap\DEV\DVEBMGS00\work\testpdf',
    length like sy-tabix,
    lengthn like sy-tabix.
    call function 'GUI_UPLOAD'
    exporting
    filename = 'c:\temp\test.pdf'
    filetype = 'BIN'
    importing
    filelength = length
    tables
    data_tab = itab.
    open dataset dsn for output in binary mode.
    loop at itab.
    transfer itab-field to dsn.
    endloop.
    close dataset dsn.
    clear itab.
    refresh itab.
    *To crosscheck if it went well
    open dataset dsn for input in binary mode.
    do.
    read dataset dsn into itab-field.
    if sy-subrc = 0.
    append itab.
    else.
    exit.
    endif.
    enddo.
    call function 'GUI_DOWNLOAD'
    exporting
    filename = 'c:\temp\testn.pdf'
    filetype = 'BIN'
    bin_filesize = length
    importing
    filelength = lengthn
    tables
    data_tab = itab.
    *Or
    *Use the TCode
    *CG3Z or CG3Y
    *for downloading to Application Server.

  • In smartform word document convert into pdf file

    Hi Experts,
    I have issue on smartform, i have done two page smartform in preview its coming properly but
    when i give to print its not coming properly...output is not coming properly...so please sugest me
    even how to covert smartform word document into PDF file...im waiting for your replay. Thanks in
    Advance....
    Regards
    Ashwini

    Hi,
       I hope its printer problem check with u r basis, and for Smartform to PDF bewlow is my coding in which by using OTF data from Smartform it ill veiw in PDF.
    *& Report  ZSAP_PDF_VIEWER_DEMO_2
    REPORT  ZSAP_PDF_VIEWER.
    DATA: LT_PDF TYPE TABLE OF TLINE,
          LS_PDF LIKE LINE OF LT_PDF,
          LV_URL TYPE CHAR255,
          PDF_FSIZE TYPE  I,
          LV_CONTENT  TYPE XSTRING,
          LT_DATA TYPE STANDARD TABLE OF X255.
    DATA : L_JOB_OUTPUT_INFO TYPE SSFCRESCL.
    DATA : LS_CONTROL_PARAM  TYPE SSFCTRLOP.
    DATA : G_HTML_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
           G_HTML_CONTROL   TYPE REF TO CL_GUI_HTML_VIEWER.
    DATA: LO_DIALOG_CONTAINER TYPE REF TO CL_GUI_DIALOGBOX_CONTAINER.
    DATA: LO_DOCKING_CONTAINER TYPE REF TO CL_GUI_DOCKING_CONTAINER.
    DATA : P_VBELN TYPE  VBELN_VL.
    FIELD-SYMBOLS <FS_X> TYPE X.
    INITIALIZATION.
    LS_CONTROL_PARAM-GETOTF = 'X'.
    LS_CONTROL_PARAM-NO_DIALOG = 'X'.
    START-OF-SELECTION.
      CALL FUNCTION '/1BCDWB/SF00000034'
    EXPORTING
       ARCHIVE_INDEX              =
      ARCHIVE_INDEX_TAB          =
      ARCHIVE_PARAMETERS         =
         CONTROL_PARAMETERS         = LS_CONTROL_PARAM
         P_VBELN                    = P_VBELN
      MAIL_APPL_OBJ              =
      MAIL_RECIPIENT             =
      MAIL_SENDER                =
      OUTPUT_OPTIONS             =
      USER_SETTINGS              = 'X'
    IMPORTING
         DOCUMENT_OUTPUT_INFO  = L_DOCUMENT_OUTPUT_INFO
           JOB_OUTPUT_INFO       = L_JOB_OUTPUT_INFO
         JOB_OUTPUT_OPTIONS    = L_JOB_ OUTPUT_OPTIONS
    EXCEPTIONS
        FORMATTING_ERROR           = 1
        INTERNAL_ERROR             = 2
        SEND_ERROR                 = 3
        USER_CANCELED              = 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.
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          FORMAT                = 'PDF'
        IMPORTING
          BIN_FILESIZE          = PDF_FSIZE
        TABLES
          OTF                   = L_JOB_OUTPUT_INFO-OTFDATA
          LINES                 = LT_PDF
        EXCEPTIONS
          ERR_MAX_LINEWIDTH     = 1
          ERR_FORMAT            = 2
          ERR_CONV_NOT_POSSIBLE = 3
          OTHERS                = 4.
    convert pdf to xstring string
      LOOP AT LT_PDF INTO LS_PDF.
        ASSIGN LS_PDF TO <FS_X> CASTING.
        CONCATENATE LV_CONTENT <FS_X> INTO LV_CONTENT IN BYTE MODE.
      ENDLOOP.
       CALL SCREEN 100.
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS '100'.
    **CREATE OBJECT LO_DOCKING_CONTAINER
    EXPORTING
       REPID     = SY-REPID
       DYNNR     = '100'"SY-DYNNR
       SIDE      = LO_DOCKING_CONTAINER->DOCK_AT_LEFT
       EXTENSION = 1200.
    CREATE OBJECT g_html_container
       EXPORTING
         container_name = 'HTML'.
    *CREATE OBJECT G_HTML_CONTROL
    EXPORTING
       PARENT = LO_DOCKING_CONTAINER.
      CREATE OBJECT G_HTML_CONTAINER
          EXPORTING
            CONTAINER_NAME = 'HTML'.
        CREATE OBJECT G_HTML_CONTROL
          EXPORTING
            PARENT = G_HTML_CONTAINER.
    Convert xstring to binary table to pass to the LOAD_DATA method
      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          BUFFER     = LV_CONTENT
        TABLES
          BINARY_TAB = LT_DATA.
    *application/
    Load the HTML
      CALL METHOD G_HTML_CONTROL->LOAD_DATA(
         EXPORTING
           TYPE         =  'application'
           SUBTYPE      =   'pdf' "
         IMPORTING
           ASSIGNED_URL         = LV_URL
         CHANGING
           DATA_TABLE           = LT_DATA
         EXCEPTIONS
           DP_INVALID_PARAMETER = 1
           DP_ERROR_GENERAL     = 2
           CNTL_ERROR           = 3
           OTHERS               = 4 ).
    CALL METHOD G_HTML_CONTROL->show_url
         EXPORTING  url        = lv_url
                   in_place    = 'X'
         EXCEPTIONS cntl_error = 1.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    MODULE user_command_0100 INPUT.
      DATA ok_code LIKE sy-ucomm.
      MOVE sy-ucomm TO ok_code.
      CASE ok_code.
        WHEN 'BACK' OR 'EXIT'.
         CALL METHOD LO_DOCKING_CONTAINER->free.
          CALL METHOD g_html_control->free.
          LEAVE TO SCREEN 0.
        WHEN OTHERS.
      ENDCASE.
    ENDMODULE.                 " USE

  • Is there a way to edit a PDF file without converting it into a word document?

    Is there a way to edit a PDF file without converting it into a word document?

    Then you posted in the wrong forum...
    At any rate, you can use the Edit Text & Images tool (under Tools - Content Editing) to make changes to the file. You'll need to be a bit more specific about what you want to change if you want more detailed instructions.

  • Convert XML file into PDF file

    <b>XML to PDF</b>i want to Convert XML file into PDF file pl. any one can suggests API's

    Hi,
    There are many ways to convert XML files to PDFs through java.
    One of the easiest way is by using iText.jar which have classes for conversion.
    The following are the required steps
    1. Create a document object for the XML file ( Using DOM or SAX parser).
    2. Parse the xml document and extract the content to write in PDF.
    3.Create a itext Document object.
    4.Get a PdfWriter instance for the PDF file.
    5.Write in the pdf the extracted text using the document object.
    Refer <a href="http://itextdocs.lowagie.com/examples/com/lowagie/examples/general/HelloWorld.java">here</a> for a simple pdf writer example.
    Refer <a href="http://java.sun.com/developer/codesamples/xml.html">here</a> for examples of XML Parsers.
    Regards,
    Uma

  • No Microsoft files listed in the settings "convert into PDF files"

    Hi, I wanted to convert different Microsoft Office files, but it doesn't work. There are no Microsoft files listed in the settings "convert into PDF files". I had the trial version of Adobe Acrobat Pro XI installed on a MAC in Windows that runs trough Parallels. Hope somebody can help. Thx

    Hi Rahul,
    many thanks for your suggestion.
    Yes, Parallels is a virtual machine on the top of MAC and I can see all files in the Windows Explorer. Also the ones I created on the MAC top with the Microsoft Office Software Word or Excel for MAC as well the ones I created earlier on a Windows PC.
    Unfortunately there is no possibility to convert files into PDF format with a click on the right mouse. And Adobe also doesn't open Word documents because it doesn't support this format.
    But nonetheless it wouldn't be a solution that I prefer to convert in adavance every single file in a PDF format. I need to create a PDF package from different formats.
    I assume this issue has to do something with MAC or Parallels, because this function of the Adobe Versions Acrobat 8 Pro and XI Pro work well on a Windows PC. I just don't understand why there are no Microsoft Office file formats listed in the Adobe settings. This settings also can't be changed. I tried to find out but couldn't find any hint for this problem thus I'm a bit at a loss... Maybe you have another idea?
    Regards
    Ly

  • Jar file to convert text into pdf

    java coding or jar file to convert text file into pdf. i dont want exe file...
    any converter to convert text into pdf.... to run in a webapplication

    This website is used to convert Word, Text , Excel file into pdf. I think it is useful to you.
    http://www.planetpdf.com
    Message was edited by:
    ggopi

  • How to enable commenting into pdf files using java?

    Hi All,
    Is there any way available to enable comments into pdf files through java. I have a Adobe Reader 9 and also I want put some comments into pdf file, but the reader is not allowed to place a comment into pdf file before enabling the Comments into pdf. After enabling the comments in pdf file then only we can place the comments and we can the pdf file with comments.
    Is there any way available to enable comments into pdf file to view acrobat reader.
    Thanks in advance.

    The end user who uses the web application has Acrobat installed in their mahcine needs it only for the purpose of enabling comments in pdf. If this task of enabling comments in pdf is done through my application there is no need for acrobat in such user's machine which was requested as a cost cuttnig measure.
    For this purpose, i need to know about how to enable comments in pdf through java api.
    I have used itext java api for other pdf related manipulation in java. But it does not have feature as per the requirement posted above. Can any body suggest relevant java api to achieve the task requested?
    Tahnks in Advance.

  • How do I convert a WHOLE PDF file into jpeg on LION?

    how do I convert a WHOLE PDF file into jpeg on LION?  I know how to open it in Preview but there is no longer an option through Print and if I export it only allows one page at a time and I need 223 pages...

    Use this Automator Action:

  • Why can't I copy and paste portions of the Word document that I just converted from a PDF file?

    Why can't I copy and paste portions of the Word document that I just had converted from a PDF file on your site?

    Hi,
    I am moving your posting to Adobe CreatePDF forum.
    Hisami

  • I am having a problem converting a scanned pdf file into Excel.

    I am having a problem converting a scanned pdf file into Excel. I do not get the columns and rows to align, just a single column of everything. Any suggestions?

    Export makes use of what is "in" a PDF.
    Good export is the "silk purse" and, ya know, you canna make a silk purse from a sow's ear (which is what any scanned image in PDF is with regards to export).
    The quality of export is dictated by the quality of the PDF. We are taking about the "inner essences" of the PDF (e.g., degree of compliance with the PDF Standard - ISO 32000-1).
    So, what goes in goes out or "GIGO".
    This has nothing to do with Acrobat or Acrobat's export process.
    A well-formed Tagged PDF (compliant to ISO 32000-1 & ISO 14289-1, PDF/UA-1) provides a PDF that proactively
    supports content export by Acrobat.
    To get the good stuff from export you start with a well-formed Tagged PDF.
    Goodstuff In — Goodstuff Out
    or
    Garbage In — Garbage Out
    "GIGO"
    Be well...
    Message was edited by: CtDave

  • How to convert bytes[] into multipage File object

    Hi,
    How to convert bytes[] into multipage File object??
    I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream.
    Thanks for you help in advance..

    Only text format allows you to concatenate two files together to get a longer files.
    Most formats have a header and a footer and so you cannot simply add one to the other.
    You need to use a PDF API which will allow you to build the new document (if one exists)

  • I have an iPad air and have downloaded the microsoft app excel.  I have an email with an excel attachment.  When I "tap to download" the attachment, it auto converts to a PDF file.  I want it to open in excel.  Please help.

    I have an iPad air and have downloaded the microsoft app excel.  I have an email with an excel attacment.  When I "tap to download" the attachment, it automatically converts to a PDF file and opens as a "view only" document.  I want it to open with the excel app so I can see and update the spreadsheet.  Please help.  Thanks!

    If Excel works as do other apps, you should be able to tap and hold on the attachment and then select "Open in Excel" in the window that will open. Note that you need to be subscribed to and signed into Office 365 to be able to edit documents in Microsoft's apps.
    Regards.

Maybe you are looking for