PrintPreview help for landscape

Hello friends,
I have a procedure that opens a landscape form. Everything is working fine except for one thing. When I select printpreview it shows as portrait mode. The form is in landscape mode. When I print I can select “orientation”,“landscape”. When using printpreview there is no parameters where I can select “landscape”. Any help would be appreciated.

OpenForm “Discount Listing”
Alertsheet “What do you want to display with this form?”,“Buttons”,“Cancel,Print,Print to PDF on Desktop,Preview”
if info(“dialogtrigger”)=“Print to PDF on Desktop”
printtopdf “~/Desktop/Discount Listing 2019-2020.pdf”,“form”,“Discount Listing”,“orientation”,“Landscape”
Closewindow
removeallsummaries
selectall
elseif info(“dialogtrigger”)=“Print”
printtopdf “”,“Printer”,"",“orientation”,“Landscape”
Closewindow
removeallsummaries
selectall
elseif info(“dialogtrigger”)="Preview"
printpreview
Closewindow**
removeallsummaries**
selectall**
elseif info(“dialogtrigger”)=“Cancel”
Closewindow
removeallsummaries
selectall
endif

I think you could use PrinttoPdf with the correct orientation to create a file, then open the file (Openanything [path] or Openwith “Preview”, [path]) , then delete the file (Fileerase [path]). I haven’t tested this.

If you use the Page Setup dialog to set the orientation to landscape before running your procedure, the preview will use landscape orientation.

If you want to do this programmatically, without having to use the Page Setup dialog, Tom’s answer is the correct one, except for the part about deleting. If you delete the file right away, Preview won’t be able to show it. Instead of deleting it right away, create it in the temporary folder, with a temporary name, as shown in the code below. The temporary folder is a special macOS file where you can put short term items. If you leave a file in there, macOS will automatically delete it after a couple of days. So you don’t have to worry about deleting it yourself.

let tempPDFname = info("tempfolder")+info("databasename")+"."+timestampstr()+".pdf"
printtopdf tempPDFname,
    "orientation","landscape",
    "scale",info("pagesetupscale"),
    "height",info("pagesetuppaperheight"),
    "width",info("pagesetuppaperwidth")
openanything tempPDFname

By the way, I pulled this code from the code for Preview that Panorama itself uses. The only change I made was to make it always use landscape, instead of getting the orientation from the document page setup.