1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /* 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.
- *
- */
- #include <stdlib.h>
- #include <iostream>
- #include "PDFWriter.h"
- #include "PDFPage.h"
- #include "PageContentContext.h"
- #include "PDFFormXObject.h"
- int main(){
- PDFWriter pdfWriter;
- // PREPARE PDF DOCUMENT
- // ********************
- // set path to output directory for new pdf
- pdfWriter.StartPDF(".\\myFile.pdf",ePDFVersion13);
- 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");
- pageContentContext->q();
- 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);
- pdfWriter.WritePageAndRelease(pdfPage);
- pdfWriter.EndPDF();
- }
|