Create Page Segment from RPG Field


*------------------------------------------------------------------------ * @Author: Kato Integrations * @Description: * This is a test program demonstrating how to call IPI APIs to * create a page segment (*PAGSEG) from a provided image in a field, * such as one loaded from a DB2 file. You can specify the dimensions * of the page segment being created in inches. *------------------------------------------------------------------------ H DFTACTGRP(*NO) ACTGRP(*CALLER) BNDDIR('IPIBND') OPTION(*NODEBUGIO) /COPY QRPGLECPY,IPICB // This is included for demo output purposes only and is not part of IPI. D WriteToJobLog PR 10I 0 Extproc('Qp0zLprintf') D pString * Value Options(*String) D NewLine C x'15' // This data structure will contain any error information returned by // the IPI APIs. D IPIErrorDS DS LikeDS(IPI_ErrorDS_t) Inz(*LikeDS) // This data structure is used to configure how image data is loaded as // well as whether or not the image is coming from a STMF or a field. D LoadImageDS DS LikeDS(IPI_LoadImageDS_t) D Inz(*LikeDS) // This data structure is used to pass around information about a loaded // image to other IPI APIs for further processing or output. D ImageDS DS LikeDS(IPI_ImageDS_t) D Inz(*LikeDS) // This data structure configures where the page segment will be // created and allows you to specify the target dimensions of the // page segment in inches. D TargetPagSegDS DS LikeDS(IPI_PageSegmentDS_t) D Inz(*LikeDS) D Image S 8192A Varying /FREE // Always call IPI_Initialize() before calling any other IPI APIs. // IPI_Initialize() will return *On if it was successful or *Off if not reset IPIErrorDS; if not IPI_Initialize( IPIErrorDS ); // handle error here WriteToJobLog( 'IPI_Initialize() Error' + NewLine ); WriteToJobLog( 'Error Message ID: ' + IPIErrorDS.MessageId + NewLine ); WriteToJobLog( 'Error Message: ' + IPIErrorDS.Message + NewLine ); exsr cleanup; return; endif; // Always reset IPI data structures before using them. reset ImageDS; reset LoadImageDS; // Is the input data base64 encoded? LoadImageDS.Base64Encoded = IPI_NO; // Is the image data in a CCSID other than the job CCSID? If so, // specify it in the below subfield. Note that there are other // CCSID constants in QRPGLECPY,IPICB but ones not defined in the // copybook may also be used as well. LoadImageDS.InputCcsid = IPI_CCSID_JOB; reset IPIErrorDS; // Image would be the image data as loaded from your source - such as // from a DB2 file, a webservice, from the IFS, etc. Image = ''; if not IPI_LoadImage( ImageDS : LoadImageDS : Image : IPIErrorDS ); // handle error here WriteToJobLog( 'IPI_LoadImage() Error' + NewLine ); WriteToJobLog( 'Error Message ID: ' + IPIErrorDS.MessageId + NewLine ); WriteToJobLog( 'Error Message: ' + IPIErrorDS.Message + NewLine ); exsr cleanup; return; endif; // Specify location of created page segment reset TargetPagSegDS; TargetPagSegDS.ObjectName = 'IPITSTPS'; TargetPagSegDS.LibraryName = 'IPI'; // Width in inches TargetPagSegDS.Width = 2.00; // Height in inches TargetPagSegDS.Height = 1.00; reset IPIErrorDS; if not IPI_ImageToPageSegment( ImageDS : TargetPagSegDS : IPIErrorDS ); // handle error here WriteToJobLog( 'IPI_ImageToPageSegment() Error' + NewLine ); WriteToJobLog( 'Error Message ID: ' + IPIErrorDS.MessageId + NewLine ); WriteToJobLog( 'Error Message: ' + IPIErrorDS.Message + NewLine ); exsr cleanup; return; endif; exsr cleanup; *INLR = *ON; return; begsr cleanup; // You need to call IPI_UnloadImage() on every image loaded using // IPI_LoadImage() to ensure all memory is freed correctly. IPI_UnloadImage( ImageDS ); // It is important to call IPI_Terminate() at the end of your program // This includes when an error occurs. IPI_Terminate(); endsr; /END-FREE