Adjust all content fit in a page

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Aug 5, 2024
Company:

How can the content of a printed page automatically fit on one page and be centered?

Currently,

this print form mainly uses A5 size
the number of lines is arbitrary
In the case that the number of lines increases, is there a way for the font size to automatically adjust so that the printed page does not overflow to another page?

In practice, when I adjust the print scale, it tends to keep the alignment towards the top-left of the printed page.

Thank in advance

Have a good day

 
#2
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Aug 14, 2024
Company:

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.

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.