We help IT Professionals succeed at work.

Formatting and layout in word or pdf

167 Views
Last Modified: 2017-07-19
Hi All,

We have an requirement to adjust formatting and layout (like., fonts, line breaks in table, columns and margins) of word or PDF files using any script [Perl, Python or Ruby].

Can you please suggest or provide any references or sample codes for this or suggest which scripting languages will be good for such requirements.

Thanks,
Shail
Comment
Watch Question

Walter RitzelSenior Software Engineer
CERTIFIED EXPERT

Commented:
The best starting point I know is this: https://automatetheboringstuff.com/chapter13/
It uses python and give pointers to python libraries that can handle PDF and word documents.
Colleen Kayter4D Assets

Commented:
Why are you scripting vs. applying a theme that sets all that on the fly? Just curious. With security restrictions becoming more prevalent, I would think that scripting might not work well everywhere.
Shailesh ShindeSr. Project Manager

Author

Commented:
Hi Colleen Kayter,

The reason for scripting is to include this script in existing automated processing workflow.
This script will read the config file which will contains
font-size=##
font-name=###
....
and manipulate the input source word or pdf files.

Thanks,
Shail
Shailesh ShindeSr. Project Manager

Author

Commented:
Hi All,

Can formatting be applied to the text level and the page level to a specific paragraph, a set of paragraphs, a range of pages. Is this possible using perl or python scripts?

Thanks,
Shail
4D Assets
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Shailesh ShindeSr. Project Manager

Author

Commented:
Hi,

Waiting for coder experts comments.

Thanks,
Shail
Most Valuable Expert 2011
Author of the Year 2014

Commented:
This looks at things from a PHP perspective, so it may or may not fit your environment, but since PHP is free and open-source it could be worth considering.

PHP has two well-supported libraries for building PDF documents: FPDF and TCPDF.  Both are self-contained object-oriented libraries.  The documentation is pretty good. and they have online examples.  I have never used them to import and adjust pre-existing PDF files, but some others in the E-E forums claim this can be done.  Most of my work has been to take external inputs (forms, databases, API data) and build PDF documents.  For this kind of work, either of the extensions will work well, giving you access to a variety of fonts, colors, layouts, and image placements.