KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: 4D View Pro Save Image of Current Sheet
PRODUCT: 4D View Pro | VERSION: 17 | PLATFORM: Mac & Win
Published On: March 20, 2019

With 4D View Pro it is possible to save a snap shot of the sheet as an image.

The following method will allow the view of current sheet with the column and row labels to be saved as an image. It will also include the active cell, row, and column markers.

// Method: VP_SheetToImg
// Description
// Creates an image file of the currently active
// sheet of a 4D View Pro area object
//
// Parameters
// $1 - Text VP area object name
// $2 - Text pathname of resulting object
//
// ----------------------------------------------------

C_TEXT($1;$vpArea_t)
C_TEXT($2;$pathName_t)

C_TEXT($jsCode_t)
C_TEXT($picURL_t)
C_TEXT($picData_t)
C_BLOB($picBlob_b)

If (Count parameters=2)
   $vpArea_t:=$1
   $pathName_t:=$2
  
   $jsCode_t:="document.getElementById('ssvp_vp').toDataURL('image/png');"
  
   $picURL_t:=WA Evaluate JavaScript(*;$vpArea_t;$jsCode_t)
   $picData_t:=Replace string($picURL_t;"data:image/png;base64,";"")
   BASE64 DECODE($picData_t;$picBlob_b)
   BLOB TO DOCUMENT($pathName_t;$picBlob_b)
End if


Example of using the command:
// To save the current sheet of VP Area Object "vpAreaName" as "myVP.png"

VP_Print("vpAreaName";"myVP.png")


Results of the command, Windows Photo Viewer adds a Yellow/Orange Tint, actaul color is correct. Notice that the markers highlighting the active cells, rows, and columns are also captured, so it may be useful to click off to a cell not being displayed.