Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Page Count Without Writing to Text #378

Open
robertmiles3 opened this issue Oct 16, 2022 · 1 comment · May be fixed by #871
Open

Get Page Count Without Writing to Text #378

robertmiles3 opened this issue Oct 16, 2022 · 1 comment · May be fixed by #871

Comments

@robertmiles3
Copy link

Is your feature request related to a problem? Please describe.
I am developing PDF documents that will go to a printer and need the ability to know if the generated PDF is a single page or a multi-page document so that I can file them appropriately. There currently seems to be no way to simply get the total page count without writing it to a text element using something like column.Item().Text(content => content.TotalPages());. Even then I can't access the count that it writes to text in order to grab it for other purposes.

Describe the solution you'd like
I would like the ability to get the total page count of a generated document without writing it on the document itself. A property accessible like IDocument.TotalPages would be perfect...

var document = Document.Create(container =>
{
    // foo
});
Console.WriteLine($"Page Count = {document.TotalPages}");

Describe alternatives you've considered
The only alternative I have right now is to use a tool like pdfinfo outside of the dotnet application in order to determine how many pages the document has. It goes without saying that this isn't ideal. 😉

@robertmiles3
Copy link
Author

By looking at some of the code and realizing you can write a text element to null, I did just figure out a workaround albeit hacky by adding the following that writes to a new property...

column.Item().Text(text =>
{
    text.TotalPages().Format(x =>
    {
        TotalPages = Math.Max(x.Value, TotalPages);
        return null;
    });
});

Is this trustworthy enough to use until this feature possible gets added?

@Hummel37 Hummel37 linked a pull request May 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant