Code: Alles auswählen.
FORM process_2.
DATA: lv_name TYPE string,
lv_size TYPE i,
lv_data TYPE xstring,
lv_retcode TYPE i.
DATA: lt_file TYPE srmgs_bin_content.
lv_name = gv_document.
* CALL METHOD cl_gui_frontend_services=>gui_upload
* EXPORTING
* filename = lv_name
* filetype = 'BIN'
* IMPORTING
* filelength = lv_size
* CHANGING
* data_tab = lt_file
* EXCEPTIONS
* OTHERS = 1.
* IF sy-subrc NE 0.
* MESSAGE 'Read file error!' TYPE 'E' DISPLAY LIKE 'S'.
* ENDIF.
*
* CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
* EXPORTING
* input_length = gv_size
* IMPORTING
* buffer = lv_data
* TABLES
* binary_tab = lt_file
* EXCEPTIONS
* failed = 1
* OTHERS = 2.
* IF sy-subrc NE 0.
* MESSAGE 'Binary conversion error!' TYPE 'E' DISPLAY LIKE 'S'.
* ENDIF.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_name
IMPORTING
buffer = lv_data.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_data
append_to_table = 'X' "Do not clear/refresh table
TABLES
binary_tab = lt_file.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = gv_size
IMPORTING
buffer = lv_data
TABLES
binary_tab = lt_file
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE 'Binary conversion error!' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.
PERFORM print_2 USING gv_printer lv_data CHANGING lv_retcode.
IF lv_retcode EQ 0.
IF gv_printed IS INITIAL.
gv_printed = abap_true.
ENDIF.
ELSE.
IF gv_printed IS INITIAL.
gv_printed = abap_false.
ENDIF.
* RAISE print_error.
ENDIF.
ENDFORM. " PROCESS_2
Code: Alles auswählen.
FORM print_2 USING iv_prndst TYPE rspopname
iv_content TYPE xstring
CHANGING ev_retcode TYPE i.
DATA: lv_handle TYPE sy-tabix,
lv_spoolid TYPE rspoid,
lv_partname TYPE adspart,
lv_globaldir TYPE text1024,
lv_dstfile TYPE text1024,
lv_filesize TYPE i,
lv_pages TYPE i,
lv_content TYPE xstring,
lv_document TYPE c LENGTH 128.
CLEAR: ev_retcode.
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = iv_prndst
doctype = 'ADSP'
copies = gv_copies
immediate_print = 'X'
auto_delete = ' '
IMPORTING
handle = lv_handle
spoolid = lv_spoolid
partname = lv_partname
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
MOVE gv_document to lv_document.
CALL FUNCTION 'ADS_GET_PATH'
IMPORTING
ads_path = lv_globaldir.
**
CONCATENATE lv_globaldir '\' lv_partname '.pdf' INTO lv_dstfile.
** MOVE gv_document to lv_dstfile.
* OPEN DATASET lv_dstfile FOR OUTPUT IN BINARY MODE.
* IF sy-subrc NE 0.
* ev_retcode = 4.
* RETURN.
* ENDIF.
*
* READ DATASET lv_dstfile INTO lv_content.
* TRANSFER iv_content TO lv_dstfile.
* IF sy-subrc NE 0.
* RETURN.
* ENDIF.
*
* CLOSE DATASET lv_dstfile.
* IF sy-subrc NE 0.
* RETURN.
* ENDIF.
* CALL FUNCTION 'Z_EWM_PDF_GET_PAGES'
* EXPORTING
* iv_content = iv_content
* IMPORTING
* ev_pages = lv_pages.
**
** lv_pages = p_ncopi.
* lv_filesize = xstrlen( iv_content ).
*DATA FILENAME TYPE C.
*DATA BUFFER TYPE XSTRING.
*DATA APPEND TYPE C.
*DATA USEGLOBALDIR TYPE C.
*DATA CLIENT TYPE MANDT.
CALL FUNCTION 'ADS_WRITE_TO_FILE'
EXPORTING
filename = lv_document "Dateipfad\Datei
buffer = iv_content
* APPEND = ' '
* USEGLOBALDIR = 'X'
CLIENT = sy-mandt
EXCEPTIONS
CANNOT_OPEN_FILE = 1
OPEN_DATASET_NO_AUTHORITY = 2
OPEN_DATASET_INTERNAL_ERROR = 3
OPEN_DATASET_TOO_MANY_FILES = 4
DATASET_CANT_CLOSE = 5
CLOSE_DATASET_INTERNAL_ERROR = 6
CANNOT_CLOSE_FILE = 7
CANNOT_TRANSFER_DATA = 8
TRANSFER_INTERNAL_ERROR = 9
DATASET_WRITE_ERROR = 10
OTHERS = 11
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = lv_handle
partname = lv_partname
size = lv_filesize
pages = lv_pages
no_pdf = ' '
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = lv_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
ENDFORM.
Code: Alles auswählen.
OPEN DATASET lv_name in BINARY MODE FOR INPUT.
READ DATASET lv_name INTO lv_data.
CLOSE DATASET lv_name.
leider kann ich diese Methode nicht verwenden, da es unter umständen sein kann, dass auch über ein ITS Service oder über eine BSP_Applikation der Druck angestoßen wird.a-dead-trousers hat geschrieben: Schau dir mal bitte das Coding etwas genauer an:
Du wandelst lv_name (vermutlich der Dateiname) in einen XSTRING um anstatt den Dateinhalt.
Grob gesagt fehlt dir das Auslesen der Datei (vgl. mit cl_gui_frontend_services=>gui_upload)
in der Variable lv_name steht der Name mit kompletten Pfad (\\<Server>\<Verzeichnis>\<Dokument>.PDF)a-dead-trousers hat geschrieben: Schau dir mal bitte das Coding etwas genauer an:
Du wandelst lv_name (vermutlich der Dateiname) in einen XSTRING um anstatt den Dateinhalt.
So, das ist jetzt ein etwas anderes Thema: Wie kann man in SAP eine Datei auslesen?harry1991 hat geschrieben:in der Variable lv_name steht der Name mit kompletten Pfad (\\<Server>\<Verzeichnis>\<Dokument>.PDF)
Leider läuft der OPEN DATASET hire auf den RC 8 ( Datei konnte nicht geöffnet werden )
Ob der Inhalt PDF oder PCL ist, hängt vom verwendeten Druckertreiber ab. Bei HPxx ist der Inhalt PCL5 und die Dateiendung ist e.g. SPOOL0000001701_00001.pclADS*FP_TEST_00*/sap/bc/fp/form/layout/FP_TEST_00.XDP?fp-language=DE&fp-cacheinfo=2007-02-09T14%3a28%3a37Z%2451e721c5-23fc-4f4e-a124-732f1d98372a%240%240%24v0%2e9*de_DE*D**00*1*-*D*
SPOOL0000001701_00001.xfd%PDF-1.6%âãÏÓ.....
Fazit: um ein PDF Drucken zu können, muss es im Spool schon als PCL File vorliegen.<data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/ ... INES><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 1 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 2 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 3 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 4 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 5 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 6 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 7 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 8 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 9 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 10 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 11 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 12 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 13 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 14 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 15 on page 1</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 1 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 2 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 3 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 4 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 5 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 6 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 7 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 8 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 9 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 10 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 11 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 12 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 13 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 14 on page 2</TDLINE></DATA><DATA xfa:dataNode="dataGroup"><TDFORMAT></TDFORMAT><TDLINE>Line 15 on page 2</TDLINE></DATA></TEXTLINES></data>
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZTEST_SEND_PDF_TO_SPOOL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_SEND_PDF_TO_SPOOL.
data:
HANDLE type SY-TABIX,
SPOOLID type TSP01-RQIDENT,
ADSDOCTYPE TYPE ADSDOCTYPE value 'ADSP',
PARTNAME type ADSPART,
PARTNAME2 type ADSPART.
data:
size type i value 1,
pages type i value 2,
fname type string value 'E:\_test\W7.pdf'.
data xtab type table of solix.
data xbuffer type xstring.
data sfname(20) value 'C:\spool\000.pdf'.
*ADSP Spool Auftrag für Druckausgabe
*ADSM Spool Auftrag für E-Mailausgabe
*ADSF Spool Auftrag für Faxausgabe
*ADSA Spool Auftrag Application
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
DEST = 'LP01'
* LDEST =
* NAME =
* SUFFIX1 =
* SUFFIX2 =
* COPIES =
* PRIO =
* IMMEDIATE_PRINT =
* AUTO_DELETE =
* TITLELINE =
* RECEIVER =
* DIVISION =
* AUTHORITY =
* POSNAME =
* ACTTIME =
* LIFETIME = '8'
* APPEND =
* COVERPAGE =
DOCTYPE = ADSDOCTYPE
* USESPOOLID =
* SPONUMIV = ' '
IMPORTING
HANDLE = handle
SPOOLID = spoolid
PARTNAME = PARTNAME
EXCEPTIONS
DEVICE_MISSING = 1
NO_SUCH_DEVICE = 2
OPERATION_FAILED = 3
WRONG_DOCTYPE = 4
WRONG_DEVICETYPE = 5
OTHERS = 6.
break sapuser.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = fname
FILETYPE = 'BIN'
* HAS_FIELD_SEPARATOR = SPACE
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = SPACE
* CODEPAGE = SPACE
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH = size
* HEADER =
CHANGING
DATA_TAB = xtab[]
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
others = 19.
IF SY-SUBRC <> 0.
ENDIF.
*ADS_WRITE_TO_FILE
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = size
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
BUFFER = Xbuffer
TABLES
BINARY_TAB = xtab[]
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
sfname = PARTNAME.
CALL FUNCTION 'ADS_WRITE_TO_FILE'
EXPORTING
FILENAME = sfname
BUFFER = xbuffer
* APPEND = ' '
* USEGLOBALDIR = 'X'
EXCEPTIONS
CANNOT_OPEN_FILE = 1
OPEN_DATASET_NO_AUTHORITY = 2
OPEN_DATASET_INTERNAL_ERROR = 3
OPEN_DATASET_TOO_MANY_FILES = 4
DATASET_CANT_CLOSE = 5
CLOSE_DATASET_INTERNAL_ERROR = 6
CANNOT_CLOSE_FILE = 7
CANNOT_TRANSFER_DATA = 8
TRANSFER_INTERNAL_ERROR = 9
DATASET_WRITE_ERROR = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
ENDIF.
*ADS_SR_CONFIRM
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
HANDLE = handle
PARTNAME = PARTNAME
SIZE = size
PAGES = pages
* NO_PDF = ' '
IMPORTING
NEW_PARTNAME = PARTNAME2
EXCEPTIONS
HANDLE_NOT_VALID = 1
OPERATION_FAILED = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
break sapuser.
*ADS_SR_CLOSE
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
HANDLE = handle
* FINAL =
EXCEPTIONS
HANDLE_NOT_VALID = 1
OPERATION_FAILED = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
break sapuser.
Oder der Drucker versteht es PDF zu drucken. PS funktioniert auch wenn der Drucker es interpretieren kann, aber man muss die PDF-Datei vorher mit einem Programm in PS konvertieren (bei uns PDF2PS aus der xPDF-Library)Tron hat geschrieben:Fazit: um ein PDF Drucken zu können, muss es im Spool schon als PCL File vorliegen.
Zusammen mit den oben genannten 2 Dateien.
Code: Alles auswählen.
REPORT z_print_ext_pdf.
CONSTANTS: lc_printer TYPE rspopname VALUE 'PDFP'. "PDF-Fähiger Drucker
DATA:
lv_partname TYPE adspart,
lv_globaldir TYPE text1024,
lv_dstfile TYPE c LENGTH 128,
lv_content_dst TYPE xstring,
lv_srcfile TYPE c LENGTH 128
VALUE '\\127.0.0.1\TEST.pdf',
lv_content_src TYPE xstring.
DATA: lv_handle TYPE sytabix,
lv_spoolid TYPE rspoid,
lv_pages TYPE i,
lv_size TYPE i.
* Spool Job eröffnen
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = lc_printer
doctype = 'ADSP'
copies = '1'
immediate_print = ' '
auto_delete = ' '
IMPORTING
handle = lv_handle
spoolid = lv_spoolid
partname = lv_partname
EXCEPTIONS
OTHERS = 1.
* Globalen Pfad im SAP lesen, um dort die PDF zu erzeugen und abzulegen
CALL FUNCTION 'ADS_GET_PATH'
IMPORTING
ads_path = lv_globaldir.
* Zusammenführung von Globalen Pfad und PDF-Spoolnamen. "\" unter Windows
CONCATENATE lv_globaldir '\' lv_partname '.pdf' INTO lv_dstfile.
*----------------------------Begin-----------------------------------*
* Lesen des Inhalts der Quell-Datei (PDF vom Server)
* Lesen des Binären Inhalts der Quelldatei
* um diesen der Zieldatei hinzuzufügen ( Datei im Globalen Verzeichnis)
OPEN DATASET lv_srcfile FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
READ DATASET lv_srcfile INTO lv_content_src.
ENDIF.
OPEN DATASET lv_dstfile FOR OUTPUT IN BINARY MODE.
* Füge Inhalt der Quelldatei der Zieldatei hinzu
TRANSFER lv_content_src TO lv_dstfile.
* Schließen der Datenverarbeitung der Dateien
CLOSE DATASET lv_dstfile.
CLOSE DATASET lv_srcfile.
* Lesen des Inhalts der Quell-Datei (PDF vom Server)
*----------------------------Ende------------------------------------*
*----------------------------Begin-----------------------------------*
* PDF-Daten an den Spool übergeben
* Inhalt der PDF Datei binär in die Spool Datei schreiben
CALL FUNCTION 'ADS_WRITE_TO_FILE'
EXPORTING
filename = lv_partname
buffer = lv_content_src
* APPEND = ' '
* USEGLOBALDIR = 'X'
EXCEPTIONS
cannot_open_file = 1
open_dataset_no_authority = 2
open_dataset_internal_error = 3
open_dataset_too_many_files = 4
dataset_cant_close = 5
close_dataset_internal_error = 6
cannot_close_file = 7
cannot_transfer_data = 8
transfer_internal_error = 9
dataset_write_error = 10
OTHERS = 11.
* Seitenanzahl ermitteln
CALL FUNCTION 'Z_EWM_PDF_GET_PAGES2'
EXPORTING
iv_content = lv_content_src
IMPORTING
ev_pages = lv_pages.
* Bestätigen, dass der Druckjob nun beendet ist.
lv_size = xstrlen( lv_content_src ).
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = lv_handle
partname = lv_partname
size = lv_size
pages = lv_pages
no_pdf = ' '
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ENDIF.
* Spool Job schließen
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = lv_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ENDIF.
* PDF-Daten an den Spool übergeben
*----------------------------Ende------------------------------------*
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Form GET_PAGE_COUNT_PDF
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GF_CONTENT_SRC text
* -->P_GF_PAGES text
*----------------------------------------------------------------------*
FORM get_page_count_pdf USING lf_content_pdf TYPE xstring
gf_pages TYPE i.
DATA: lf_pdf TYPE string.
DATA: lf_lines TYPE i,
lf_pages TYPE numc5,
lf_temp TYPE string.
DATA: lt_result TYPE match_result_tab.
FIELD-SYMBOLS: <fs_result> LIKE LINE OF lt_result,
<fs_subm> LIKE LINE OF <fs_result>-submatches.
lf_pages = 0.
CALL FUNCTION 'CRM_IC_XML_XSTRING2STRING'
EXPORTING
inxstring = lf_content_pdf
IMPORTING
outstring = lf_pdf.
FIND REGEX `/Count (.{1,5})/` IN lf_pdf IGNORING CASE RESULTS
lt_result.
IF sy-subrc NE 0.
FIND ALL OCCURRENCES OF REGEX `/Count (.{1,4})/` IN lf_pdf
IGNORING CASE RESULTS lt_result.
ENDIF.
lf_lines = lines( lt_result ).
IF lf_lines IS NOT INITIAL.
READ TABLE lt_result ASSIGNING <fs_result> INDEX lf_lines.
IF sy-subrc EQ 0.
READ TABLE <fs_result>-submatches ASSIGNING <fs_subm> INDEX 1.
IF sy-subrc EQ 0.
lf_temp = lf_pdf+<fs_subm>-offset(<fs_subm>-length).
CONDENSE lf_temp NO-GAPS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = lf_temp
IMPORTING
output = lf_pages.
gf_pages = lf_pages.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " GET_PAGE_COUNT_PDF