Page 1 of 1

Scaling preformatted text to fit the page width

Posted: Fri Feb 04, 2022 7:56 pm
by chrispitude
Hi everyone,

We sometimes run into problems when we have wide text content in our <pre> elements, such as columnar reports from a software program:

Code: Select all

prompt> report_something -wide

Name                                                 Status     Configuration    Options       Attributes
----------------------------------------------------------------------------------------------------------
some_hierarchical_path/lower_level_path/object_1     valid      foo=1, bar=2     -something    x, y, z
some_hierarchical_path/lower_level_path/object_2     invalid    foo=3, baz=4     -nothing      q, r, s
Sometimes we are able to manually edit the output in a text editor to remove whitespace width or shorten names; but sometimes that isn't enough.

We also have an @outputclass value of smallfonts that applies CSS to reduce the font size by 1pt, and a value of wide that applies CSS to move the left margin leftward.

But sometimes, even manual editing, plus smallfonts, plus wide aren't enough. (This typically occurs with tabular reports in which every column is significant to the example.)

I thought about implementing additional @outputclass values (smallerfonts? smallestfonts??) to reduce the font size even more. But that is granular by construction, and it's a bit hacky and company-specific.

Does PDF Chemistry have some magic way to scale a <pre> to precisely as small as it needs to be to fit the available width? Then we could just apply @outputclass="wide" plus this additional magic property, let the text scale into that, and call it good.

Thanks!

Re: Scaling preformatted text to fit the page width

Posted: Fri Feb 04, 2022 7:59 pm
by chrispitude
I should mention that the solution does not need to be include WebHelp, as browsers tend to have wider aspect ratios; a PDF-only solution is perfectly fine.

Re: Scaling preformatted text to fit the page width

Posted: Tue Feb 08, 2022 5:27 pm
by julien_lacour
Hello,

A solution could be to rotate the pages containing those <pre> elements, by using the following CSS:

Code: Select all

*[class ~= "topic/pre"][outputclass ~= "wide"],
*[class ~= "pr-d/codeblock"][outputclass ~= "wide"] {
  page: landscape-page;
}
And adding the @outputclass="wide" on the element that need more space.

Is this solution enough for this use-case?

Regards,
Julien

Re: Scaling preformatted text to fit the page width

Posted: Mon Apr 25, 2022 8:47 pm
by chrispitude
Hi Julien,

Page rotation is not a good solution for us, as it would be too disruptive to the flow of the book. (Plus, we have some PDF post-processing that assumes all pages are in portrait orientation.)

Hi everyone,

I noticed that PDF Chemistry does honor the @scale attribute for some elements (like <table> and <equation-figure>) but not for <pre> and <codeblock>. I filed an enhancement request with Julien to support this, and he or I will reply back here if it gets implemented.

Re: Scaling preformatted text to fit the page width

Posted: Tue Apr 26, 2022 2:03 pm
by julien_lacour
Hi Chris,

The @scale attribute support will be available on both Oxygen's next maintenance build and next version.
You will be able to set a smaller scaling factor on those huge codeblocks :D

Regards,
Julien

Re: Scaling preformatted text to fit the page width

Posted: Wed Jun 22, 2022 8:51 pm
by chrispitude
Hi Julien,

I see that the @scale attribute is now supported for <pre> blocks in the latest v24.1 maintenance release - thank you!

- Chris