Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------------------------------------
- File : PDF Wrapper for PDFSuper.p
- Purpose :
- Syntax :
- Description :
- Author(s) : connorrs
- Created : Fri Aug 19 10:27:02 EDT 2016
- Notes :
- ----------------------------------------------------------------------*/
- USING PROGRESS.Lang.*.
- block-level ON ERROR UNDO, throw.
- CLASS Business.PDF:
- {Includes/PDFSuper.i}
- /* PDF properties */
- DEF public property pdfStream AS CHAR public GET. private SET.
- DEF public property pdfDirectory AS CHAR public GET. private SET.
- DEF public property pdfFilename AS CHAR public GET. private SET.
- DEF public property pdfTitle AS CHAR public GET. private SET.
- DEF public property pdfOrientation AS CHAR public GET. private SET.
- DEF public property pdfMaxPages AS INT public GET. private SET.
- /* Logo properties */
- DEF public property logoUsed AS LOG public GET. private SET.
- DEF public property logoPath AS CHAR public GET. private SET.
- /* Current page info */
- DEF public property pageNumber AS INT public GET. private SET.
- DEF public property pageCount AS INT public GET. private SET.
- DEF public property pageHeight AS INT public GET. private SET.
- DEF public property pageWidth AS INT public GET. private SET.
- DEF public property pageMax AS INT public GET. private SET.
- /* Page positions */
- DEF public property pageX AS INT public GET. private SET.
- DEF public property pageY AS INT public GET. private SET.
- /* Report properties */
- DEF public property headerLine AS CHAR public GET. private SET.
- DEF public property headerFont AS CHAR public GET. private SET.
- DEF public property headerFontSize AS INT public GET. private SET.
- DEF public property reportOrganization AS CHAR public GET. private SET.
- DEF public property reportPrivacyText AS CHAR public GET. private SET.
- /* Font properties */
- DEF public property fontType AS CHAR public GET. private SET.
- DEF public property fontSize AS INT public GET. private SET.
- DEF public property fontColor AS INT public GET. private SET.
- CONSTRUCTOR PDF(pdfDirectory AS CHAR, pdfFileName AS CHAR, pdfTitle AS CHAR, pdfOrientation AS CHAR):
- ASSIGN
- THIS-OBJECT:pdfStream = "spdf"
- THIS-OBJECT:pdfDirectory = pdfDirectory
- THIS-OBJECT:pdfFileName = pdfFileName
- THIS-OBJECT:pdfTitle = pdfTitle
- THIS-OBJECT:pdfOrientation = pdfOrientation
- .
- /* Set page height and width. TODO: DOUBLE CHECK THESE NUMBERS */
- IF pdfOrientation EQ "Portrait" THEN ASSIGN
- THIS-OBJECT:pageHeight = 792
- THIS-OBJECT:pageWidth = 612
- .
- ELSE IF pdfOrientation EQ "Landscape" THEN ASSIGN
- THIS-OBJECT:pageHeight = 612
- THIS-OBJECT:pageWidth = 792
- .
- ELSE ASSIGN
- THIS-OBJECT:pdfOrientation = "Portrait"
- THIS-OBJECT:pageHeight = 792
- THIS-OBJECT:pageWidth = 612
- .
- /* Get the report defaults */
- RUN Business/GetReportDefaults.p(OUTPUT logoUsed, OUTPUT logoPath, OUTPUT pageMax, OUTPUT pdfTitle, OUTPUT reportOrganization, OUTPUT reportPrivacyText).
- END CONSTRUCTOR.
- /**
- * Initializes the PDF and sets various internal PDF properties
- */
- METHOD public void StartPDF():
- RUN PDFStart(
- THIS-OBJECT:pdfDirectory,
- THIS-OBJECT:pdfFilename,
- THIS-OBJECT:pdfOrientation,
- "letter",
- "",
- THIS-OBJECT:pdfTitle,
- "",
- "helvetica",
- 9.0,
- "",
- THIS-OBJECT:headerLine,
- "helvetica-bold",
- "9.0",
- "",
- "",
- THIS-OBJECT:pdfTitle,
- ""
- ).
- /* Set page properties */
- ASSIGN
- THIS-OBJECT:pageNumber = 1
- THIS-OBJECT:pageCount = 1
- .
- END METHOD.
- /**
- * Creates an entry in the chr(30) delimited list of header column values and position
- *
- * @param char columnText: The label of the column to be added
- * @param char columnPos: The position of the column.
- */
- METHOD public void AddHeaderColumn(columnText AS CHAR, columnPos AS INT):
- /* If the header line is not blank, add another delimiter. Without this, the list will go out of range */
- IF THIS-OBJECT:headerLine NE "" THEN THIS-OBJECT:headerLine = THIS-OBJECT:headerLine + CHR(30).
- THIS-OBJECT:headerLine = THIS-OBJECT:headerLine + columnText + CHR(30) + STRING(columnPos).
- END METHOD.
- METHOD public void SetHeader(headerLine AS CHAR):
- THIS-OBJECT:headerLine = headerLine.
- /* PDFSUPER CALL - sets sv-header */
- RUN reset-header(THIS-OBJECT:headerLine).
- END METHOD.
- METHOD public void PrintHeader():
- RUN prt-header(THIS-OBJECT:headerLine, THIS-OBJECT:fontType, THIS-OBJECT:fontSize, THIS-OBJECT:fontColor).
- END METHOD.
- /* Print text at current y position with no cutoff */
- METHOD public void PrintText(printedText AS CHAR, x1 AS INT):
- RUN pdf_text_xy(pdfStream, printedText, x1, pdf_textY(pdfStream)). /* TODO: SET THIS TO pageY */
- END METHOD.
- /* Print text at current y position with no cutoff - this overloaded function takes an integer and prints it as a char */
- METHOD public void PrintText(printedText AS INT, x1 AS INT):
- RUN pdf_text_xy(pdfStream, STRING(printedText), x1, pdf_textY(pdfStream)). /* TODO: SET THIS TO pageY */
- END METHOD.
- /**
- * Skips a number of lines, and pages if necessary, given the current font size and weight.
- *
- * @param int lines: the number of lines to be skipped.
- */
- METHOD public void NextLine(lines AS INT):
- DEF VAR newPageNeeded AS LOG NO-UNDO INIT no.
- RUN next-line-class(lines, "", OUTPUT newPageNeeded).
- /* If on last page, create a new page */
- IF newPageNeeded AND THIS-OBJECT:pageNumber EQ THIS-OBJECT:pageCount THEN DO:
- _newPage().
- END.
- /* Goes to the next page, does not page */
- ELSE IF newPageNeeded AND THIS-OBJECT:pageNumber LT THIS-OBJECT:pageCount THEN DO:
- THIS-OBJECT:pageNumber = THIS-OBJECT:pageNumber + 1.
- _setPage(THIS-OBJECT:pageNumber).
- END.
- /* Else does nothing */
- END METHOD.
- /**
- * Sets the current y position of the stream, from a top-down perspective (top = 0, bottom = pageHeight)
- */
- METHOD public void SetY(y1 AS INT):
- /* Make sure the page height isn't set beyond the page limits */
- IF y1 LE THIS-OBJECT:pageHeight THEN DO:
- RUN sety(y1).
- END.
- ELSE DO:
- MESSAGE "PDF Set Error: Y has been set beyond the page limits in class method SetY with a position of " + STRING(y1).
- END.
- END METHOD.
- /**
- * Returns the current y position of the stream, from a top-down perspective (top = 0, bottom = pageHeight)
- */
- METHOD public INT GetY():
- RETURN THIS-OBJECT:pageHeight - pdf_textY(THIS-OBJECT:pdfStream).
- END METHOD.
- /**
- * Creates a new page. Calls the internal new page function
- */
- METHOD public void NewPage():
- _newPage().
- END METHOD.
- /**
- * Checks to see if the given number of lines will fit on the current page, given the current font size and weight.
- *
- * @param int lines: The number of lines to be checked.
- * @returns log: If yes, then a new page is required.
- */
- METHOD public LOG RequiresNewPage(lines AS INT):
- DEF VAR newPage AS CHAR NO-UNDO.
- newPage = pdf_ckpage2(pdfStream, lines, ""). /* Blank is for color - check to see what it does eventually */
- IF newPage EQ "yes" THEN RETURN yes.
- ELSE IF newPage EQ "no" THEN RETURN no.
- ELSE RETURN no.
- END METHOD.
- /**
- * Checks to see if the given number of lines will fit on the current page, given the current font size and weight. If a new page is needed, creates one autmatically
- *
- * @param int lines: The number of lines to be checked.
- */
- METHOD public void CheckPage(lines AS INT):
- DEF VAR newPage AS CHAR NO-UNDO.
- newPage = pdf_ckpage(pdfStream, lines, ""). /* Blank is for color - check to see what it does eventually */
- IF newPage EQ "new-page" THEN DO:
- _newPage().
- END.
- END METHOD.
- /**
- * Set the page number.
- *
- * @param int pageNum: The page number to set to.
- */
- METHOD public void SetPage(pageNum AS INT):
- _setPage(pageNum).
- END METHOD.
- /**
- * Prints a straight line with the given coordinates, with a set line weight.
- *
- * @param int x1
- * @param int x2
- * @param int y1
- * @param int y2
- */
- METHOD public void PrintLine(x1 AS INT, x2 AS INT, y1 AS INT, y2 AS INT):
- RUN pdf_line(pdfStream, x1, y1, x2, y2, 1).
- END METHOD.
- /**
- * Prints a straight line with the given coordinates, with a custom line weight.
- *
- * @param int x1
- * @param int x2
- * @param int y1
- * @param int y2
- * @param int lineWeight
- */
- METHOD public void PrintLine(x1 AS INT, x2 AS INT, y1 AS INT, y2 AS INT, lineWeight AS INT):
- RUN pdf_line(pdfStream, x1, y1, x2, y2, lineWeight).
- END METHOD.
- /**
- * Sets the current font type
- *
- * @param char fontType
- */
- METHOD public void SetFont(fontType AS CHAR):
- RUN pdf_set_font(THIS-OBJECT:pdfStream, fontType, THIS-OBJECT:fontSize).
- END METHOD.
- /**
- * Sets the current font type and font size
- *
- * @param char fontType
- * @param int fontSize
- */
- METHOD public void SetFont(fontType AS CHAR, fontSize AS INT):
- RUN pdf_set_font(THIS-OBJECT:pdfStream, fontType, fontSize).
- END METHOD.
- /**
- * Sets the current font type
- *
- * @param char fontType
- */
- METHOD public void SetFontSize(fontSize AS INT):
- RUN pdf_set_font(THIS-OBJECT:pdfStream, THIS-OBJECT:fontType, fontSize).
- END METHOD.
- /**
- * Closes the PDF stream
- */
- METHOD public void ClosePDF():
- RUN pdf_close(pdfStream).
- END METHOD.
- /**
- * Internal function for handling paging.
- */
- METHOD private void _newPage():
- /* Make sure that the current page is the last page before running a new page */
- IF THIS-OBJECT:pageNumber EQ THIS-OBJECT:pageCount THEN DO:
- RUN new-page.
- ASSIGN
- THIS-OBJECT:pageNumber = THIS-OBJECT:pageNumber + 1.
- THIS-OBJECT:pageCount = THIS-OBJECT:pageNumber.
- END.
- ELSE DO:
- MESSAGE "PDF Paging Error! Paging must happen on the last page!".
- END.
- END METHOD.
- /**
- * Internal function for handling setting of pages
- * @param int pageNum: the page number to set the PDF to.
- */
- METHOD private void _setPage(pageNum AS INT):
- /* Make sure the page exists */
- IF pageNum GT 0 AND pageNum LE THIS-OBJECT:pageCount THEN DO:
- RUN pdf_set_page(THIS-OBJECT:pdfStream, pageNum).
- THIS-OBJECT:pageNumber = pageNum.
- END.
- ELSE IF pageNum LE 0 THEN DO:
- MESSAGE "Paging error! Page number must be greater than 0. Page number set is " + STRING(pageNum).
- END.
- ELSE IF pageNum GT THIS-OBJECT:pageCount THEN DO:
- MESSAGE "Paging error! Page number must be less than the current page count. Page number set is " + STRING(pageNum).
- END.
- ELSE DO:
- MESSAGE "Paging error! Something went wrong".
- END.
- END METHOD.
- END CLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement