0

I'm new to GTK4, an open source toolkit for C++ binding. I want to send text from current TextView buffer (from a saved file) to a PDF file using GTK libraries (gtkmm4), but couldn't get anything printed out.

This is the code I have started from reading the documentation:

void MainWindow:export_note() {
  auto op = Gtk::PrintOperation::create();
  // setup op


  cout << save_file_path << endl;
  string content = editor.get_buffer()->get_text();
  ofstream out(work_dir + save_file_path);
  out << content;
  out.close();

  curr_state = edit_file;


  op->set_export_filename("test.pdf");
  auto res = op->run(Gtk::PrintOperation::Action::EXPORT);

  return;
}

This only exports to a blank PDF, but I'm expecting text to show up on PDF.

Benson
  • 1
  • 2
  • gtkmm4 is the library since the notes app is built from scratch under gtk – Benson Dec 03 '22 at 22:55
  • I don't think I have that installed. – Benson Dec 03 '22 at 22:58
  • I have a functioning notes app that every time a new note is created, the save_file function is enabled to save the current text buffer (contents of the file) into the actual file. I just need to figure out a way to send that textview content to pdf when I export, if you get what I mean. – Benson Dec 03 '22 at 23:03
  • How would I be able to send text to PDF with a binary app in gtk? – Benson Dec 03 '22 at 23:11
  • I wish I knew Postscript if I were to use it – Benson Dec 03 '22 at 23:14

1 Answers1

0

It looks like you are not using any binary application to attempt conversion from text to text/pdf or more commonly binary application/pdf. You cannot simply stuff text data into a container called Test.pdf

There are simple means to convert Text to PDF, traditionally by using PostScript Printer files, but more commonly recently using a PDF printer driver direct

so start at the most basic level Hello World needs a file something like this, where the body is built up from stacked vectors or font labelled strings at X&Y co-ordinates.

Test.pdf

%PDF-1.1
%âãÏÓ
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
2 0 obj<</Type/Pages/Kids [3 0 R]/Count 1/MediaBox [0 0 594 792]>>endobj
3 0 obj<</Type/Page/Parent 2 0 R/Resources<</Font<</F1<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>>>>>/Contents 4 0 R>>endobj
4 0 obj<</Length 81
>>
stream

BT /F1 18 Tf 036 740 Td (Hello) Tj ET
BT /F1 18 Tf 036 720 Td (World!) Tj ET

endstream 
endobj xref
0 5 
0000000000 65535 f
0000000019 00000 n
0000000063 00000 n
0000000137 00000 n
0000000267 00000 n
trailer<</Root 1 0 R /Size 5>>startxref
399 %%EOF

K J
  • 8,045
  • 3
  • 14
  • 36