var poPDF = render.transaction({
entityId: recId,
printMode: render.PrintMode.PDF
});
poPDF.folder= folderID;
var fileId = poPDF.save();
The above is a sample function to generate the PDF of any transaction. This code will generate a PDF based on the form selected in the transaction and it can be saved to the desired folder.