Guest User

Untitled

a guest
Feb 25th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <podofo/podofo.h>
  3.  
  4. using namespace PoDoFo;
  5.  
  6. void addText(const std::string &family, double pos, PdfStreamedDocument &doc, PdfPainter &painter, PdfPage* pPage)
  7. {
  8.     bool bold = false;
  9.     bool italic = false;
  10.     bool underline = false;
  11.     int tracking = 0;
  12.     float pointSize = 10.0f;
  13.     const PdfEncoding *encoding = PdfEncodingFactory::GlobalIdentityEncodingInstance();
  14. //    const PdfEncoding *encoding = PdfEncodingFactory::GlobalMacRomanEncodingInstance();
  15.     PdfFont *pFont = doc.CreateFont(family.c_str(),
  16.                                     bold, italic, false, encoding,
  17.                                     PdfFontCache::eFontCreationFlags_None, true);
  18. //    PdfFont *pFont = doc.CreateFontSubset(family.c_str(), bold, italic, false, encoding);
  19.     if (!pFont)
  20.     {
  21.         std::cout << "No Font!" << std::endl;
  22.         return;
  23.     }
  24.     pFont->SetFontSize(pointSize);
  25.     pFont->SetFontCharSpace(tracking / 10.0f);
  26.     pFont->SetUnderlined(underline);
  27.  
  28.     painter.SetFont(pFont);
  29.     PdfString pdfText;
  30.     const std::string text{"Some normal text фівїй"};
  31.     pdfText = PdfString(reinterpret_cast<const PoDoFo::pdf_utf8*>(text.c_str()));
  32.  
  33.     painter.DrawText(20, pPage->GetPageSize().GetHeight() - pos, pdfText);
  34. }
  35.  
  36. int main()
  37. {
  38.     PdfStreamedDocument document("PODOFO_RESULT.pdf");
  39.     PdfPainter painter;
  40.     PdfPage* pPage = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
  41.     if (!pPage)
  42.     {
  43.         std::cout << "No Page!" << std::endl;
  44.         return -1;
  45.     }
  46.  
  47.     painter.SetPage(pPage);
  48.     // TTFs
  49.     addText("Arial", 50, document, painter, pPage);
  50.     addText("Chalkduster", 60, document, painter, pPage);
  51.     addText("Ayuthaya", 70, document, painter, pPage);
  52.     addText("AppleGothic", 80, document, painter, pPage);
  53.     addText("BigCaslon", 90, document, painter, pPage);
  54.     addText("Courier New", 100, document, painter, pPage);
  55.     addText("Bradley Hand", 110, document, painter, pPage);
  56.     addText("Georgia", 120, document, painter, pPage);
  57.     addText("Farisi", 130, document, painter, pPage);
  58.     addText("Herculanum", 140, document, painter, pPage);
  59.     addText("Impact", 150, document, painter, pPage);
  60.  
  61.     painter.FinishPage();
  62.  
  63.     document.Close();
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment