GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

Hammer Attila
Dear list,

Possible you have an ydea with following problem:
I have a little Python3 code part with uses GtkSource.View and
GtkSource.PrintCompositor to print native text file content with
Gtk.Printoperation class.
The example code is following:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
from gi.repository import Gtk, GtkSource, Gio, GLib
def begin_printing(operation, context, compositor):
     while not compositor.paginate(context):
     n_pages = compositor.get_n_pages()

def draw_page(operation, context, page_nr, compositor):
     compositor.draw_page(context, page_nr)

filename = GtkSource.File()
fileloader=, filename)
fileloader.load_async(GLib.PRIORITY_LOW, None, None, None, None, filename)
printop.connect('begin-print', begin_printing, printcompositor)
printop.connect('draw-page', draw_page, printcompositor), None)

The test.txt file is very simple, but important to keep entire content
when the printing is happening the begin_printing and draw_page code parts:
The first line have two spaces and the hungarian alma word.
After this line have 26 blank lines (this is need to keeping future).
The 28 TH line have 31 space characters, and the 32. column have an 1
This is a typical braille document similar content.

What happening when I running this example code and generating a .pdf
file document?
The logic answer is the printed file content is not changed in the PDF
file (I think this previous).
But, not this is the case.

If I my Ubuntu system running for example with pdftotext -layout
test.pdf command, the converted text file result is following:


The -layout switch tells pdftotext converter to keep original layout.

If I running pdftotext test.pdf command, the converted text file
containing following text:


Unfortunatelly I only this way possible testing printed output, because
I not see entire the screen, I using Ubuntu system with the Orca Screen

The interesting bonus thing:
If I turning on the line number printing related property before
paginate and set line numbering related property with 1, everi blank
line inserted with the printed output.

I experiencing similar working method with Gedit text editor with this
example text.

I tried debugging the begin_printing code part with the printcompositor
buffer inserted text.
The text is equals my original text file content.

I haven't got another idea to how can possible keeping the original
content when GtkSource Print compositor drawing the printed pages.

I tryed replacing GtkSource.PrintCompositor related code part with
general Cairo and Pangolayout related codes, without success.
In the Pangolayout.get_text() code returns the original content, but the
printed .pdf file dropped lot of blank lines.

Why important this?
I working a hungarian language specific application with converts from
normal documents to braille documents using with Liblouis UTDML tool.
Everithing working right, except the printing.
So, when the printing is happening, need sending the printer the
generated raw braille content without format loss from the
GTKSource.PrintCompositor buffer.

Have chance to I forgot a very simple think. I already readed lot of GTK
documentation with GtkPrintOperation printing related, but not yet
founding a solution this issue related.

I attaching the example code, the test.txt file and a generated .pdf
document with I created from the GtkPrintoperation print dialog.

Kind regards,

Attila Hammer

gtk-app-devel-list mailing list
[hidden email]

test.txt (94 bytes) Download Attachment