* Generate Cover Sheet PDF lcCoverPDFFile = SUBSTR(SYS(2015),3,8)+'.pdf' SET PROCEDURE TO WWAPI ADDITIVE SET PROCEDURE TO WWPDF ADDITIVE oPDF=CREATE("wwPDF","WINNT") oPDF.nTimeout = 20 oPDF.SetLandscapemode(.F.) llResult = oPDF.PrintReport("resp_Cover.frx", 'D:\Data\FMS_Pdfs\' + lcCoverPDFFile) IF NOT llResult RELEASE oPDF html_out = "Location: " + lcPageToReturnTo + "?Message=" + "Cover_sheet_PDF_File_could_not_be_generated" + CHR(10)+CHR(10) RETURN ENDIF RELEASE oPDF RELEASE PROCEDURE WWAPI RELEASE PROCEDURE WWPDF * Generate the enclosure SELECT FinalOut lcEnclPDFFile = SUBSTR(SYS(2015),3,8)+'.pdf' SET PROCEDURE TO WWAPI ADDITIVE SET PROCEDURE TO WWPDF ADDITIVE oPDF=CREATE("wwPDF","WINNT") oPDF.nTimeout = 10 oPDF.SetLandscapemode(.T.) llResult = oPDF.PrintReport("resp_Encl.frx", 'D:\Data\FMS_Pdfs\' + lcEnclPDFFile) IF NOT llResult RELEASE oPDF html_out = "Location: " + lcPageToReturnTo + "?Message=" + "Enclosure_PDF_File_could_not_be_generated" + CHR(10)+CHR(10) RETURN ENDIF * I have to merge the two reports * Create an AVDoc Object for the Cover PDF oCoverAVDoc = CREATEOBJECT("AcroExch.AVDoc") IF !(TYPE("oCoverAVDoc")="O" AND !ISNULL(oCoverAVDoc)) html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_create_Cover_AVDoc_object' + CHR(10)+CHR(10) RETURN ENDIF * Open the pdf of the Cover Sheet x = .F. x = oCoverAVDoc.OPEN('D:\Data\FMS_Pdfs\' + lcCoverPDFFile, "Cover") IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_open_Cover_PDF' + CHR(10)+CHR(10) RETURN ENDIF * Create an PDDoc Object for the Cover PDF oCoverPDDoc = oCoverAVDoc.GetPDDoc() IF !(TYPE("oCoverPDDoc")="O" AND !ISNULL(oCoverPDDoc)) html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_create_PDDoc_ref_for_cover' + CHR(10)+CHR(10) RETURN ENDIF * Get the page count of the Cover PDF lnCoverPgCnt = .T. lnCoverPgCnt = oCoverPDDoc.GetNumPages() IF !TYPE("lnCoverPgCnt")="N" html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_get_cover_page_count' + CHR(10)+CHR(10) RETURN ENDIF * If the page count is more than one * there is a blank page on the end and * we need to delete it. IF lnCoverPgCnt > 1 x = .F. x = oCoverPDDoc.DeletePages(lnCoverPgCnt-1, lnCoverPgCnt-1) IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_delete_cover_blank_page' + CHR(10)+CHR(10) RETURN ENDIF ENDIF * Create an AVDoc Object for the Enclosure PDF oEnclAVDoc = CREATEOBJECT("AcroExch.AVDoc") IF !(TYPE("oEnclAVDoc")="O" AND !ISNULL(oEnclAVDoc)) html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_create_enclosure_AVDoc_object' + CHR(10)+CHR(10) RETURN ENDIF * Open the Enclosure PDF x = .F. x = oEnclAVDoc.OPEN('D:\Data\FMS_Pdfs\' + lcEnclPDFFile, "Encl") IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_open_cover_PDF' + CHR(10)+CHR(10) RETURN ENDIF * Create a PDDoc Object for the Enclosure PDF oEnclPDDoc = oEnclAVDoc.GetPDDoc() IF !(TYPE("oEnclPDDoc")="O" AND !ISNULL(oEnclPDDoc)) html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_create_PDDoc_ref_for_cover' + CHR(10)+CHR(10) RETURN ENDIF * Get the page count of the Enclosure PDF lnEnclPgCnt = .T. lnEnclPgCnt = oEnclPDDoc.GetNumPages() IF !TYPE("lnEnclPgCnt")="N" html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_get_enclosure_page_count' + CHR(10)+CHR(10) RETURN ENDIF * Insert the enclosure report * into the cover letter report x = .F. x = oCoverPDDoc.InsertPages( 0, oEnclPDDoc, 0, lnEnclPgCnt, .F.) IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_insert_enclosure' + CHR(10)+CHR(10) RETURN ENDIF * 0x20 perform garbage collection on * unreferenced objects * 0x4 writes the file linearized * 0x1 write entire file * Save the combined final rewsponse lcFinalPDFFile = SUBSTR(SYS(2015),3,8)+'.pdf' x = .F. x = oCoverPDDoc.SAVE(0x20+0x4+0x1, 'D:\Data\FMS_Pdfs\' + lcFinalPDFFile) IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_save_Final_PDF' + CHR(10)+CHR(10) RETURN ENDIF * Close the Cover PDF x = .F. x = oCoverAVDoc.CLOSE(.T.) IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_close_Cover_AVDoc' + CHR(10)+CHR(10) RETURN ENDIF * Close the Enclosure PDF x = .F. x = oEnclAVDoc.CLOSE(.T.) IF !x html_out = "Location: " + lcPageToReturnTo + "?Message=" + 'Could_not_close_Enclosure_AVDoc' + CHR(10)+CHR(10) RETURN ENDIF * Return the link to the Final Response html_out = "Location: " + lcPageToReturnTo + "?PDF=" + lcFinalPDFFile + CHR(10)+CHR(10) RETURN