1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /* 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
- * to MSVC. So building for GNU compiler will take some modification of Cmake.
- * 4.16.20 - after getting an image onto the pdf, we realized there was an error that was not getting logged/presented to us.
- * we came upon this error, by trying to run the pdfHummusTest1.exe and the pdf file was not being created (because it was still
- * open -> Windows locking files regardless of where they are open). This is the reason why we wanted to figure out if PDFHummus
- * had an error logging capability and then we had to try and figure out how to use it... to be continued for next time.
- * 19 April 2020
- * Gal's documentation for using the logging capabilitites was old, the LogConfiguration function takes 3 parameters.
- * Gal does not actually handle or log errors.
- */
- #include <stdlib.h>
- #include <iostream>
- #include "PDFWriter.h"
- #include "PDFPage.h"
- #include "PageContentContext.h"
- #include "PDFFormXObject.h"
- #include "Trace.h"
- int main(){
- PDFWriter pdfWriter;
- // PREPARE PDF DOCUMENT
- // ********************
- // set path to output directory for new pdf
- EStatusCode e = pdfWriter.StartPDF(".\\myFile.pdf",ePDFVersion13,LogConfiguration(true,true,".\\logMe"));
- TRACE_LOG("ooogaBooga");
- if (e){
- printf ("something interesting");
- }
- PDFPage* pdfPage = new PDFPage();
- // set dimensions for an A4 sized page
- pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
- PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
- // include font file
- PDFUsedFont* arialTTF = pdfWriter.GetFontForFile("C:\\Windows\\Fonts\\arial.ttf");
- // ADD CONTENT
- // ********************
- // set font color to black
- pageContentContext->k(0,0,0,1);
- // set text object
- pageContentContext->BT();
- // set font
- pageContentContext->Tf(arialTTF,1);
- // set position of text
- pageContentContext->Tm(20,0,0,20,40,822);
- // insert text into PDF
- pageContentContext->Tj("Text placed and scaled with Tm");
- // end of text
- pageContentContext->ET();
- PDFFormXObject* image = pdfWriter.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
- if (!image){
- printf ("hiiii");
- }
- pageContentContext->q();
- pageContentContext->cm(0.25,0,0,0.25,86,125);
- //pageContentContext->cm(0.4,0,0,0.4,57.5,241);
- pageContentContext->Do(pdfPage->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
- pageContentContext->Q();
- // END PAGE, WRITE PDF.
- // ********************
- pdfWriter.EndPageContentContext(pageContentContext);
- EStatusCode f = pdfWriter.WritePageAndRelease(pdfPage);
- if (f){
- printf ("something interesting");
- }
- pdfWriter.EndPDF();
- }
|