Paozhu logoPaozhu Docs
Documentation
DEV

Advanced modules

Build flags and basic usage for PDF, Office, ZIP, email, SMS, payment and chart modules.

Build flags

terminalbash
cmake .. -DCMAKE_BUILD_TYPE=Release \
  -DENABLE_PDF=ON -DENABLE_OFFICE=ON -DENABLE_ZIP=ON \
  -DENABLE_SMS=ON -DENABLE_WEBPAY=ON -DENABLE_CHART=ON
make -j8

All modules are off by default. ENABLE_OFFICE automatically enables ENABLE_ZIP.

PDF

controller/src/test_webpdf.cppcpp
#include "webpdf/webpdf.h"
pz::webpdf pdf;
pdf.AddPage();
pdf.AddFont("msyh.ttc", "msyh");
pdf.SetFont("msyh", 12);
pdf.WriteHTML("<h1>Paozhu PDF</h1><p>Hello from C++.</p>");
pdf.Output("F", "./temp/report.pdf");

Office / ZIP

pz::excel, pz::word and pz::zip provide read/write, cell operations and archive handling. setCellColor now means cell background color.

Email and SMS

controller/src/test_email.cppcpp
email::send_email mail;
mail.smpturl = "smtp.example.com";
mail.isssl = true;
mail.port = 465;
mail.username = "no-reply@example.com";
mail.password = "secret";
mail.send();

SMS uses sms::send_sms("aliyun").send(). The email field smpturl is spelled that way in the source.

Payment, WeChat and charts

Alipay uses pay::alipay. WeChat Pay V2 uses MD5/XML and V3 uses SHA256-RSA2048/JSON. pzcharts provides 17 Svg*Chart classes with a common render(). Never hardcode secrets.

QR Code generation

Paozhu bundles a QR-Code generator built on top of qrencode and the bundled PNG encoder. Two CMake flags must be enabled together: ENABLE_GD pulls in the GD graphics stack and qrencode, while ENABLE_IMAGE enables the PNG image class used to render the final QR matrix.

Build flags & system dependencies

terminalbash
# macOS
brew install qrencode

# Debian / Ubuntu
sudo apt install libqrencode-dev

# Windows (vcpkg)
vcpkg install qrencode

# Then build with both flags ON
cmake .. -DCMAKE_BUILD_TYPE=Release \
  -DENABLE_GD=ON -DENABLE_IMAGE=ON
make -j8

Basic usage

Construct a qr::qrcode, call .text(content, ecc, version) to encode, then hand over the raw matrix (q.data, q.width(), q.height()) to image::png::qrdata(). Finally save the PNG to your www/upload directory.

controller/src/testqrcode.cppcpp
#ifdef ENABLE_IMAGE
#include "qrcode.h"
#include "pzpng.h"
#endif

//@urlpath(null, testqrcode)
std::string testqrcode(std::shared_ptr<httppeer> peer)
{
    httppeer &client = peer->get_peer();
    std::string atxt = client.post["qrcontent"].to_string();
    if (atxt.empty()) atxt = "hello paozhu";

#ifdef ENABLE_IMAGE
    qr::qrcode q;
    q.text(atxt, qr::Ecc::M, 1);       // content, error-correction, version hint

    image::png img;
    unsigned char scale = 10;
    unsigned int border = 20;
    img.create(q.width()*scale + border*2,
               q.height()*scale + border*2, 6, 8);
    img.fillColor({255, 255, 255, 255});
    img.qrdata(q.data, q.width(), q.height(), scale, border, border);

    std::string upload = client.get_sitepath();
    upload += "/upload/test.png";
    img.save(upload);

    client << "<img src=\"/upload/test.png\">";
#endif
    return "";
}

API reference

APIDescription
qr::qrcode q;Construct an empty QR encoder (header: qrcode.h)
q.text(content, ecc, version)Encode string; ecc is qr::Ecc::L/M/Q/H, version = 1–40 (0 = auto)
q.dataRaw black/white matrix (vector<unsigned char>)
q.width(), q.height()QR matrix dimensions after encoding
q.versionActual QR version used (auto-picked when you pass 0)
image::png img;Bundled PNG writer (header: pzpng.h)
img.create(w, h, color_type, bit_depth)Create a blank canvas
img.fillColor({r,g,b,a})Background fill (white {255,255,255,255})
img.qrdata(q.data, q.w(), q.h(), scale, ox, oy)Draw the QR matrix onto the canvas
img.save(path)Write PNG to disk