Browse Source

made some changes to Makefile to compile BasicImageAndText & PauseAndContinue.
using pauseAndContinue to compare pdfHummusTest1 to see how pause and continue works.
check ToDo for more notes.

wes 4 years ago
parent
commit
20ae0bcb10
5 changed files with 240 additions and 18 deletions
  1. 87 0
      BasicImageAndText.cpp
  2. 2 2
      Makefile
  3. 119 0
      PauseAndContinue.cpp
  4. 4 3
      ToDo/ToDo.txt
  5. 28 13
      pdfHummusTest1.cpp

+ 87 - 0
BasicImageAndText.cpp

@@ -0,0 +1,87 @@
+// standard library includes
+#include <iostream>
+#include <string>
+using namespace std;
+// end standard library includes
+
+// pdfwriter library includes
+#include "PDFWriter.h"
+#include "PDFPage.h"
+#include "PageContentContext.h"
+#include "PDFFormXObject.h"
+#include "ResourcesDictionary.h"
+// end pdfwriter library includes
+
+using namespace PDFHummus;
+
+int main(int argc, char* argv[])
+{
+	PDFWriter pdfWriter;
+	EStatusCode status;
+
+	do
+	{
+		status = pdfWriter.StartPDF(".\\BasicImageAndText.pdf",ePDFVersion13);
+		if(status != eSuccess)
+			break;
+
+		// Create a new page
+		PDFPage* pdfPage = new PDFPage();
+		pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
+
+		// Create an image object from image
+		PDFFormXObject* image = pdfWriter.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
+		if(!image)
+		{
+			status = eFailure;
+			break;
+		}
+
+		// Create a content context for the page
+		PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
+
+		// Place the image in the center of the page
+		pageContentContext->q();
+		pageContentContext->cm(0.4,0,0,0.4,57.5,241);
+		pageContentContext->Do(pdfPage->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
+		pageContentContext->Q();
+
+		// Image object can be deleted right after i was used
+		delete image;
+
+
+		// Create a title text over the image
+		PDFUsedFont* arialTTF = pdfWriter.GetFontForFile("C:\\Windows\\Fonts\\arial.ttf");
+		if(!arialTTF)
+		{
+			status = eFailure;
+			break;
+		}
+
+		pageContentContext->BT();
+		pageContentContext->k(0,0,0,1);
+		pageContentContext->Tf(arialTTF,20);
+		pageContentContext->Tm(1,0,0,1,90,610);
+		pageContentContext->Tj("San Antonio Pass, Cordillera Huayhuash, Peru");
+		pageContentContext->ET();				
+
+		// End content context, and write the page
+		status = pdfWriter.EndPageContentContext(pageContentContext);
+		if(status != eSuccess)
+			break;
+
+		status = pdfWriter.WritePageAndRelease(pdfPage);
+		if(status != eSuccess)
+			break;
+
+		status = pdfWriter.EndPDF();
+	}while(false);
+
+	if(eSuccess == status)
+		cout<<"Succeeded in creating PDF file\n";
+	else
+		cout<<"Failed in creating PDF file\n";
+
+	return 0;
+}
+

+ 2 - 2
Makefile

@@ -32,5 +32,5 @@ libharuEXMP.exe : libharuEXMP.cpp libharuEXMP/libpng16.dll libharuEXMP/libhpdf.d
 	copy $(ow)\bin\$(@F) "$(@D)\"
 cleanPDFtest.exe : cleanPDFtest.cpp cleanPDFtest/libpng16.dll cleanPDFtest/libhpdf.dll
 	g++ $< -L $(ow)/lib/  -I $(ow)/include/ -lhpdf -o $(basename $@)/$@
-pdfHummusTest1.exe : pdfHummusTest1.cpp
-	g++ -I C:/Users/bad-p/Downloads/PDFHummus-build/PDFWriter/include $< -L C:/Users/bad-p/Downloads/PDFHummus-build/PDFWriter/objs -lall -o $(basename $@)/$@
+BasicImageAndText.exe pdfHummusTest1.exe PauseAndContinue.exe :  
+	g++ -I C:/Users/bad-p/Downloads/PDFHummus-build/PDFWriter/include $(@:.exe=.cpp) -L C:/Users/bad-p/Downloads/PDFHummus-build/PDFWriter/objs -lall -o $(basename $@)/$@

+ 119 - 0
PauseAndContinue.cpp

@@ -0,0 +1,119 @@
+// standard library includes
+#include <iostream>
+#include <string>
+using namespace std;
+// end standard library includes
+
+// pdfwriter library includes
+#include "PDFWriter.h"
+#include "PDFPage.h"
+#include "PageContentContext.h"
+
+using namespace PDFHummus;
+
+static const string scBasePath =  "";
+static const string scSystemFontsPath = "C:\\windows\\fonts\\";
+
+int main(int argc, wchar_t* argv[])
+{
+	EStatusCode status;
+
+	do
+	{
+
+		{
+			PDFWriter pdfWriterA;
+			
+			status = pdfWriterA.StartPDF(scBasePath + "PauseAndContinue.pdf",ePDFVersion13);
+			if(status != eSuccess)
+				break;
+
+			// Create a new page
+			PDFPage* pdfPage = new PDFPage();
+			pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
+
+			// Create a content context for the page
+			PageContentContext* pageContentContext = pdfWriterA.StartPageContentContext(pdfPage);
+
+			PDFUsedFont* arialTTF = pdfWriterA.GetFontForFile(scSystemFontsPath + "arial.ttf");
+			if(!arialTTF)
+			{
+				status = eFailure;
+				break;
+			}
+
+			pageContentContext->k(0,0,0,1);
+
+			pageContentContext->BT();
+			pageContentContext->Tf(arialTTF,1);
+			pageContentContext->Tm(20,0,0,20,40,822);
+			pageContentContext->Tj("Hello World");
+			pageContentContext->ET();				
+
+			// End content context, and write the page
+			status = pdfWriterA.EndPageContentContext(pageContentContext);
+			if(status != eSuccess)
+				break;
+
+			status = pdfWriterA.WritePageAndRelease(pdfPage);
+			if(status != eSuccess)
+				break;
+
+			status = pdfWriterA.Shutdown(scBasePath + "PauseAndContinueTest.txt");
+			if(status != eSuccess)
+				break;
+		}
+		
+
+		{
+			PDFWriter pdfWriterB;
+			
+			status = pdfWriterB.ContinuePDF(scBasePath + "PauseAndContinue.pdf",scBasePath + "PauseAndContinueTest.txt");
+			if(status != eSuccess)
+				break;
+
+			// Create a new page
+			PDFPage* pdfPage = new PDFPage();
+			pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
+
+			// Create a content context for the page
+			PageContentContext* pageContentContext = pdfWriterB.StartPageContentContext(pdfPage);
+
+			PDFUsedFont* arialTTF = pdfWriterB.GetFontForFile(scSystemFontsPath + "arial.ttf");
+			if(!arialTTF)
+			{
+				status = eFailure;
+				break;
+			}
+
+			pageContentContext->k(0,0,0,1);
+
+			pageContentContext->BT();
+			pageContentContext->Tf(arialTTF,1);
+			pageContentContext->Tm(20,0,0,20,40,822);
+			pageContentContext->Tj("Hello Again, World");
+			pageContentContext->ET();				
+
+			// End content context, and write the page
+			status = pdfWriterB.EndPageContentContext(pageContentContext);
+			if(status != eSuccess)
+				break;
+
+			status = pdfWriterB.WritePageAndRelease(pdfPage);
+			if(status != eSuccess)
+				break;
+
+			status = pdfWriterB.EndPDF();
+			if(status != eSuccess)
+				break;
+		}
+
+	}while(false);
+		
+	if(eSuccess == status)
+		cout<<"Succeeded in creating PauseAndContinue.PDF file\n";
+	else
+		cout<<"Failed in creating PauseAndContinue.PDF file\n";
+		
+	return 0;
+}

+ 4 - 3
ToDo/ToDo.txt

@@ -5,6 +5,7 @@
 19April20
 Successfully created a log file for errors using Gal's LogConfiguration structure. We are not sure what errors he actually keeps track of so we have to hunt for errors to log.
 
-25April20
-Unsure if we can have both text and a picture on the same page for the PDFWriter. Need to possibly create a second page, one with text on it, then one with the picture on it.
-Third page we could try and create it with both. This may have something to do with how pageContentContext works??? Anyways, the image is working now and the text is commented out.
+28April20
+Got image and text to work - but image resource has to be added before adding to pagecontext. there is a committed version of this from today. 
+We are now need to figure out how start and continue works. In Gal's example it creates 2 separate pages. In our example it is now creating one page with only the image on it, no text.
+The text could be getting overwritten. or??? will continue next time.

+ 28 - 13
pdfHummusTest1.cpp

@@ -43,18 +43,11 @@ int main(){
     PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(pdfPage);
     //  include font file
     PDFUsedFont* arialTTF = pdfWriter.GetFontForFile("C:\\Windows\\Fonts\\arial.ttf");
+    //  include image file
+    
     //  ADD CONTENT 
     //  ********************
-    PDFFormXObject* image = pdfWriter.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
-    if (!image){
-        printf ("hiiii");
-    }
-    pageContentContext->q();
-    pageContentContext->cm(1,0,0,1,0,0);
-    //pageContentContext->cm(0.4,0,0,0.4,57.5,241);
-    pageContentContext->Do(pdfPage->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
-    pageContentContext->Q();
-    delete image;
+    
     //  set font color to black
     pageContentContext->k(0,0,0,1);
     //  set text object
@@ -67,13 +60,35 @@ int main(){
     pageContentContext->Tj("Text placed and scaled with Tm");
     //  end of text
     pageContentContext->ET();
+    pdfWriter.EndPageContentContext(pageContentContext);
+    pdfWriter.WritePageAndRelease(pdfPage);
+    // ****************Shutdown Usage************
+    // ******************************************
+    // ******************************************
+    pdfWriter.Shutdown("c:\\myFile.pdf.shutdown");
+    PDFWriter pdfWriterB;
+    pdfWriterB.ContinuePDF("c:\\myFile.pdf","myFile.pdf.shutdown","",LogConfiguration(true,true,".\\logMe"));
+    PDFPage* pdfPageB = new PDFPage();
+    //  set dimensions for an A4 sized page
+    pdfPageB->SetMediaBox(PDFRectangle(0,0,595,842));
+    PageContentContext* pageContentContextB = pdfWriterB.StartPageContentContext(pdfPageB);
+    PDFFormXObject* image = pdfWriterB.CreateFormXObjectFromJPGFile("C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg");
+    if (!image){
+        TRACE_LOG("Image file not found, creating PDF without image.");
+        printf("The image \"C:\\Users\\bad-p\\Desktop\\Work Folder\\VS CODE\\SanAntonioPass.jpg\" was not found.");
+    }
+    pageContentContextB->q();
+    pageContentContextB->cm(0.4,0,0,0.4,57.5,241);
+    pageContentContextB->Do(pdfPageB->GetResourcesDictionary().AddFormXObjectMapping(image->GetObjectID()));
+    pageContentContextB->Q();
+    delete image;
     //  END PAGE, WRITE PDF.
     //  ******************** 
-    pdfWriter.EndPageContentContext(pageContentContext);
-    EStatusCode f = pdfWriter.WritePageAndRelease(pdfPage);
+    pdfWriterB.EndPageContentContext(pageContentContextB);
+    EStatusCode f = pdfWriterB.WritePageAndRelease(pdfPageB);
     if (f){
         printf ("something interesting");
     }
-    pdfWriter.EndPDF();
+    pdfWriterB.EndPDF();
 
 }