7024

Place a vertical or rotated text in a PDF with Python

Question:

I'm currently generating a PDF with PyFPDF. I also need to add a vertical/rotated text. Unfortunately, it's not directly supported in PyPDF as far as I see. There are solutions for FPDF for PHP.

<strong>Is there a way to insert vertical or rotated text in a PDF from Python, either with PyFPDF or with another library?</strong>

Answer1:

I believe you can do so with <a href="http://pymupdf.readthedocs.io/en/latest/page/#Page.insertText" rel="nofollow">PyMuPDF</a>. I've inserted text with the module before but not rotated text. There is a rotate parameter in the insertText method so hopefully it will work for you.

It can be done as follows:

import fitz doc = fitz.open(filename) page = doc[0] point = fitz.Point(x, y) # in PDF units (1 / 72 of an inch) page.insertText( point, text="Hello World", fontsize=8, fontname="Helvetica", # Use a PDF Base 14 Fonts, else check documentation color=(0, 0, 0), rotate=90 ) doc.save(filename, incremental=True) doc.close()

Recommend

  • NSArray and NSString
  • Insert text at cursor position failing on blank lines
  • Example from three.js but how to implement using SceneKit?
  • How to check whether an image is captured in portrait mode or landscape mode using camera in android
  • DJ3S - Graticule removed when rotation is done in orthographic projection
  • 2D opengl rotation causes sprite distortion
  • What does getters & setters method do in Java, how are they different from normal methods, and w
  • Hexagonal pattern with CSS
  • React Native: Native Android UI component with JWPlayer shows no video image
  • How can I rotate a UIViewController to its supported interface orientation when navigating to it?
  • Which way to go with graphic-intense multi-touch app, XNA or WPF?
  • Does sql server minds the way records where inserted?
  • Linux command line : edit hacked index files
  • segue from landscape only to portrait only
  • import scipy.sparse failed
  • Updating both a ConcurrentHashMap and an AtomicInteger safely
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Python pickle not one-to-one: different pickles give same object
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Meteor helpers not available in Angular template
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • PHP - How to update data to MySQL when click a radio button
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Join two tables and save into third-sql
  • How to handle AllServersUnavailable Exception
  • Trying to switch camera back to front but getting exception
  • Why winpcap requires both .lib and .dll to run?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Free memory of cv::Mat loaded using FileStorage API
  • using HTMLImports.whenReady not working in chrome
  • Angular 2 constructor injection vs direct access
  • Programmatically clearing map cache
  • reshape alternating columns in less time and using less memory
  • How to load view controller without button in storyboard?