PauseAndContinue.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // standard library includes
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. // end standard library includes
  6. // pdfwriter library includes
  7. #include "PDFWriter.h"
  8. #include "PDFPage.h"
  9. #include "PageContentContext.h"
  10. using namespace PDFHummus;
  11. static const string scBasePath = "";
  12. static const string scSystemFontsPath = "C:\\windows\\fonts\\";
  13. int main(int argc, wchar_t* argv[])
  14. {
  15. EStatusCode status;
  16. do
  17. {
  18. {
  19. PDFWriter pdfWriterA;
  20. status = pdfWriterA.StartPDF(scBasePath + "PauseAndContinue.pdf",ePDFVersion13);
  21. if(status != eSuccess)
  22. break;
  23. // Create a new page
  24. PDFPage* pdfPage = new PDFPage();
  25. pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
  26. // Create a content context for the page
  27. PageContentContext* pageContentContext = pdfWriterA.StartPageContentContext(pdfPage);
  28. PDFUsedFont* arialTTF = pdfWriterA.GetFontForFile(scSystemFontsPath + "arial.ttf");
  29. if(!arialTTF)
  30. {
  31. status = eFailure;
  32. break;
  33. }
  34. pageContentContext->k(0,0,0,1);
  35. pageContentContext->BT();
  36. pageContentContext->Tf(arialTTF,1);
  37. pageContentContext->Tm(20,0,0,20,40,822);
  38. pageContentContext->Tj("Hello World");
  39. pageContentContext->ET();
  40. // End content context, and write the page
  41. status = pdfWriterA.EndPageContentContext(pageContentContext);
  42. if(status != eSuccess)
  43. break;
  44. status = pdfWriterA.WritePageAndRelease(pdfPage);
  45. if(status != eSuccess)
  46. break;
  47. status = pdfWriterA.Shutdown(scBasePath + "PauseAndContinueTest.txt");
  48. if(status != eSuccess)
  49. break;
  50. }
  51. {
  52. PDFWriter pdfWriterB;
  53. status = pdfWriterB.ContinuePDF(scBasePath + "PauseAndContinue.pdf",scBasePath + "PauseAndContinueTest.txt");
  54. if(status != eSuccess)
  55. break;
  56. // Create a new page
  57. PDFPage* pdfPage = new PDFPage();
  58. pdfPage->SetMediaBox(PDFRectangle(0,0,595,842));
  59. // Create a content context for the page
  60. PageContentContext* pageContentContext = pdfWriterB.StartPageContentContext(pdfPage);
  61. PDFUsedFont* arialTTF = pdfWriterB.GetFontForFile(scSystemFontsPath + "arial.ttf");
  62. if(!arialTTF)
  63. {
  64. status = eFailure;
  65. break;
  66. }
  67. pageContentContext->k(0,0,0,1);
  68. pageContentContext->BT();
  69. pageContentContext->Tf(arialTTF,1);
  70. pageContentContext->Tm(20,0,0,20,40,822);
  71. pageContentContext->Tj("Hello Again, World");
  72. pageContentContext->ET();
  73. // End content context, and write the page
  74. status = pdfWriterB.EndPageContentContext(pageContentContext);
  75. if(status != eSuccess)
  76. break;
  77. status = pdfWriterB.WritePageAndRelease(pdfPage);
  78. if(status != eSuccess)
  79. break;
  80. status = pdfWriterB.EndPDF();
  81. if(status != eSuccess)
  82. break;
  83. }
  84. }while(false);
  85. if(eSuccess == status)
  86. cout<<"Succeeded in creating PauseAndContinue.PDF file\n";
  87. else
  88. cout<<"Failed in creating PauseAndContinue.PDF file\n";
  89. return 0;
  90. }