1
1

pdfHummusTest1.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Found that previous library was complied with the MSVC compiler and not compatible with GNU toolchain. Tried to use Msys with PDFHummus Cmake build tools and it was hard-coded
  2. * to MSVC. So building for GNU compiler will take some modification of Cmake.
  3. *
  4. */
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include "PDFWriter.h"
  8. #include "PDFPage.h"
  9. #include "PageContentContext.h"
  10. #include "PDFFormXObject.h"
  11. int main(){
  12. PDFWriter pdfWriter;
  13. // PREPARE PDF DOCUMENT
  14. // ********************
  15. // set path to output directory for new pdf
  16. pdfWriter.StartPDF(".\\myFile.pdf",ePDFVersion13);
  17. PDFPage* pdfPage = new PDFPage();
  18. // set dimensions for an A4 sized page
  19. pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
  20. PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
  21. // include font file
  22. PDFUsedFont* arialTTF = pdfWriter.GetFontForFile("C:\\Windows\\Fonts\\arial.ttf");
  23. // ADD CONTENT
  24. // ********************
  25. // set font color to black
  26. pageContentContext->k(0,0,0,1);
  27. // set text object
  28. pageContentContext->BT();
  29. // set font
  30. pageContentContext->Tf(arialTTF,1);
  31. // set position of text
  32. pageContentContext->Tm(20,0,0,20,40,822);
  33. // insert text into PDF
  34. pageContentContext->Tj("Text placed and scaled with Tm");
  35. // end of text
  36. pageContentContext->ET();
  37. PDFFormXObject* image = pdfWriter.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
  38. pageContentContext->q();
  39. pageContentContext->cm(0.4,0,0,0.4,57.5,241);
  40. pageContentContext->Do(
  41. pdfPage->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
  42. pageContentContext->Q();
  43. // END PAGE, WRITE PDF.
  44. // ********************
  45. pdfWriter.EndPageContentContext(pageContentContext);
  46. pdfWriter.WritePageAndRelease(pdfPage);
  47. pdfWriter.EndPDF();
  48. }