Make Text
This example shows how to generate a simple text PDF with rix.pdf.make_text.
The example uses the public Rix facade:
#include <rix.hpp>and accesses PDF through:
rix.pdfUse this example when you only need a quick PDF with a title and plain text content.
Create the file
mkdir -p ~/rix-pdf-make-text-example
cd ~/rix-pdf-make-text-example
touch make_text.cppAdd:
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"rix_pdf_make_text.pdf",
"This file was generated with the high-level rix.pdf.make_text helper.",
"Rix PDF");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}
rix.debug.print("created:", "rix_pdf_make_text.pdf");
return 0;
}Run it:
vix run make_text.cppIf Rix is not available yet for single-file usage:
vix install -g rix/rix
vix run make_text.cppThis creates:
rix_pdf_make_text.pdfWhat this example does
The example calls:
rix.pdf.make_text(...)make_text creates a document, adds a page, writes the title and text content, and saves the PDF file.
It is the shortest PDF workflow in rix/pdf.
Function shape
Use:
auto saved = rix.pdf.make_text(
"output.pdf",
"Text content",
"Optional title");The arguments are:
output file path
text content
optional titleThe result is a PDF status.
Save path
The first argument is the output file path:
"rix_pdf_make_text.pdf"The path must not be empty.
If the file is inside a folder, the folder must already exist.
Example:
mkdir -p outputThen:
auto saved = rix.pdf.make_text(
"output/hello.pdf",
"Hello from rix.pdf",
"Rix PDF");Text content
The second argument is the content written inside the PDF:
"This file was generated with the high-level rix.pdf.make_text helper."Use it for short plain-text content.
For complex layout, use rix.pdf.document() instead.
Optional title
The third argument is optional:
"Rix PDF"When provided, it is used as the document title and visible heading.
You can also call make_text without a title:
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello from rix.pdf");Check errors
make_text returns a status.
Always check it:
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}On success:
rix.debug.print("created:", "rix_pdf_make_text.pdf");Complete minimal example
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello from rix.pdf",
"Rix PDF");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}
rix.debug.print("created:", "hello.pdf");
return 0;
}Run:
vix run make_text.cppWithout a title
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"plain.pdf",
"This PDF has text content without a visible title.");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}
rix.debug.print("created:", "plain.pdf");
return 0;
}Run:
vix run make_text.cppWith a title
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"with-title.pdf",
"This PDF includes a title and body text.",
"Generated Text PDF");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}
rix.debug.print("created:", "with-title.pdf");
return 0;
}The title is used for metadata and visible content.
When to use make_text
Use make_text when you need:
a quick text-only PDF
a small generated note
a simple export
a small report summary
a minimal exampleIt is useful when the document does not need custom layout.
When not to use make_text
Use rix.pdf.document() when you need:
multiple pages
tables
drawings
images
custom metadata
custom text styles
manual positioning
several sectionsExample:
auto doc = rix.pdf.document();
auto &page = doc.add_page();
page.heading(
page.x_left(),
page.y_top(),
"Custom PDF",
1);
auto saved = rix.pdf.save(doc, "custom.pdf");make_text vs document
make_text is short:
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello from rix.pdf",
"Rix PDF");document gives more control:
auto doc = rix.pdf.document();
doc.set_title("Rix PDF");
auto &page = doc.add_page();
page.heading(
page.x_left(),
page.y_top(),
"Rix PDF",
1);
page.paragraph(
page.x_left(),
page.y_top() - 50.0F,
page.content_width(),
"Hello from rix.pdf");
auto saved = rix.pdf.save(doc, "hello.pdf");Choose make_text for speed.
Choose document for layout control.
Error example
An empty path fails:
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"",
"This should fail.",
"Invalid path");
if (saved.failed())
{
rix.debug.eprint(
"expected pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 0;
}
return 1;
}Run:
vix run make_text.cppThe failure is expected because the output path is empty.
Missing folder example
This can fail if output/ does not exist:
auto saved = rix.pdf.make_text(
"output/hello.pdf",
"Hello from rix.pdf",
"Rix PDF");Create the folder first:
mkdir -p outputThen run again.
Use in a Vix project
Create a project:
vix new rix-pdf-make-text --app
cd rix-pdf-make-textAdd Rix:
vix add rix/rix
vix installMake sure vix.app contains:
deps = [
"rix/rix",
]A minimal vix.app can look like this:
name = "rix-pdf-make-text"
type = "executable"
standard = "c++20"
output_dir = "bin"
sources = [
"src/main.cpp",
]
include_dirs = [
"include",
"src",
]
deps = [
"rix/rix",
]
packages = [
"vix",
]
links = [
"vix::vix",
]Put the example code in:
src/main.cppBuild and run:
vix build
vix runSingle-file usage
For examples, tests, and quick experiments:
vix run make_text.cppIf needed:
vix install -g rix/rix
vix run make_text.cppFor project usage, prefer:
vix add rix/rix
vix installand keep the dependency in vix.app:
deps = [
"rix/rix",
]Use only PDF with the facade
If you want the rix.* facade style but only want PDF mounted, define the feature macro before including rix.hpp:
#define RIX_ENABLE_PDF
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello from rix.pdf",
"Rix PDF");
return saved.ok() ? 0 : 1;
}When at least one RIX_ENABLE_* macro is defined, only selected modules are mounted.
If you also want debug output:
#define RIX_ENABLE_PDF
#define RIX_ENABLE_DEBUG
#include <rix.hpp>
int main()
{
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello from rix.pdf",
"Rix PDF");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}
rix.debug.print("created:", "hello.pdf");
return 0;
}Use the independent package
For independent usage, install:
vix add rix/pdf
vix installIn vix.app:
deps = [
"rix/pdf",
]Then include:
#include <rix/pdf.hpp>Example:
#include <rix/pdf.hpp>
int main()
{
auto pdf = rixlib::pdf::module();
auto saved = pdf.make_text(
"hello.pdf",
"Hello from rix/pdf",
"Rix PDF");
return saved.ok() ? 0 : 1;
}The examples in this documentation prefer the public facade:
#include <rix.hpp>and:
rix.pdfCommon mistakes
Forgetting to install Rix
If rix.hpp is not found, install Rix first.
For a project:
vix add rix/rix
vix installFor single-file usage:
vix install -g rix/rixPutting Rix in packages
Wrong:
packages = [
"rix/rix",
]Correct:
deps = [
"rix/rix",
]deps is for Vix Registry packages.
packages is for CMake package discovery.
Using make_text for complex layout
make_text is for simple text PDFs.
For layout, tables, drawings, or custom styles, use:
auto doc = rix.pdf.document();Saving to an empty path
This fails:
rix.pdf.make_text(
"",
"Hello",
"Rix PDF");Use a real path:
rix.pdf.make_text(
"hello.pdf",
"Hello",
"Rix PDF");Saving to a missing folder
This can fail:
rix.pdf.make_text(
"output/hello.pdf",
"Hello",
"Rix PDF");Create the folder first:
mkdir -p outputNot checking save errors
Wrong:
rix.pdf.make_text(
"hello.pdf",
"Hello",
"Rix PDF");Correct:
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello",
"Rix PDF");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}What you should remember
Use make_text for a simple text PDF:
auto saved = rix.pdf.make_text(
"hello.pdf",
"Hello from rix.pdf",
"Rix PDF");Check errors:
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
}Use document() for custom layout:
auto doc = rix.pdf.document();For project usage:
vix add rix/rix
vix installand keep:
deps = [
"rix/rix",
]Next step
Continue with PDF error handling.
Next: Error handling