Procházet zdrojové kódy

After fixing a bug, PDFHummus now generates similarly to GK example.

wes před 4 roky
rodič
revize
c8762088af
2 změnil soubory, kde provedl 75 přidání a 103 odebrání
  1. 5 9
      ToDo/ToDo.txt
  2. 70 94
      pdfHummusTest1.cpp

+ 5 - 9
ToDo/ToDo.txt

@@ -1,12 +1,8 @@
-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 now need to figure out how shutdown 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.
-
 
 
 30April20
 30April20
-1) Figure out this error message for pdfHummusTest1.exe:
-    terminate called after throwing an instance of 'std::bad_alloc'
-    what():  std::bad_alloc 
-segmentation fault was found on line 99 of the code.
 2) Debugger only seems to work if we use the -g command when compiling to include debug inside of executable. Find out if we can do this another way or if we need to 
 2) Debugger only seems to work if we use the -g command when compiling to include debug inside of executable. Find out if we can do this another way or if we need to 
-turn that on and off, manually. This may lead to another task of addding this to all other targets in the makefile. 
+turn that on and off, manually. This may lead to another task of addding this to all other targets in the makefile. 
+
+2May20
+1) Continue with PDF Hummus, get text and image to work on same page using the Shutdown & Continue function.
+2) make the text on page code into one function vs all the separate parts it is in currently.

+ 70 - 94
pdfHummusTest1.cpp

@@ -21,102 +21,78 @@
 int main(){
 int main(){
     //  Go to: "%AppData%\..\Local\VirtualStore"  - because Windows does not write to the C:\ drive  
     //  Go to: "%AppData%\..\Local\VirtualStore"  - because Windows does not write to the C:\ drive  
     printf("if running on Windows check here for file(s): %%AppData%%\\..\\Local\\VirtualStore\n");
     printf("if running on Windows check here for file(s): %%AppData%%\\..\\Local\\VirtualStore\n");
-    {
-        PDFWriter pdfWriter;
-        //  PREPARE PDF DOCUMENT
-        //  ********************
-        //  get a PDFWriter object to interact with. set the PDF version, set log file
-        EStatusCode e = pdfWriter.StartPDF("c:\\myFile.pdf",ePDFVersion13,LogConfiguration(true,true,".\\logMe"));
-        if (e){ 
-            /*  25APR20 - look through codebase and found these three reasons for nonrecoverable failure:
-            *  - user requested encryption, document doesn't support it
-            *  - it is unlikely, but for some reason GK wanted to call OutputFile::CloseFile(), it failed 
-            *  - operating system was unsuccessful at giving a lock for the filename *
-            * 
-            *  * Windows 'gives' a lock, but doesn't protect others from writing to this filename
-            */
-            printf("Terminating (c:\\myFile.pdf): unsuccessful lock or couldn't close existing or requested encryption but not supported\n");
-            TRACE_LOG("Terminating (c:\\myFile.pdf): unsuccessful lock or couldn't close existing or requested encryption but not supported");
-            exit(1);
-        }
-        TRACE_LOG("Notified OS we might use c:\\myFile.pdf");
-        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");
-        //  include image file
-        
-        //  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();
-        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.
-        //  ******************** 
-        pdfWriterB.EndPageContentContext(pageContentContextB);
-        EStatusCode f = pdfWriterB.WritePageAndRelease(pdfPageB);
-        if (f){
-            printf ("something interesting");
-        }
-        pdfWriterB.EndPDF();*/
-        if(false)for(int i = 0;0<1000000000;i++){
-            if(i*i*i<(i/3))
-            break;
-        }
-        /*
-        LPOVERLAPPED kyle;
-        //  waiting for previous wfsopen to finish from GK lib
-        while(true){
-            //  open file
-            FILE *f = fopen("C:\\Users\\bad-p\\AppData\\Local\\VirtualStore\\myFile.pdf","r");
-            //  create lock for file, after lock is created, done waiting.
-            if(LockFileEx(
-                f,                                       //  handle to file (needs to be GENERIC_READ)
-                LOCKFILE_EXCLUSIVE_LOCK,                 //  force an exclussive lock vs. a shared lock
-                0,                                       //  must be set to 0 (dwReservered)
-                0,                                       //  The low-order 32 bits of the length of the byte range to lock
-                MAXDWORD,                                //  The high-order 32 bits of the length of the byte range to lock. | MAXDWORD = 0xffffffff
-                kyle                                     //  
-            )) { fclose(f); break; }
-            //  check for file every 6th of a second
-            else { fclose(f); Sleep(650); }
-        }
+    PDFWriter pdfWriter;
+    //  PREPARE PDF DOCUMENT
+    //  ********************
+    //  get a PDFWriter object to interact with. set the PDF version, set log file
+    EStatusCode e = pdfWriter.StartPDF("c:\\myFile.pdf",ePDFVersion13,LogConfiguration(true,true,".\\logMe"));
+    if (e){ 
+        /*  25APR20 - look through codebase and found these three reasons for nonrecoverable failure:
+        *  - user requested encryption, document doesn't support it
+        *  - it is unlikely, but for some reason GK wanted to call OutputFile::CloseFile(), it failed 
+        *  - operating system was unsuccessful at giving a lock for the filename *
+        * 
+        *  * Windows 'gives' a lock, but doesn't protect others from writing to this filename
         */
         */
+        printf("Terminating (c:\\myFile.pdf): unsuccessful lock or couldn't close existing or requested encryption but not supported\n");
+        TRACE_LOG("Terminating (c:\\myFile.pdf): unsuccessful lock or couldn't close existing or requested encryption but not supported");
+        exit(1);
     }
     }
+    TRACE_LOG("Notified OS we might use c:\\myFile.pdf");
+    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");
+    //  include image file
+    
+    //  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();
+    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.
+    //  ******************** 
+    pdfWriterB.EndPageContentContext(pageContentContextB);
+    EStatusCode f = pdfWriterB.WritePageAndRelease(pdfPageB);
+    if (f){
+        printf ("something interesting");
+    }
+    pdfWriterB.EndPDF();*/
+    
     PDFWriter pdfWriterB;
     PDFWriter pdfWriterB;
     pdfWriterB.ContinuePDF("C:\\Users\\bad-p\\AppData\\Local\\VirtualStore\\myFile.pdf","C:\\Users\\bad-p\\AppData\\Local\\VirtualStore\\myFile.pdf.shutdown");
     pdfWriterB.ContinuePDF("C:\\Users\\bad-p\\AppData\\Local\\VirtualStore\\myFile.pdf","C:\\Users\\bad-p\\AppData\\Local\\VirtualStore\\myFile.pdf.shutdown");
     // Create a new page
     // Create a new page