Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <podofo/podofo.h>
- using namespace PoDoFo;
- void addText(const std::string &family, double pos, PdfStreamedDocument &doc, PdfPainter &painter, PdfPage* pPage)
- {
- bool bold = false;
- bool italic = false;
- bool underline = false;
- int tracking = 0;
- float pointSize = 10.0f;
- const PdfEncoding *encoding = PdfEncodingFactory::GlobalIdentityEncodingInstance();
- // const PdfEncoding *encoding = PdfEncodingFactory::GlobalMacRomanEncodingInstance();
- PdfFont *pFont = doc.CreateFont(family.c_str(),
- bold, italic, false, encoding,
- PdfFontCache::eFontCreationFlags_None, true);
- // PdfFont *pFont = doc.CreateFontSubset(family.c_str(), bold, italic, false, encoding);
- if (!pFont)
- {
- std::cout << "No Font!" << std::endl;
- return;
- }
- pFont->SetFontSize(pointSize);
- pFont->SetFontCharSpace(tracking / 10.0f);
- pFont->SetUnderlined(underline);
- painter.SetFont(pFont);
- PdfString pdfText;
- const std::string text{"Some normal text фівїй"};
- pdfText = PdfString(reinterpret_cast<const PoDoFo::pdf_utf8*>(text.c_str()));
- painter.DrawText(20, pPage->GetPageSize().GetHeight() - pos, pdfText);
- }
- int main()
- {
- PdfStreamedDocument document("PODOFO_RESULT.pdf");
- PdfPainter painter;
- PdfPage* pPage = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
- if (!pPage)
- {
- std::cout << "No Page!" << std::endl;
- return -1;
- }
- painter.SetPage(pPage);
- // TTFs
- addText("Arial", 50, document, painter, pPage);
- addText("Chalkduster", 60, document, painter, pPage);
- addText("Ayuthaya", 70, document, painter, pPage);
- addText("AppleGothic", 80, document, painter, pPage);
- addText("BigCaslon", 90, document, painter, pPage);
- addText("Courier New", 100, document, painter, pPage);
- addText("Bradley Hand", 110, document, painter, pPage);
- addText("Georgia", 120, document, painter, pPage);
- addText("Farisi", 130, document, painter, pPage);
- addText("Herculanum", 140, document, painter, pPage);
- addText("Impact", 150, document, painter, pPage);
- painter.FinishPage();
- document.Close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment