Skip to content

Commit c45efdc

Browse files
docs/recipes-stories.rst: added descriptions of Story.write*() samples.
1 parent 04d1e66 commit c45efdc

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

docs/recipes-stories.rst

+84
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,90 @@ This example takes some JSON data input which it uses to populate a :ref:`Story`
374374

375375

376376

377+
-----
378+
379+
380+
Using the alternative :meth:`Story.write*()` functions
381+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
382+
383+
The :meth:`Story.write*()` functions provide a different way to use the
384+
:ref:`Story` functionality, removing the need for calling code to implement
385+
a loop that calls :meth:`Story.place()` and :meth:`Story.draw()` etc, at the
386+
expense of having to provide at least a ``rectfn()`` callback.
387+
388+
389+
How to do basic layout with :meth:`Story.write()`
390+
-------------------------------------------------
391+
392+
This script lays out multiple copies of its own source code, into four
393+
rectangles per page.
394+
395+
``docs/samples`` file ``story-write.py``.
396+
397+
|toggleStart|
398+
399+
.. literalinclude:: samples/story-write.py
400+
401+
|toggleEnd|
402+
403+
404+
-----
405+
406+
How to do iterative layout for a table of contents with :meth:`Story.write_stabilized()`
407+
----------------------------------------------------------------------------------------
408+
409+
This script creates html content dynamically, adding a contents section based
410+
on :ref:`ElementPosition` items that have non-zero ``.heading`` values.
411+
412+
The contents section is at the start of the document, so modifications to the
413+
contents can change page numbers in the rest of the document, which in turn can
414+
cause page numbers in the contents section to be incorrect.
415+
416+
So the script uses :meth:`Story.write_stabilized()` to repeatedly lay things
417+
out until things are stable.
418+
419+
420+
``docs/samples`` file ``story-write-stabilized.py``.
421+
422+
|toggleStart|
423+
424+
.. literalinclude:: samples/story-write-stabilized.py
425+
426+
|toggleEnd|
427+
428+
429+
430+
-----
431+
432+
433+
How to do iterative layout and create PDF links with :meth:`Story.write_stabilized_links()`
434+
-------------------------------------------------------------------------------------------
435+
436+
This script is similar to the one described in "How to use
437+
:meth:`Story.write_stabilized()`" above, except that the generated PDF also
438+
contains links that correspond to the internal links in the original html.
439+
440+
This is done by using :meth:`Story.write_stabilized_links()`; this is slightly
441+
different from :meth:`Story.write_stabilized()`:
442+
443+
* It does not take a :ref:`DocumentWriter` ``writer`` arg.
444+
* It returns a PDF :ref:`Document` instance.
445+
446+
[The reasons for this are a little involved; for example a
447+
:ref:`DocumentWriter` is not necessarily a PDF writer, so doesn't really work
448+
in a PDF-specific API.]
449+
450+
451+
``docs/samples`` file ``story-write-stabilized-links.py``.
452+
453+
|toggleStart|
454+
455+
.. literalinclude:: samples/story-write-stabilized-links.py
456+
457+
|toggleEnd|
458+
459+
460+
377461
-----
378462

379463

0 commit comments

Comments
 (0)