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

void PoDoFo::Impose::PdfTranslator::setTarget ( const std::string &  target )

Set the path of the file where the imposed PDF doc will be save.

Its time to manage other keys of the page dictionary.

Definition at line 238 of file pdftranslator.cpp.

References PoDoFo::PdfDictionary::AddKey(), PoDoFo::PdfMemoryOutputStream::Close(), PoDoFo::PdfVariant::GetArray(), PoDoFo::PdfPage::GetArtBox(), PoDoFo::PdfPage::GetBleedBox(), PoDoFo::PdfXObject::GetContents(), PoDoFo::PdfPage::GetContents(), PoDoFo::PdfPage::GetCropBox(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfStream::GetFilteredCopy(), PoDoFo::PdfDocument::GetInfo(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfMemoryOutputStream::GetLength(), PoDoFo::PdfPage::GetMediaBox(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfVecObjects::GetObject(), PoDoFo::PdfMemDocument::GetObjects(), PoDoFo::PdfDocument::GetPage(), PoDoFo::PdfMemDocument::GetPdfVersion(), PoDoFo::PdfVariant::GetReference(), PoDoFo::PdfObject::GetStream(), PoDoFo::PdfPage::GetTrimBox(), PoDoFo::PdfDictionary::HasKey(), PoDoFo::PdfObject::HasStream(), PoDoFo::PdfVariant::IsArray(), PoDoFo::PdfVariant::IsReference(), PoDoFo::PdfStream::Set(), PoDoFo::PdfInfo::SetAuthor(), PoDoFo::PdfMemDocument::SetPdfVersion(), and PoDoFo::PdfMemoryOutputStream::TakeBuffer().

            {
//                std::cerr<<"PdfTranslator::setTarget "<<target<<std::endl;
                  if ( !sourceDoc )
                        throw std::logic_error ( "setTarget() called before setSource()" );

                  targetDoc = new PdfMemDocument;
                  outFilePath  = target;

                  for ( int i = 0; i < pcount ; ++i )
                  {
                        PdfPage * page = sourceDoc->GetPage ( i );
                        PdfMemoryOutputStream outMemStream ( 1 );

                        PdfXObject *xobj = new PdfXObject ( page->GetMediaBox(), targetDoc );
                        if ( page->GetContents()->HasStream() )
                        {
                              page->GetContents()->GetStream()->GetFilteredCopy ( &outMemStream );
                        }
                        else if ( page->GetContents()->IsArray() )
                        {
                              PdfArray carray ( page->GetContents()->GetArray() );
                              for ( unsigned int ci = 0; ci < carray.GetSize(); ++ci )
                              {
                                    if ( carray[ci].HasStream() )
                                    {
                                          carray[ci].GetStream()->GetFilteredCopy ( &outMemStream );
                                    }
                                    else if ( carray[ci].IsReference() )
                                    {
                                          PdfObject *co = sourceDoc->GetObjects().GetObject ( carray[ci].GetReference() );

                                          while ( co != NULL )
                                          {
                                                if ( co->IsReference() )
                                                {
                                                      co = sourceDoc->GetObjects().GetObject ( co->GetReference() );
                                                }
                                                else if ( co->HasStream() )
                                                {
                                                      co->GetStream()->GetFilteredCopy ( &outMemStream );
                                                      break;
                                                }
                                          }

                                    }

                              }
                        }

                        /// Its time to manage other keys of the page dictionary.
                        std::vector<std::string> pageKeys;
                        std::vector<std::string>::const_iterator itKey;
                        pageKeys.push_back ( "Group" );
                        for ( itKey = pageKeys.begin(); itKey != pageKeys.end(); ++itKey )
                        {
                              PoDoFo::PdfName keyname ( *itKey );
                              if ( page->GetObject()->GetDictionary().HasKey ( keyname ) )
                              {
                                    xobj->GetObject()->GetDictionary().AddKey ( keyname, migrateResource ( page->GetObject()->GetDictionary().GetKey ( keyname ) ) );
                              }
                        }

                        outMemStream.Close();

                        PdfMemoryInputStream inStream ( outMemStream.TakeBuffer(),outMemStream.GetLength() );
                        xobj->GetContents()->GetStream()->Set ( &inStream );

                        resources[i+1] = getInheritedResources ( page );
                        xobjects[i+1] = xobj;
                        cropRect[i+1] = page->GetCropBox();
                        bleedRect[i+1] = page->GetBleedBox();
                        trimRect[i+1] = page->GetTrimBox();
                        artRect[i+1] = page->GetArtBox();

                  }


                  targetDoc->SetPdfVersion ( sourceDoc->GetPdfVersion() );

                  PdfInfo *sInfo ( sourceDoc->GetInfo() );
                  PdfInfo *tInfo ( targetDoc->GetInfo() );

                  if ( sInfo->GetAuthor() != PdfString::StringNull )
                        tInfo->SetAuthor ( sInfo->GetAuthor() );
                  if ( sInfo->GetCreator() != PdfString::StringNull )
                        tInfo->SetCreator ( sInfo->GetCreator() );
                  if ( sInfo->GetSubject() != PdfString::StringNull )
                        tInfo->SetSubject ( sInfo->GetSubject() );
                  if ( sInfo->GetTitle() != PdfString::StringNull )
                        tInfo->SetTitle ( sInfo->GetTitle() );
                  if ( sInfo->GetKeywords() != PdfString::StringNull )
                        tInfo->SetKeywords ( sInfo->GetKeywords() );

                  if ( sInfo->GetTrapped() != PdfName::KeyNull )
                        tInfo->SetTrapped ( sInfo->GetTrapped() );


//    PdfObject *scat( sourceDoc->GetCatalog() );
//    PdfObject *tcat( targetDoc->GetCatalog() );
//    TKeyMap catmap = scat->GetDictionary().GetKeys();
//    for ( TCIKeyMap itc = catmap.begin(); itc != catmap.end(); ++itc )
//    {
//          if(tcat->GetDictionary().GetKey(itc->first) == 0)
//          {
//                PdfObject *o = itc->second;
//                tcat->GetDictionary().AddKey (itc->first , migrateResource( o ) );
//          }
//    }

//    delete sourceDoc;
            }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index