Page Generation Landscape/Portrait · Issue #352 · QuestPDF/QuestPDF · GitHub
Skip to content

Page Generation Landscape/Portrait #352

Closed

Description

@denizakkas

Problem:
We generate pdfs atm in dimmension of 62x29. Which will be printed on varity of devices with the same Printer.
Some Devices doesnt allow on print switching from landsacpe to Portrait while some devices expect on the other hand that the pdf will be in Portrait mode. One one device i need to print 62x29 on another device like Ipad i need to print it as 29x62.

Our current solution looks like this
page.Content().Container().RotateRight().Element(..)
But if u have Header or Footer this wont work well.

We generate the Pdf as 62x29 but should be allowed to rotate it on its side so the result would be 29x62

Solution:
The perfect solution would be to have some settings in page, to allow it to rotate the entire content, header and footer.
page.ApplyRotateRight();

Activity

  1. bennetbo commented on Oct 2, 2022

    @bennetbo
    Contributor

    I believe you are looking for this.
    In your PageDescriptor set your size to landscape mode, e.g. page.Size(PageSizes.A4.Landscape().

  2. denizakkas commented on Oct 2, 2022

    @denizakkas
    Author

    Thanks for the quick answer. The problem is i will get an layout exception. Since i would expected my container to be a specfic size.

    My Container is designed to create an Landscape 62x29. But i want to create in specifc cases the same flipped as 29x62. Without duplicating any Container Code to have special cases for portait 29x62

    grafik

  3. MarcinZiabek commented on Oct 2, 2022

    @MarcinZiabek
    Member

    @BEBO-MAKER Thank you for a quick answer!

    @denizakkas You can try using the ScaleToFit element, but it is always a compromise. If your content expects a very specific available size (e.g. due to hardcoded values), the library cannot help much. If the exception is thrown because of layout contraints, you can investigate them further using the ElementTrace information.

  4. denizakkas commented on Oct 2, 2022

    @denizakkas
    Author

    @MarcinZiabek thanks for that information

    So in this example here. You would suggest to use instead a fixed height then? And get rid of the header/footer. So i can simply RotateRight the remaining Content?
    grafik

    Since i dont see any other way to make this work.
    I still think besides this exmaple. It can be pretty usefull to rotate the whole page including Footer and Header

  5. MarcinZiabek commented on Oct 3, 2022

    @MarcinZiabek
    Member

    I am not sure if I follow. Would you like to provide more detailed images? I am especially interested in the content direction within Header / Content / Footer.

  6. denizakkas commented on Oct 4, 2022

    @denizakkas
    Author

    @MarcinZiabek Sorry i should comeup with an Codeexample to make it more Clear. Including and proper Image.

    Here we go lets look at this example

    As an Example for an Implementation
    grafik

        container.Page(
            page =>
            {
                page.Size( 62f, 29f, Unit.Millimetre);
                page.Margin( 3, Unit.Millimetre);
    
                page.Header().LineHorizontal(2);
                page.Content().Text("Test");
                page.Footer().LineHorizontal(2);
            }
        );
    

    Since i want it rotate on its side, the most obvious way to Rotate it would be to use RotateLeft for example on Header & Content & Footer. Which will of course not work. (Which is absolutly okay)

    grafik

        container.Page(
            page =>
            {
                page.Size( 292f, 62f, Unit.Millimetre);
                page.Margin( 3, Unit.Millimetre);
    
                page.Header().RotateLeft().LineHorizontal(2);
                page.Content().RotateLeft().Text("Test");
                page.Footer().RotateLeft().LineHorizontal(2);
            }
        );
    

    What i am forced now Todo is something like that to get my expected result. Which will make Header & Footer completly obsolute for this usecase.

        container.Page(
            page =>
            {
                page.Size( 29f, 62f, Unit.Millimetre);
                page.Margin( 3, Unit.Millimetre);
    
                page.Content().RotateLeft().Column(
                    col =>
                    {
                        col.Item().LineHorizontal(2);
                        col.Item().Height(21f, Unit.Millimetre).Text("Test");
                        col.Item().LineHorizontal(2);
    
                    });
            }
        );
    

    grafik

    And my suggestion is something like a SetPortrait() function or maybe some ApplyRotateLeft to force Rotating Header, Content and Footer all together.
    Or maybe some DocumentMetaData to allow it rotate the result.

        container.Page(
            page =>
            {
                page.Size( 62f, 29f, Unit.Millimetre);
                page.Margin( 3, Unit.Millimetre);
                **page.SetPortrait();**
    
                page.Content().Column(
                    col =>
                    {
                        page.Header().LineHorizontal(2);
                        page.Content().Text("Test");
                        page.Footer().LineHorizontal(2);
                    });
            }
        );
    

    Sorry for that long post.

  7. MarcinZiabek commented on Oct 4, 2022

    @MarcinZiabek
    Member

    The Page element works as a very specific composition, take a look at this code inside the library. You can recreate similar structure yourself inside the Content slot.

    Then, you have much better control over entire layout. For example, you can use the content rotation trick that I have described in this issue. Maybe this will help you somehow.

    Also, would you like to take a look at this PR ans provide your thoghts? #357

  8. MarcinZiabek commented on Mar 4, 2025

    @MarcinZiabek
    Member

    Since there has been no recent activity, I’m closing this issue. If you experience a similar problem or have a related request, feel free to open a new GitHub issue. I appreciate your feedback! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions