pdfHummusTest1.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.16.20 - after getting an image onto the pdf, we realized there was an error that was not getting logged/presented to us.
  4. * we came upon this error, by trying to run the pdfHummusTest1.exe and the pdf file was not being created (because it was still
  5. * open -> Windows locking files regardless of where they are open). This is the reason why we wanted to figure out if PDFHummus
  6. * had an error logging capability and then we had to try and figure out how to use it... to be continued for next time.
  7. */
  8. #include <stdlib.h>
  9. #include <iostream>
  10. #include "PDFWriter.h"
  11. #include "PDFPage.h"
  12. #include "PageContentContext.h"
  13. #include "PDFFormXObject.h"
  14. int main(){
  15. PDFWriter pdfWriter;
  16. // PREPARE PDF DOCUMENT
  17. // ********************
  18. LogConfiguration test = LogConfiguration::DefaultLogConfiguration();
  19. test.ShouldLog = true;
  20. test.LogFileLocation = ".\\hemph";
  21. // set path to output directory for new pdf
  22. EStatusCode e = pdfWriter.StartPDF(".\\myFile.pdf",ePDFVersion13,test);
  23. if (e){
  24. printf ("something interesting");
  25. }
  26. PDFPage* pdfPage = new PDFPage();
  27. // set dimensions for an A4 sized page
  28. pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
  29. PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
  30. // include font file
  31. PDFUsedFont* arialTTF = pdfWriter.GetFontForFile("C:\\Windows\\Fonts\\arial.ttf");
  32. // ADD CONTENT
  33. // ********************
  34. // set font color to black
  35. pageContentContext->k(0,0,0,1);
  36. // set text object
  37. pageContentContext->BT();
  38. // set font
  39. pageContentContext->Tf(arialTTF,1);
  40. // set position of text
  41. pageContentContext->Tm(20,0,0,20,40,822);
  42. // insert text into PDF
  43. pageContentContext->Tj("Text placed and scaled with Tm");
  44. // end of text
  45. pageContentContext->ET();
  46. PDFFormXObject* image = pdfWriter.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
  47. if (!image){
  48. printf ("hiiii");
  49. }
  50. pageContentContext->q();
  51. pageContentContext->cm(0.25,0,0,0.25,86,125);
  52. //pageContentContext->cm(0.4,0,0,0.4,57.5,241);
  53. pageContentContext->Do(pdfPage->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
  54. pageContentContext->Q();
  55. // END PAGE, WRITE PDF.
  56. // ********************
  57. pdfWriter.EndPageContentContext(pageContentContext);
  58. pdfWriter.WritePageAndRelease(pdfPage);
  59. pdfWriter.EndPDF();
  60. }