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
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
donkosak
Code: Alles auswählen.
pdftk my.pdf dump_data | grep NumberOfPages