pdfHummusTest1.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * 19 April 2020
  8. * Gal's documentation for using the logging capabilitites was old, the LogConfiguration function takes 3 parameters.
  9. * Gal does not actually handle or log errors.
  10. */
  11. #include <stdlib.h>
  12. #include <iostream>
  13. #include "PDFWriter.h"
  14. #include "PDFPage.h"
  15. #include "PageContentContext.h"
  16. #include "PDFFormXObject.h"
  17. #include "Trace.h"
  18. int main(){
  19. PDFWriter pdfWriter;
  20. // PREPARE PDF DOCUMENT
  21. // ********************
  22. // set path to output directory for new pdf
  23. EStatusCode e = pdfWriter.StartPDF(".\\myFile.pdf",ePDFVersion13,LogConfiguration(true,true,".\\logMe"));
  24. TRACE_LOG("ooogaBooga");
  25. if (e){
  26. printf ("something interesting");
  27. }
  28. PDFPage* pdfPage = new PDFPage();
  29. // set dimensions for an A4 sized page
  30. pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
  31. PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
  32. // include font file
  33. PDFUsedFont* arialTTF = pdfWriter.GetFontForFile("C:\\Windows\\Fonts\\arial.ttf");
  34. // ADD CONTENT
  35. // ********************
  36. // set font color to black
  37. pageContentContext->k(0,0,0,1);
  38. // set text object
  39. pageContentContext->BT();
  40. // set font
  41. pageContentContext->Tf(arialTTF,1);
  42. // set position of text
  43. pageContentContext->Tm(20,0,0,20,40,822);
  44. // insert text into PDF
  45. pageContentContext->Tj("Text placed and scaled with Tm");
  46. // end of text
  47. pageContentContext->ET();
  48. PDFFormXObject* image = pdfWriter.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
  49. if (!image){
  50. printf ("hiiii");
  51. }
  52. pageContentContext->q();
  53. pageContentContext->cm(0.25,0,0,0.25,86,125);
  54. //pageContentContext->cm(0.4,0,0,0.4,57.5,241);
  55. pageContentContext->Do(pdfPage->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
  56. pageContentContext->Q();
  57. // END PAGE, WRITE PDF.
  58. // ********************
  59. pdfWriter.EndPageContentContext(pageContentContext);
  60. EStatusCode f = pdfWriter.WritePageAndRelease(pdfPage);
  61. if (f){
  62. printf ("something interesting");
  63. }
  64. pdfWriter.EndPDF();
  65. }