This is what I've come up with. I'm not certain it will work, but it's worth a try.
You'll need to implement the following script:
| Code |
|---|
Procedure AdjustFontSizeAndMarginsBeforePrint(PrintForm)
// Set default values
MaxLines = 50; // Example: Maximum lines that fit on an A5 page
ActualLines = PrintForm.LineCount();
// Calculate if font size adjustment is needed
If ActualLines > MaxLines Then
ScaleFactor = MaxLines / ActualLines;
AdjustedFontSize = PrintForm.FontSize * ScaleFactor;
PrintForm.SetFontSize(AdjustedFontSize);
EndIf;
// Calculate margins for centering
ContentHeight = PrintForm.ContentHeight;
ContentWidth = PrintForm.ContentWidth;
VerticalMargin = (A5Height - ContentHeight) / 2;
HorizontalMargin = (A5Width - ContentWidth) / 2;
// Apply the calculated margins
PrintForm.SetMargins(VerticalMargin, HorizontalMargin);
EndProcedure |
If you have any questions, feel free to write them down. We'll try to figure it out somehow.