Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

void PoDoFo::Impose::PdfTranslator::setSource ( const std::string &  source )

Set the source document(s) to be imposed. Argument source is the path of the PDF file, or the path of a file containing a list of paths of PDF files...

Definition at line 83 of file pdftranslator.cpp.

References PoDoFo::PdfError::ErrorMessage(), PoDoFo::PdfPage::GetMediaBox(), PoDoFo::PdfDocument::GetPage(), PoDoFo::PdfDocument::GetPageCount(), and PoDoFo::PdfMemDocument::InsertPages().

            {
                  int dbg(0);
//                std::cerr<<"PdfTranslator::setSource "<<source<<std::endl;
                  std::cerr<< ++dbg <<std::endl;
                  if ( checkIsPDF ( source ) )
                  {
//          std::cerr << "Appending "<<source<<" to source" << endl;
                        multiSource.push_back ( source );
                  }
                  else
                  {

                        ifstream in ( source.c_str(), ifstream::in );
                        if ( !in.good() )
                              throw runtime_error ( "setSource() failed to open input file" );


                        char *filenameBuffer = new char[1000];
                        do
                        {
                              in.getline ( filenameBuffer, 1000 );
                              std::string ts ( filenameBuffer, in.gcount() );
                              if ( ts.size() > 4 ) // at least ".pdf" because just test if ts is empty doesn't work.
                              {
                                    multiSource.push_back ( ts );
                                    std::cerr << "Appending "<< ts <<" to source" << endl;
                              }
                        }
                        while ( !in.eof() );
                        in.close();
                        delete filenameBuffer;
                  }
                  std::cerr<< ++dbg <<std::endl;

                  for ( std::vector<std::string>::const_iterator ms = multiSource.begin(); ms != multiSource.end(); ++ms )
                  {
                        if ( ms == multiSource.begin() )
                        {
//                            std::cerr << "First doc is "<< (*ms).c_str()   << endl;
                              try{
                                    sourceDoc = new PdfMemDocument ( ( *ms ).c_str() );
                              }
                              catch(PdfError& e)
                              {
                                    std::cerr<<"Unable to create Document: " <<PdfError::ErrorMessage( e. GetError() )<<endl;
                                    return;
                              }
                        }
                        else
                        {
                              PdfMemDocument mdoc ( ( *ms ).c_str() );
//                std::cerr << "Appending "<< mdoc.GetPageCount() << " page(s) of " << *ms  << endl;
                              sourceDoc->InsertPages ( mdoc, 0, mdoc.GetPageCount() );
                        }
                  }

                  pcount = sourceDoc->GetPageCount();
//    std::cerr << "Document has "<< pcount << " page(s) " << endl;
                  if ( pcount > 0 ) // only here to avoid possible segfault, but PDF without page is not conform IIRC
                  {
                        PoDoFo::PdfRect rect ( sourceDoc->GetPage ( 0 )->GetMediaBox() );
                        // keep in mind it’s just a hint since PDF can have different page sizes in a same doc
                        sourceWidth =  rect.GetWidth() - rect.GetLeft();
                        sourceHeight =  rect.GetHeight() - rect.GetBottom() ;
                  }
            }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index