I roughly do it like this for pdf (I'm just showing parts which I think are relevant to keep the code simple).
The fastreport template remains the same whether it is used for printing or export to pdf
聽 local oFrPrn := frReportManager():new("frsysth.dll")
oFrPrn:setWorkArea("payroll", select("payroll")) // must be before :loadFromfile()
oFrPrn:setWorkArea("staff", select("staff"))
oFrPrn:SetResyncPair("payroll", "staff")
oFrPRn:loadFromFile("payslip.fr3")
聽 oFrPrn:printOptions:SetShowDialog(.f.)
聽 oFrPrn:SetProperty("PDFExport", "ShowDialog", .f.)
聽 oFrPrn:SetProperty("PDFExport", "Compressed", .t.)
聽 oFrPrn:SetProperty("PDFExport", "EmbeddedFonts", .f.)
聽 oFrPrn:SetProperty("PDFExport", "OpenAfterExport", .f.)
聽 oFrPrn:SetProperty("PDFExport", "PrintOptimized", .t.)
聽 oFrPrn:SetProperty("PDFExport", "ShowProgress", .f.)
聽 oFrPrn:SetProperty("PDFExport", "Background", .t.)
聽 oFrPrn:SetProperty("PDFExport", "Title", "Payslip")
聽 oFrPrn:SetProperty("PDFExport", "Subject", "Period: "+dtoc((cDbf)->frange) + " - "+dtoc((cDbf)->trange) )
聽 oFrPrn:SetProperty("PDFExport", "Author", "Bill Gates")
聽 oFrPrn:SetProperty("PDFExport", "Creator", "Microsoft")
聽 oFrPrn:SetProperty("PDFExport", "OwnerPassword", "Mine!")
聽 oFrPrn:SetProperty("PDFExport", "DefaultPath", ud_outDir())
聽 oFrPrn:SetProperty("PDFExport", "OverWritePrompt", .f.)
聽 oFrPrn:SetProperty("PDFExport", "ProtectionFlags", "[ePrint, eCopy]")
聽 oFrPrn:SetProperty("PDFExport", "FileName", cPdf)
聽 if lEncrypt
聽 聽 聽oFrPrn:SetProperty("PDFExport", "UserPassword", cUserPassword)
聽 endif
聽 oFrPrn:PrepareReport()
聽 oFrPrn:DoExport("PDFExport")
聽 oFrPrn:end()