Normalize PDF orientation with MBS Plugins and DynaPDF
Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ]
# Load PDF from container
Go to Record/Request/Page [ First ]
Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Generate Previews::InputPDF) ]
# Check if first page is rotated
Set Variable [ $rotation ; Value: MBS("DynaPDF.GetImportOrientation"; $pdf; 1) ]
// Show Custom Dialog [ "Rotation is " & $rotation ]
If [ $rotation ≠ 0 ]
# Rotate all pages to 0° if needed
Set Variable [ $page ; Value: 1 ]
Set Variable [ $pageCount ; Value: MBS( "DynaPDF.GetImportPageCount"; $PDF ) ]
Loop
# Check current page rotatations
Set Variable [ $rotation ; Value: MBS("DynaPDF.GetImportOrientation"; $pdf; $page) ]
If [ $rotation = 0 ]
# import as is
Set Variable [ $r ; Value: MBS( "DynaPDF.ImportPDFPage"; $PDF; $page ) ]
Else
# import and rotate
Set Variable [ $template ; Value: MBS( "DynaPDF.ImportPageAsTemplate"; $PDF; $page ) ]
Set Variable [ $template ; Value: MBS( "DynaPDF.RotateTemplate"; $pdf; $template; -$Rotation ) ]
# now put on a new page:
Set Variable [ $r ; Value: MBS( "DynaPDF.AppendPage"; $PDF) ]
Set Variable [ $w ; Value: MBS( "DynaPDF.GetTemplWidth"; $pdf; $template ) ]
Set Variable [ $h ; Value: MBS( "DynaPDF.GetTemplHeight"; $pdf; $template ) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.SetPageWidth"; $PDF; $w) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.SetPageHeight"; $PDF; $h) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.PlaceTemplate"; $PDF; $template; 0; 0; $w; $h) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.EndPage"; $PDF) ]
End If
#
# next page
Set Variable [ $page ; Value: $page + 1 ]
Exit Loop If [ $page > $pageCount ]
End Loop
#
# Save PDF
Set Field [ Generate Previews::OutputPDF ; MBS("DynaPDF.Save"; $pdf; GetAsText ( Generate Previews::InputPDF )) ]
End If
Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]