KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Method to save a 4D Write Document as a PDF file
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: January 21, 2015

It is possible to save a 4D Write Document as a PDF file instead of one of the default types listed below:



Before using the method, Windows Platforms will need the PDFCreator printer drivers which can be obtained at the following link:
https://sourceforge.net/projects/pdfcreator/files/PDFCreator/
Select one of the drivers and install it on all windows machines that will be using this function. There are two types of UI's for PDFCreator an older type for versions 1.7.x and older and a newer type for 1.9.x and up. Based on the version there will be differences in performing the save as a PDF.

Below is the method to save a 4D Write Document as a PDF on MacOS, WRtoPDF_Mac:

C_LONGINT($1;$WR_refl)
C_TEXT($2;$pathname_t)

If(Count parameters>=2)
 $WR_refl:=$1
 $pathname_t:=$2

 WR SET PRINT OPTION ($WR_refl;wr destination option;3;0;$pathname_t)
 WR PRINT ($WR_refl;0;1)
End if



Next is the method for Windows, WRtoPDF_Win:

C_LONGINT($1;$WR_refl)
C_TEXT($2;$pathname_t)
C_TEXT($3;$filename_t)

If(Count parameters>=2)
 $WR_refl:=$1
 $pathname_t:=$2

 SET CURRENT PRINTER(PDFCreator Printer name)

 If (OK=1)
  SET PRINT OPTION("PDFOptions:UseAutosave";1)

  If(Count parameters>=3)
   $filename_t:=$3
   SET PRINT OPTION(Spooler document name option;$filename_t)

  Else
   SET PRINT OPTION(Destination option;3;$pathname_t)
  End if

  OPEN PRINTING JOB
  WR PRINT ($WR_refl;wr print values;1)
  CLOSE PRINTING JOB
  SET PRINT OPTION("PDFInfo:Reset standard options";0)
 End if
End if


In the Windows version there is an optional thierd parameter that is needed to use save a 4D Write Document as a PDF with the newer verions of PDFCreator (1.9.x and up). The default naming convention is based on the print job's name in the newer version. The naming convention can also be left up to PDF creator's UI.



The older versions of PDFCreator uses the same format as Mac to name the file with the $pathname variable.

Then both methods can be combined into one single method for flexibility in WRtoPDF_Main:

C_LONGINT($1$WR_refl;$os_t)
C_TEXT($2;$pathname_t)
C_TEXT($3;$filename_t)

If(Count parameters>=2)
 $WR_refl:=$1
 $pathname_t:=$2

 PLATFORM PROPERTIES($os_t)
 If ($os_t=Windows)
  If(Count parameters>=3)
   $filename_t:=$3
   WRtoPDF_Win($WR_refl;$pathname_t;$filename_t)

  Else
   WRtoPDF_Win($WR_refl;$pathname_t)
  End If

 Else
  WRtoPDF_Mac($WR_refl;$pathname_t)
 End if
End if


These methods will allow 4D Write documents to be saved in a PDF format. Example to use the command is shown below with the 4D Write Area's object name as wrArea, the first is for those with the older versions of PDFCreator and the second is for the newer ones.

C_TEXT($pathname_t)

$pathname_t:=Get 4D folder(Current resources folder)
$pathname_t:=$pathname_t+"Pdf_name.pdf"

WRtoPDF_Main (wrArea;$pathname_t)


C_TEXT($pathname_t)
C_TEXT($filename_t)

$pathname_t:=Get 4D folder(Current resources folder)
$pathname_t:=$pathname_t+"Pdf_name.pdf"
$filename_t:="Pdf_name"

WRtoPDF_Main (wrArea;$pathname_t;$filename_t)