//*********************************************************************
// Object : n_cst_pdf
// Function : of_merge_two_pdf_files
//
// Ancestor : Extended
// Access : Public
// Arguments : value string as_first_pdf_file
// value string as_second_pdf_file
// value string as_result_filename
//
// Returns : String Error msg; Empty string = no error
// Throws : None
//
// Description : Merge the PDF files as specified, with the resulting
// merged file to be named <as_result_filename>.
//
//********************************************************************
// Revision History
//
// Developer Date Version Description
// --------- ----------- --------- -------------------------------
// O Knight 02-SEP-2022 4.0.5.240 #5440515: Initial install.
//
//********************************************************************
// COPYRIGHT © 2022 CSG SYSTEMS INTERNATIONAL, INC. AND/OR ITS
// AFFILIATES (“CSG”). ALL RIGHTS RESERVED.
//********************************************************************
boolean lb_exists
long ll_rc, ll_pos
string ls_err, ls_file [3], ls_path [3], ls_cmd, ls_msg
// Validate the input files
// ~~~~~~~~~~~~~~~~~~~~~~~~
ls_err = this.FUNCTION of_wait_for_file_to_be_created (as_first_pdf_file)
IF (ls_err <> "") THEN
ls_err = "The first PDF file to be merged does not exist, of the code does not " + &
"have access to the file. ~r~n Filename: " + as_first_pdf_file
GOTO Exit_Function
END IF
ls_err = this.FUNCTION of_wait_for_file_to_be_created (as_second_pdf_file)
IF (ls_err <> "") THEN
ls_err = "The second PDF file to be merged does not exist, of the code does not " + &
"have access to the file. ~r~n Filename: " + as_second_pdf_file
GOTO Exit_Function
END IF
// Ensure the output/result file does NOT exist
lb_exists = FileExists (as_result_filename)
IF (lb_exists) THEN
lb_exists = FileDelete (as_result_filename)
END IF
// Separate the path and file names (Used in tracking)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Split the first filename
ll_pos = LASTPOS (as_first_pdf_file, "\")
IF (ll_pos > 0) THEN
ls_file [1] = MID (as_first_pdf_file, (ll_pos + 1), 9999)
ls_path [1] = MID (as_first_pdf_file, 1, ll_pos) // Include the final "\"
ELSE
ls_err = "The first PDF file to be merged with the invoice has no PATH.~r~n Filename: " + as_first_pdf_file
GOTO Exit_Function
END IF
// Split the second filename
ll_pos = LASTPOS (as_second_pdf_file, "\")
IF (ll_pos > 0) THEN
ls_file [2] = MID (as_second_pdf_file, (ll_pos + 1), 9999)
ls_path [2] = MID (as_second_pdf_file, 1, ll_pos) // Include the final "\"
ELSE
ls_err = "The second PDF file to be merged with the invoice has no PATH.~r~n Filename: " + as_second_pdf_file
GOTO Exit_Function
END IF
// Merge the two PDF file using: PDFtk_Pro
// https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
// sid.steward@pdflabs.com
// Example: pdftk in1.pdf in2.pdf cat output out1.pdf
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ls_cmd = "pdftk " + &
'"' + as_first_pdf_file + '" ' + &
'"' + as_second_pdf_file + '" cat output ' + &
'"' + as_result_filename + '" '
// ll_rc = RUN (ls_cmd)
lb_exists = inv_runwait.runandwait (ls_cmd, inv_runwait.sw_shownormal)
IF (lb_exists) THEN
ls_msg = "We merged the PDF Notice with the invoice."
// ls_err = "SUCCESS! We merged the two PDF files: ~r~n" + &
// "~r~n Error: " + inv_runwait.LastErrorText + &
// "~r~n File 1: " + as_first_pdf_file + &
// "~r~n File 2: " + as_second_pdf_file + &
// "~r~n Output: " + as_result_filename + &
// "~r~n" + &
// "~r~n LS_CMD = ~r~n " + ls_cmd
//
// MessageBox ("PDF Files Merged", ls_err)
ELSE
ls_msg = "Unable to merge the PDF Notice with the invoice."
// ls_err = "Unable to merge the two PDF files: ~r~n" + &
// "~r~n Error: " + inv_runwait.LastErrorText + &
// "~r~n File 1: " + as_first_pdf_file + &
// "~r~n File 2: " + as_second_pdf_file + &
// "~r~n Output: " + as_result_filename + &
// "~r~n" + &
// "~r~n LS_CMD = ~r~n " + ls_cmd
//
// MessageBox ("PDF Merge Error", ls_err, Exclamation!)
END IF
gnv_app.of_SetMicroHelp (ls_msg)
Exit_Function:
RETURN ls_err
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//*********************************************************************
// Object : n_cst_pdf
// Function : of_wait_for_file_to_be_created
//
// Ancestor : Extended
// Access : Public
// Arguments : value string as_filename
//
// Returns : String Error msg; Empty string = no error
// Throws : None
//
// Description : Wait until the specified file actually exists.
//
//********************************************************************
// Revision History
//
// Developer Date Version Description
// --------- ----------- --------- -------------------------------
// O Knight 28-AUG-2022 4.0.5.241 #5440515: Initial install.
//
//********************************************************************
// COPYRIGHT © 2022 CSG SYSTEMS INTERNATIONAL, INC. AND/OR ITS
// AFFILIATES (“CSG”). ALL RIGHTS RESERVED.
//********************************************************************
boolean lb_exists
long ll_seconds
string ls_err
time lt_start, lt_now
lt_start = NOW ()
lb_exists = FALSE
gnv_app.of_SetMicrohelp ("Waiting for the temp invoice file to be created....")
DO WHILE (NOT lb_exists)
lb_exists = FileExists (as_filename)
IF (NOT lb_exists) THEN
lt_now = Now ()
ll_seconds = SecondsAfter (lt_start, lt_now)
IF (ll_seconds > 60) THEN
ls_err = "The specified file did not exist after 60 seconds. ~r~n" + &
"~r~n Temp File: " + as_filename
GOTO Exit_Function
END IF
END IF
LOOP
gnv_app.of_SetMicrohelp ("The file has been created: " + as_filename)
Exit_Function:
IF (ls_err <> "") THEN
MessageBox ("File Creation Error", ls_err, Exclamation!)
END IF
RETURN ls_err
Andreas.