View Source Mudbrick.Predicates (mudbrick v0.8.0)

Useful for testing PDF documents.

While these predicates do check the PDF in a black-box way, it's not expected that they will work on PDFs not generated with Mudbrick.

Summary

Functions

Checks for presence of text in the pdf iodata. Searches compressed and uncompressed data.

Checks for presence of text in the pdf iodata. Searches compressed and uncompressed data.

Functions

@spec has_text?(pdf :: iodata(), text :: binary()) :: boolean()

Checks for presence of text in the pdf iodata. Searches compressed and uncompressed data.

This arity only works with text that can be found in literal form inside a stream, compressed or uncompressed,

Link to this function

has_text?(pdf, text, opts)

View Source
@spec has_text?(pdf :: iodata(), text :: binary(), opts :: list()) :: boolean()

Checks for presence of text in the pdf iodata. Searches compressed and uncompressed data.

This arity requires you to pass the raw font data in which the text is expected to be written. The text must be present in TJ operator format, which raw hexadecimal form corresponding to the font's glyph IDs, interspersed with optional kerning offsets.

The OpenType library is used to find font features, such as ligatures, which are expected to have been used in the PDF.

Options

  • :in_font - raw font data in which the text is expected. Required.

Example: with compression

iex> import Mudbrick.TestHelper
...> import Mudbrick.Predicates
...> import Mudbrick
...> font = bodoni_regular()
...> raw_pdf =
...>   new(compress: true, fonts: %{default: font})
...>   |> page()
...>   |> text(
...>     "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWhello, CO₂!WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
...>     font_size: 100
...>   )
...>   |> render()
...>   |> IO.iodata_to_binary()
...> {has_text?(raw_pdf, "hello, CO₂!", in_font: font), has_text?(raw_pdf, "good morning!", in_font: font)}
{true, false}

Example: without compression

iex> import Mudbrick.TestHelper
...> import Mudbrick.Predicates
...> import Mudbrick
...> font = bodoni_regular()
...> raw_pdf =
...>   new(compress: false, fonts: %{default: font})
...>   |> page()
...>   |> text(
...>     "Hello, world!",
...>     font_size: 100
...>   )
...>   |> render()
...>   |> IO.iodata_to_binary()
...> {has_text?(raw_pdf, "Hello, world!", in_font: font), has_text?(raw_pdf, "Good morning!", in_font: font)}
{true, false}