Skip to content

PDF Management

IMPORTANT: These functions only create and edit PDF files. To view them, go to the "Advanced Scene Lua 5.1 MANAGE FILE" tutorial page.

Name Input Params Return Data Description
resiot_pdfnew String, String String, String Create a new PDF file
resiot_pdfsave String String Save the PDF file
resiot_pdfdrawline String, Float64, Float64, Float64, Float64, Float64 String Draw a line in the PDF file
resiot_pdftext String, Float64, Float64, String, String, String, Float64 String Write a text in the PDF file
resiot_pdfimage String, String, Float64, Float64, Float64, Float64, String String Copy an image in the PDF file
resiot_pdfaddpage String String Add a new page in the PDF file
resiot_pdfcolor String, Int, Int, Int String Change the default color of all the text that's going to be written after the execution

resiot_pdfnew(String, String)

Create a new PDF file.
Example
IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
Input Parameters
 - Orientation (String): * The orientation of the pages of the PDF file. It can only have four values: "P" or "Portrait" and "L" or "Landscape".
 - Format (String): * The format of the pages of the PDF file. It can only have six values: "A3", "A4", "A5", "Letter", "Legal" or "Tabloid"

Returns
 - IdHexPDF (String): * Hexadecimal Id of the PDF file denerated.
 - Error (String): * If the function couldn't create a PDF file, the error is written here.

Orientation = "P"  -- Possible Values: ["P", "Portrait", "L", "Landscape"];
Format = "A4"      -- Possible Values: ["A3", "A4", "A5", "Letter", "Legal", "Tabloid"]; If left empty  it will take "A4" as default
IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
else
    -- value read correctly
    resiot_debug(IdHexPDF)
end

Return to index


resiot_pdfsave(String)

Save the PDF file.
Example
Error = resiot_pdfsave (IdHexPDF)
Input Parameters
 - IdHexPDF (String): * Hexadecimal Id of the PDF you want to save. This value is returned by the function "resiot_pdfnew".
Returns
 - Error (String): * If the function couldn't save the PDF file, the error is written here.

IdHexPDF = "617474313534" -- IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
Error = resiot_pdfsave (IdHexPDF)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end

Return to index


resiot_pdfdrawline(String, Float64, Float64, Float64, Float64, Float64)

Draw a line in the PDF file.
Example
Error = resiot_pdfdrawline (IdHexPDF, Width, X1, Y1, X2, Y2)
Input Parameters
 - IdHexPDF (String): * Hexadecimal Id of the PDF in which you want to draw. This value is returned by the function "resiot_pdfnew".
 - Width (Float64): * The width of the line you want to write. (in millimeters)

 - X1 & Y1 (Float64): * The coordinates in which the line starts. They are calculated using the distance of the point from the sides of the sheet.
 - X2 & Y2 (Float64): * The coordinates in which the line ends. They are calculated using the distance of the point from the sides of the sheet.

Returns
 - Error (String): * If the function couldn't draw on the PDF file, the error is written here. *

IdHexPDF = "617474313534" -- IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
Width = 0.2               -- 0.2 mm of width for the line
-- Orizzontal line Example:
X1 = 10
Y1 = 10
X2 = 50
Y2 = 10
-- Vertical line Example:
X1 = 10
Y1 = 10
X2 = 10
Y2 = 50
-- Oblique line Example:
X1 = 10
Y1 = 10
X2 = 50
Y2 = 50
-- 
Error = resiot_pdfdrawline (IdHexPDF, Width, X1, Y1, X2, Y2)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end

Return to index


resiot_pdftext(String, Float64, Float64, String, String, String, Float64)

Write a text in the PDF file.
Example
Error = resiot_pdftext (IdHexPDF, X, Y, Text, Font, Style, Size)
Input Parameters
 - IdHexPDF (String): * Hexadecimal Id of the PDF in which you want to draw. This value is returned by the function "resiot_pdfnew".
 - X & Y (Float64): * The coordinates in which the text starts. They are calculated using the distance of the point from the sides of the sheet.

 - Text (String): * The text you want to write in the PDF file.
 - Font (String): * The font in which the text will be written. This option use the standard type of fonts.

 - Style (String): * The Style in which the text will be written. The possibilities are "B" (Bold), "U" (Underline) and "I" (Italic). They can be used together.
 - Size (Float64): * The Size in which the text will be written.

Returns
 - Error (String): * If the function couldn't draw on the PDF file, the error is written here. *

IdHexPDF = "617474313534" -- IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
X = 10
Y = 10
Text = "Some Example Text"
Font = "Arial"
Style = "BUI"             -- This means that the text will be Bold, Underlined and in Italic form. 
                          -- If you don't want one of these you can use all the combination that you want.
                          -- For example you can use only "BI" to be Bold and in Italic form
Size = 10
Error = resiot_pdftext (IdHexPDF, X, Y, Text, Font, Style, Size)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end

Return to index


resiot_pdfimage(String, String, Float64, Float64, Float64, Float64, String)

Copy an image in the PDF file. To work correctly you need first to upload the image you wish to copy in the pdf file, to do so you need to go to the page "Attachment List".
Example
Error = resiot_pdfimage (IdHexPDF, IdHexAttachment, X, Y, Width, Height, URL)
Input Parameters
 - IdHexPDF (String): * Hexadecimal Id of the PDF in which you want to draw. This value is returned by the function "resiot_pdfnew".
 - IdHexAttachment (String): * Hexadecimal Id of the Image saved in the attachment table. This value can be found in the "Attachment List" page.

 - X & Y (Float64): * The coordinates in which the text starts. They are calculated using the distance of the point from the sides of the sheet.
 - Width (Float64): * The Width of the image. If this and the Height are 0 then it will take the default Width value of the image.

 - Height (Float64): * The Height of the image. If this and the Width are 0 then it will take the default Height value of the image.
 - URL (String): * The link of the page that will open when the image is clicked. If it is left empty, then clicking the image won't open any web page.

Returns
 - Error (String): * If the function couldn't copy the image on the PDF file, the error is written here. *

IdHexPDF = "617474313534" -- IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
IdHexAttachment = "617474393034" -- Hexadecimal Id of a row  of the page "Attachment List"
X = 10
Y = 10
Width = 0
Height = 0
URL = ""
Error = resiot_pdfimage (IdHexPDF, IdHexAttachment, X, Y, Width, Height, URL)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end

Return to index


resiot_pdfaddpage(String)

Add a new page in the PDF file.
Example
Error = resiot_pdfaddpage (IdHexPDF)
Input Parameters
 - IdHexPDF (String): * Hexadecimal Id of the PDF in which you want to add a new page. This value is returned by the function "resiot_pdfnew".
Returns
 - Error (String): * If the function couldn't add another page in the PDF file, the error is written here.

IdHexPDF = "617474313534" -- IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
Error = resiot_pdfaddpage (IdHexPDF)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end

Return to index


resiot_pdfcolor(String, Int, Int, Int)

Sets the color of all the text after this line .
Example
Error = resiot_pdfaddpage (IdHexPDF)
Input Parameters
 - IdHexPDF (String): * Hexadecimal Id of the PDF in which you want to add a new page. This value is returned by the function "resiot_pdfnew".
 - Red (Int): * Red color. Valid values go from 0 to 255.

 - Green (Int): * Green color. Valid values go from 0 to 255.
 - Blue (Int): * Blue color. Valid values go from 0 to 255.

Returns
 - Error (String): * If the function find your pdf or you set an invalid color value, you'll get more details here. Empty otherwise. *

IdHexPDF = "617474313534" -- IdHexPDF, Error = resiot_pdfnew (Orientation, Format)
Error = resiot_pdftext (IdHexPDF, 10, 10, "Default color text", "Arial", "BUI", 12)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end
Error = resiot_pdfcolor (IdHexPDF, 255, 0, 0) -- All text being added after this will be red
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end
Error = resiot_pdftext (IdHexPDF, 10, 40, "Red color text", "Arial", "BUI", 12)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
end
-- 
-- Result Example:
-- Default color text (colored in black)
-- Red color text (colored in red)

Return to index