<< Click to Display Table of Contents >> Navigation: How to > Print a PDF |
vpxPrint can print a file and create a pdf in a single run.
You can also do a lot of things with PDF files including:
1.import the pages of one or more pdf files,
2.merge or rearrange them with other PDF,
3.adding anything,
4.preview or not,
5.direct and silently printing,
6.create a new pdf file and/or print,
7.etc...
A PROGRESS procedure to see different situations with 4 PDF pages / page or page / page (simply delete the "<PREVIEW>" tag to print the file directly:
{ xprint.i }
DEF STREAM I. DEF STREAM O.
DEF VAR Filename AS CHAR NO-UNDO. DEF VAR i AS INT NO-UNDO. DEF VAR tempDIR AS CHAR NO-UNDO. DEF VAR inputFile AS CHAR NO-UNDO.
DEF VAR BaseName AS CHAR NO-UNDO. DEF VAR AbsName AS CHAR NO-UNDO. DEF VAR FileType AS CHAR NO-UNDO. DEF VAR xprFILE AS CHAR NO-UNDO. DEF VAR ReturnStatus AS INT NO-UNDO. DEF VAR commandLine AS CHAR NO-UNDO.
DEF VAR OK AS LOGICAL NO-UNDO.
SYSTEM-DIALOG GET-FILE inputFile FILTERS "Source Files (*.pdf)" "*.pdf" MUST-EXIST TITLE "Select the PDF file" UPDATE OK.
IF NOT OK THEN RETURN.
tempDir = SESSION:TEMP-DIRECTORY.
/* Create unique names =================*/ FILENAME = "PDF" + REPLACE(STRING(ETIME(TRUE)), '999', '777') + "_999.jpg". commandLine = '"' + inputFile + '" ' + tempDir + FILENAME + " -pages=all -quality=100":U.
/*================= Extract all pages from the PDF ======= just to know the number of pages */ SESSION:SET-WAIT-STATE("GENERAL"). RUN ExecuteAndWait("PDFtoJpg.exe", commandLine, tempDir, 1, returnStatus). SESSION:SET-WAIT-STATE(""). /*==========================================================================================*/
FILENAME = REPLACE(FILENAME, "999.jpg", ""). xprFile = tempDir + "PDFtoVPX.xpr".
/* Sort the pages: ============*/
INPUT STREAM i FROM OS-DIR(tempDir) NO-ECHO. I = 0. DEF WORKFILE P NO-UNDO FIELD JPGName AS CHAR.
REPEAT : IMPORT Stream I BaseName AbsName FileType. If FileType = "F" AND baseName BEGINS FILENAME THEN DO: i = i + 1. CREATE P. JPGName = AbsName. END. END.
INPUT STREAM I CLOSE.
MESSAGE "The file" inputFile "has" I "page" + STRING(i > 1, "s./.") SKIP (1) "Files are in the" tempDir "folder ," SKIP "with a generic name of '" FILENAME + "xxx.jpg'." VIEW-AS ALERT-BOX INFO.
/* Create the xpr file =================*/ OUTPUT STREAM O TO VALUE(xprFile) PAGED PAGE-SIZE 1024. PUT STREAM o CONTROL '<preview>' /* Delete if no preview */ '<units=mm><FArial>'.
PUT STREAM O UNFORMATTED "<P28><R30><CENTER=C80><B>Example: 4 PDF pages / vpxPrint page" SKIP(2) "<P12><CENTER=C80></B><I>" inputFile " has " i " page" STRING(i > 1, "s./.") "</I>" SKIP.
PAGE STREAM O.
/* define 4 frames to receive the 4 PDF pages on a page: */ /* ===================================================== */ PUT STREAM o CONTROL
'<#1><at=145,100><#11>' '<at=#1,105><#2><at=#11,+100><#12>' '<at=+5,#1><#3><at=+140,100><#13>' '<at=#3,#2><#4><at=+140,#12><#14>'.
/* Sort by names ===========*/ i = 0. FOR EACH P BY JPGName: i = i + 1. /* draw a rectangle around the page (<rect#1>) */ PUT STREAM o UNFORMATTED "<=" i + 10 "><IMAGE#" i "=" P.JPGName "><rect#1>" SKIP. IF i = 4 THEN DO: PAGE STREAM O. i = 0. END. END.
PAGE STREAM O. PUT STREAM O UNFORMATTED "<P28><R30><CENTER=C80><B>Example: 1 PDF page / vpxPrint page". PAGE STREAM O.
/* One PDF page per vpxPrint page ++++++++++++++++++++++++++++*/ PUT STREAM o CONTROL '<#1><at=297,210><#2>'.
/* Sort by names ===========*/ FOR EACH P BY JPGName: PUT STREAM o UNFORMATTED "<=2><IMAGE#1=" P.JPGName ">" SKIP. PAGE STREAM O. END.
OUTPUT STREAM O CLOSE.
RUN printFile(xprFile).
FOR EACH P: OS-DELETE VALUE(JPGName). END.
/* OS-DELETE VALUE(xprFile). */
|