コード例 #1
0
ファイル: PdfFont.cpp プロジェクト: arunjalota/paperman
void PdfFont::WriteStringToStream( const PdfString & rsString, PdfStream* pStream )
{
    if( !m_pEncoding )
    {
	PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    PdfString sEncoded = m_pEncoding->ConvertToEncoding( rsString, this );
    if( sEncoded.IsUnicode() ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InternalLogic, "ConvertToEncoding must not return a unicode string" );
    }

    pdf_long  lLen    = 0;
    char* pBuffer = NULL;

    std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode );    
    pFilter->Encode( sEncoded.GetString(), sEncoded.GetLength(), &pBuffer, &lLen );

    pStream->Append( "<", 1 );
    pStream->Append( pBuffer, lLen );
    pStream->Append( ">", 1 );

    free( pBuffer );
}
コード例 #2
0
void TextExtractor::AddTextElement( double dCurPosX, double dCurPosY, 
                                    PdfFont* pCurFont, const PdfString & rString )
{
    if( !pCurFont ) 
    {
        fprintf( stderr, "WARNING: Found text but do not have a current font: %s\n", rString.GetString() );
        return;
    }

    if( !pCurFont->GetEncoding() ) 
    {
        fprintf( stderr, "WARNING: Found text but do not have a current encoding: %s\n", rString.GetString() );
        return;
    }

    // For now just write to console
    PdfString unicode = pCurFont->GetEncoding()->ConvertToUnicode( rString, pCurFont );
    const char* pszData = unicode.GetStringUtf8().c_str();
    while( *pszData ) {
        printf("%02x", static_cast<unsigned char>(*pszData) );
        ++pszData;
    }
    printf("\n");

    printf("(%.3f,%.3f) %s \n", dCurPosX, dCurPosY, unicode.GetStringUtf8().c_str() );
}
コード例 #3
0
void PdfFileSpec::Init( const wchar_t* pszFilename, const unsigned char* data, ptrdiff_t size, bool bStripPath)
{
    PdfObject* pEmbeddedStream;
    PdfString filename;

    filename.setFromWchar_t( MaybeStripPath( pszFilename, true) );

    this->GetObject()->GetDictionary().AddKey( "F", this->CreateFileSpecification( MaybeStripPath( pszFilename, bStripPath ) ) );
    this->GetObject()->GetDictionary().AddKey( "UF", filename.ToUnicode() );

    PdfDictionary ef;

    pEmbeddedStream = this->CreateObject( "EmbeddedFile" );
    this->EmbeddFileFromMem( pEmbeddedStream, data, size );

    ef.AddKey( "F",  pEmbeddedStream->Reference() );

    this->GetObject()->GetDictionary().AddKey( "EF", ef );
}
コード例 #4
0
void EncryptTest::TestAuthenticate( PdfEncrypt* pEncrypt, int keyLength, int rValue ) 
{
    PdfString documentId;
    documentId.SetHexData( "BF37541A9083A51619AD5924ECF156DF", 32 );

    pEncrypt->GenerateEncryptionKey( documentId );

    std::string documentIdStr( documentId.GetString(), documentId.GetLength() );
    std::string password = "******";
    std::string uValue( reinterpret_cast<const char*>(pEncrypt->GetUValue()), 32 );
    std::string oValue( reinterpret_cast<const char*>(pEncrypt->GetOValue()), 32 );

    // Authenticate using user password
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "authenticate using user password",
                                  pEncrypt->Authenticate( documentIdStr, std::string("user"),
                                                          uValue, oValue, pEncrypt->GetPValue(), keyLength, rValue ),
                                  true );

    // Authenticate using owner password
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "authenticate using owner password",
                                  pEncrypt->Authenticate( documentIdStr, std::string("podofo"), 
                                                          uValue, oValue, pEncrypt->GetPValue(), keyLength, rValue ),
                                  true );
}