Scaling preformatted text to fit the page width

Are you missing a feature? Request its implementation here.
chrispitude
Posts: 455
Joined: Thu May 02, 2019 2:32 pm

Scaling preformatted text to fit the page width

Post 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!
chrispitude
Posts: 455
Joined: Thu May 02, 2019 2:32 pm

Re: Scaling preformatted text to fit the page width

Post 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.
julien_lacour
Posts: 257
Joined: Wed Oct 16, 2019 3:47 pm

Re: Scaling preformatted text to fit the page width

Post 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
chrispitude
Posts: 455
Joined: Thu May 02, 2019 2:32 pm

Re: Scaling preformatted text to fit the page width

Post 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.
julien_lacour
Posts: 257
Joined: Wed Oct 16, 2019 3:47 pm

Re: Scaling preformatted text to fit the page width

Post 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
Post Reply