0

我正在尝试在 c++ 中使用 PODOFO 在 PDF 中创建文本。单击文本后,它可以移动到同一 PDF 中的特定页面/区域。我的最终目标是在 PDF 中创建一个目录。以下代码是我正在做的。

#include <iostream>
#include <string>
#include <podofo/podofo.h>

using namespace PoDoFo;
using namespace std;

int main( int argc, char* argv[] )
{
try {
    string filename = std::string(argv[0]) + "testtesttesttest.pdf";
    PdfStreamedDocument* document = new PdfStreamedDocument(filename.c_str());
    PdfPage* pPage1;
    PdfPainter painter;
    PdfFont* pFont;
    pPage1 = document->CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
    painter.SetPage(pPage1);
    if( !pPage1 ) {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }
    pFont = document->CreateFont( "Arial" );
    if( !pFont ) {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }
    pFont->SetFontSize( 18.0 );
    painter.SetFont( pFont );
    painter.DrawText( 56.69, pPage1->GetPageSize().GetHeight() - 56.69, "Hello World!" );
    PdfPage* pPage2 = document->CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_Letter ) );
    painter.SetPage( pPage1 );
    this->drawHyperLinkText(&painter, pPage1, pPage2, document );
    //painter.SetPage( pPage2 );
    painter.FinishPage();
    document->GetInfo()->SetCreator ( PdfString("examplehelloworld - A PoDoFo test application") );
    document->GetInfo()->SetAuthor  ( PdfString("Dominik Seichter") );
    document->GetInfo()->SetTitle   ( PdfString("Hello World 222") );
    document->GetInfo()->SetSubject ( PdfString("Testing the PoDoFo PDF Library") );
    document->GetInfo()->SetKeywords( PdfString("Test;PDF;Hello World;") );
    document->Close();
} catch( const PdfError & eCode ) {
    eCode.PrintErrorMsg();
}
   return 0;
}

void drawHyperLinkText( PdfPainter* pPainter, PdfPage* pPage1, PdfPage* pPage2, PdfStreamedDocument* pDocument )
{
    PdfString sJap(reinterpret_cast<const pdf_utf8*>("test"));
    PdfAnnotation* pAnnotation = pPage2->CreateAnnotation( ePdfAnnotation_Link, PdfRect( 400.0, 200.0, 20.0, 20.0 ) );
    PdfString sGerman(reinterpret_cast<const pdf_utf8*>("Unicode Umlauts: ÄÖÜß"));
    pAnnotation->SetTitle( sGerman );
    pAnnotation->SetContents( sJap );
    pAnnotation->SetOpen( true );
    pAnnotation->SetDestination(pPage1);
}

我不知道我做对与否。我创建了两个页面并想在页面中添加文本。当我单击文本时,它会移回第 1 页。但它总是在最后一行崩溃 pAnnotation->SetDestination(pPage1);

谁能给我一些帮助或一个例子来做到这一点?谢谢

4

0 回答 0