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

void PoDoFo::Impose::PdfTranslator::impose (  )

When all is prepared, call it to do the job.

Definition at line 381 of file pdftranslator.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfDocument::CreatePage(), PoDoFo::PdfPage::GetContentsForAppending(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfXObject::GetObjectReference(), PoDoFo::PdfPage::GetResources(), PoDoFo::PdfXObject::GetResources(), PoDoFo::PdfObject::GetStream(), PoDoFo::PdfStream::Set(), and PoDoFo::PdfMemDocument::Write().

            {
//                std::cerr<<"PdfTranslator::impose"<<std::endl;
                  if ( !targetDoc )
                        throw std::invalid_argument ( "impose() called with empty target" );

//                PdfObject trimbox;
//                PdfRect trim ( 0, 0, destWidth, destHeight );
//                trim.ToVariant ( trimbox );
                  std::map<int, PdfRect>* bbIndex = NULL;
                  if(boundingBox.size() > 0)
                  {
                        if(boundingBox.find("crop") != std::string::npos)
                        {
                              bbIndex = &cropRect;
                        }
                        else if(boundingBox.find("bleed") != std::string::npos)
                        {
                              bbIndex = &bleedRect;
                        }
                        else if(boundingBox.find("trim") != std::string::npos)
                        {
                              bbIndex = &trimRect;
                        }
                        else if(boundingBox.find("art") != std::string::npos)
                        {
                              bbIndex = &artRect;
                        }
                  }

                  typedef map<int, vector<PageRecord> > groups_t;
                  groups_t groups;
                  for ( unsigned int i = 0; i < planImposition->size(); ++i )
                  {
                        groups[ ( *planImposition ) [i].destPage].push_back ( ( *planImposition ) [i] );
                  }
                  
                  unsigned int lastPlate(0);
                  groups_t::const_iterator  git = groups.begin();
                  const groups_t::const_iterator gitEnd = groups.end();
                  while ( git != gitEnd )
                  {
                        PdfPage * newpage;
                        // Allow "holes" in dest. pages sequence.
                        unsigned int curPlate(git->first);
                        while(lastPlate != curPlate)
                        {
                              newpage = targetDoc->CreatePage ( PdfRect ( 0.0, 0.0, destWidth, destHeight ) );
                              ++lastPlate;
                        }
//          newpage->GetObject()->GetDictionary().AddKey ( PdfName ( "TrimBox" ), trimbox );
                        PdfDictionary xdict;

                        ostringstream buffer;
                        // Scale
                        buffer << std::fixed << scaleFactor <<" 0 0 "<< scaleFactor <<" 0 0 cm\n";

                        for ( unsigned int i = 0; i < git->second.size(); ++i )
                        {
                              PageRecord curRecord ( git->second[i] );
//                            std::cerr<<curRecord.sourcePage<< " " << curRecord.destPage<<std::endl;
                              if(curRecord.sourcePage <= pcount)
                              {
                                    double cosR = cos ( curRecord.rotate  *  3.14159 / 180.0 );
                                    double sinR = sin ( curRecord.rotate  *  3.14159 / 180.0 );
                                    double tx = curRecord.transX ;
                                    double ty = curRecord.transY ;
      
                                    int resourceIndex ( /*(curRecord.duplicateOf > 0) ? curRecord.duplicateOf : */curRecord.sourcePage );
                                    PdfXObject *xo = xobjects[resourceIndex];
                                    if(NULL != bbIndex)
                                    {
                                          PdfObject bb;
                                          // DominikS: Fix compilation using Visual Studio on Windows
                                          // bbIndex->at(resourceIndex).ToVariant( bb );                                      
                                          ((*bbIndex)[resourceIndex]).ToVariant( bb );
                                          xo->GetObject()->GetDictionary().AddKey ( PdfName ( "BBox" ), bb );
                                    }
                                    ostringstream op;
                                    op << "OriginalPage" << resourceIndex;
                                    xdict.AddKey ( PdfName ( op.str() ) , xo->GetObjectReference() );
      
                                    if ( resources[resourceIndex] )
                                    {
                                          if ( resources[resourceIndex]->IsDictionary() )
                                          {
                                                TKeyMap resmap = resources[resourceIndex]->GetDictionary().GetKeys();
                                                TCIKeyMap itres;
                                                for ( itres = resmap.begin(); itres != resmap.end(); ++itres )
                                                {
                                                      xo->GetResources()->GetDictionary().AddKey ( itres->first, itres->second );
                                                }
                                          }
                                          else if ( resources[resourceIndex]->IsReference() )
                                          {
                                                xo->GetObject()->GetDictionary().AddKey ( PdfName ( "Resources" ), resources[resourceIndex] );
                                          }
                                          else
                                                std::cerr<<"ERROR Unknown type resource "<<resources[resourceIndex]->GetDataTypeString()  <<  std::endl;
      
                                    }
                                    // Very primitive but it makes it easy to track down imposition plan into content stream.
                                    buffer << "q\n";
                                    buffer << std::fixed << cosR <<" "<< sinR<<" "<<-sinR<<" "<< cosR<<" "<< tx <<" "<<  ty << " cm\n";
                                    buffer << "/OriginalPage" << resourceIndex << " Do\n";
                                    buffer << "Q\n";
                              }
                        }
                        string bufStr = buffer.str();
                        newpage->GetContentsForAppending()->GetStream()->Set ( bufStr.data(), bufStr.size() );
                        newpage->GetResources()->GetDictionary().AddKey ( PdfName ( "XObject" ), xdict );
                        ++git;
                  }

                  targetDoc->Write ( outFilePath.c_str() );

            }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index