| 338 | }; |
| 339 | |
| 340 | SimplePDFModule::SimplePDFModule( const char *const PDFfilename, const char *const title ) |
| 341 | : filename( PDFfilename ), DocumentTitle( title ), page(0) |
| 342 | { |
| 343 | std::ofstream fout( filename.c_str(), std::ios::binary ); |
| 344 | |
| 345 | if( !fout ){ |
| 346 | std::cerr << "plotPDF() : Cannot open the file: " << filename << std::endl; |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | //-------------------------------------------------- |
| 351 | // Header Section |
| 352 | //-------------------------------------------------- |
| 353 | std::stringstream header; |
| 354 | #if 1 |
| 355 | // match to pdflatex & dvipdfmx in texlive 2019 |
| 356 | header << "%PDF-1.5\n" |
| 357 | << '%' << char(0xd0) << char(0xd4) << char(0xc5) << char(0xd8) << '\n'; |
| 358 | #else |
| 359 | header << "%PDF-1.7\n" |
| 360 | << '%' << char(0xe2) << char(0xe3) << char(0xcf) << char(0xd3) << '\n'; |
| 361 | #endif |
| 362 | |
| 363 | fout << header.str(); |
| 364 | byte_offset = header.str().length(); |
| 365 | |
| 366 | fout.close(); |
| 367 | |
| 368 | //-------------------------------------------------- |
| 369 | // Body Section : Objects |
| 370 | //-------------------------------------------------- |
| 371 | std::list<const std::string*> obj; |
| 372 | |
| 373 | std::stringstream strDocumentInfo; |
| 374 | strDocumentInfo << "1 0 obj\n" |
| 375 | << "<<\n"; |
| 376 | |
| 377 | if( strlen( DocumentTitle.c_str() ) > 0 ) |
| 378 | strDocumentInfo << " /Title (" << DocumentTitle << ")\n"; |
| 379 | |
| 380 | strDocumentInfo << " /Creator (" << PLOTPDFVAR::AppName << ")\n" |
| 381 | << " /CreationDate (D:" << get_datetime() << ")\n" |
| 382 | << ">>\n" |
| 383 | << "endobj\n"; |
| 384 | const std::string DocumentInfo = strDocumentInfo.str(); |
| 385 | |
| 386 | // /PageLayout \in { /SinglePage (default), /OneColumn, |
| 387 | // /TwoColumnLeft, /TwoColumnRight, /TwoPageLeft, /TwoPageRight } |
| 388 | // /PageMode \in { /UseNone (default), /UseOutlines, /UseThumbs, /FullScreen, /UseOC, /UseAttachements } |
| 389 | const std::string DocumentCatalog = |
| 390 | "2 0 obj\n" |
| 391 | "<<\n" |
| 392 | " /Pages 3 0 R\n" |
| 393 | " /Type /Catalog\n" |
| 394 | " /PageLayout /SinglePage\n" |
| 395 | " /PageMode 4 0 R\n" |
| 396 | " /Outlines 5 0 R\n" |
| 397 | ">>\n" |