Getting Started
Paperback uses the build2 build system, see https://build2.org/.
The first step is to include Paperback in your build2 project.
Add the following lines to your repositories.manifest file:
:
role: prerequisite
location: https://code.helloryan.se/art/libart-paperback.git##HEAD
And the following to your manifest file:
depends: libart-paperback ^0.1.0-
Finally, link your executable or library with Paperback:
import libs =+ libart-paperback%lib{art-paperback}
Usage Example
The example below shows how to use Paperback to create a new PDF document and render some text on a page. More examples are available in $src_root$/examples.
#include <fstream>
#include <iostream>
#include <art/paperback/document.hxx>
#include <art/paperback/page.hxx>
#include <art/paperback/graphics/canvas.hxx>
#include <art/paperback/graphics/standard-font.hxx>
using namespace std;
int
main(int argc, char* argv[])
{
if (argc != 2) {
cerr << "usage: " << argv[0] << " <path>\n";
return 1;
}
try {
fstream fs{argv[1], std::ios_base::out | std::ios_base::binary};
double width = 595;
double height = 842;
});
{
auto tw = helvetica.get_text_width("Hello, world!");
auto text_width = (tw.width * 14) / 1000;
auto capheight = (helvetica.get_capheight() * 14) / 1000;
double cx = (width / 2) - (text_width / 2);
double cy = (height / 2) - (capheight / 2);
bt.move_text_pos(cx, cy);
bt.show_text("Hello, world!");
}
}
catch (exception const& ex) {
cerr << argv[0] << ": an error occurred: " << ex.what() << "\n";
return 1;
}
catch (...) {
cerr << argv[0] << ": an unknown error occurred\n";
return 1;
}
return 0;
}
Definition document.hxx:12
static constexpr Create_new const create_new
Tag used to indicate the creation of a new document.
Definition document.hxx:18
Definition canvas.hxx:210
Definition canvas.hxx:245
Represents the drawable canvas of a page.
Definition canvas.hxx:15
static constexpr Clear const clear
Dispatch-tag used to clear a canvas.
Definition canvas.hxx:21
Represents a standard PDF font.
Definition standard-font.hxx:16
Represents a PDF rectangle.
Definition primitives.hxx:27
Graphics namespace.
Definition forward.hxx:105
Primary paperback namespace.
Definition array.cxx:6
Document & document(Page &page)
Get the document associated with a page.
Definition page.cxx:120
Properties of a new page.
Definition page.hxx:20