2016-06-01 7 views
0

podofoを使用してpdfドキュメントを修正する際に問題が発生しました。時間があったら、解決してください!変更時に出力テキストが垂直に反転した

http://podofo.sourceforge.net/download.htmlにpodofoソースが見つかりました。私はWindows 7 x86でコンパイルしました.podofoの機能は非常に強力です。

しかし、私が "helloworld.cpp"の例で何かを変更した場合、pdfドキュメントを変更して他のファイル名で保存するためのちょっとしたコード変更!

ローカルのpdfドキュメントファイル(ローカルPDFドキュメントはオフィスワード2007のWindows COMのインターフェイスを使用するWordドキュメントから保存されます)を機能すると、新しいファイルは正常に出力されますが、出力テキストは垂直反転されます出力テキストのY posは垂直方向に反転します。

(いくつかの人は、既存のコンテンツが現在の変換マトリックスを変更したなど、既存のコンテンツが変更されている可能性がありますが、出力テキストを上下反転された理由は、画像のスクリーンショットです)

をグラフィックス状態を変更し、現在の変換行列を変更するために、私は知らない。

screenshot

奇数は、それがうまく機能しています私が "helloworl"という例で作成したドキュメント "output.pdf"を渡したときd "である。

お時間がありましたら、解決してください、どうもありがとう!

私のコードは次のようになります変更:MKLのため

#define MEMDOCUMENT 1 // macro switch 
void HelloWorld(const char* pszFilename) 
{ 
    /* 
    * PdfStreamedDocument is the class that can actually write a PDF file. 
    * PdfStreamedDocument is much faster than PdfDocument, but it is only 
    * suitable for creating/drawing PDF files and cannot modify existing 
    * PDF documents. 
    * 
    * The document is written directly to pszFilename while being created. 
    */ 
#if MEMDOCUMENT 
    PdfMemDocument document(pszFilename); //open local pdf documet 
#else 
    PdfStreamedDocument document(pszFilename); //create a new pdf documet 
#endif 
    /* 
    * PdfPainter is the class which is able to draw text and graphics 
    * directly on a PdfPage object. 
    */ 
    PdfPainter painter; 

    /* 
    * This pointer will hold the page object later. 
    * PdfSimpleWriter can write several PdfPage's to a PDF file. 
    */ 
    PdfPage* pPage; 

    /* 
    * A PdfFont object is required to draw text on a PdfPage using a PdfPainter. 
    * PoDoFo will find the font using fontconfig on your system and embedd truetype 
    * fonts automatically in the PDF file. 
    */  
    PdfFont* pFont; 

    try { 
     /* 
     * The PdfDocument object can be used to create new PdfPage objects. 
     * The PdfPage object is owned by the PdfDocument will also be deleted automatically 
     * by the PdfDocument object. 
     * 
     * You have to pass only one argument, i.e. the page size of the page to create. 
     * There are predefined enums for some common page sizes. 
     */ 
#if MEMDOCUMENT 
     pPage = document.GetPage(0); //get the first page and modify it 
#else 
     pPage = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4)); 
#endif 
     /* 
     * If the page cannot be created because of an error (e.g. ePdfError_OutOfMemory) 
     * a NULL pointer is returned. 
     * We check for a NULL pointer here and throw an exception using the RAISE_ERROR macro. 
     * The raise error macro initializes a PdfError object with a given error code and 
     * the location in the file in which the error ocurred and throws it as an exception. 
     */ 
     if(!pPage) 
     { 
      PODOFO_RAISE_ERROR(ePdfError_InvalidHandle); 
     } 

     /* 
     * Set the page as drawing target for the PdfPainter. 
     * Before the painter can draw, a page has to be set first. 
     */ 
     painter.SetPage(pPage); 

     /* 
     * Create a PdfFont object using the font "Arial". 
     * The font is found on the system using fontconfig and embedded into the 
     * PDF file. If Arial is not available, a default font will be used. 
     * 
     * The created PdfFont will be deleted by the PdfDocument. 
     */ 
     pFont = document.CreateFont("Arial"); 

     /* 
     * If the PdfFont object cannot be allocated return an error. 
     */ 
     if(!pFont) 
     { 
      PODOFO_RAISE_ERROR(ePdfError_InvalidHandle); 
     } 

     /* 
     * Set the font size 
     */ 
     pFont->SetFontSize(18.0); 

     /* 
     * Set the font as default font for drawing. 
     * A font has to be set before you can draw text on 
     * a PdfPainter. 
     */ 
     painter.SetFont(pFont); 

     /* 
     * You could set a different color than black to draw 
     * the text. 
     * 
     * SAFE_OP(painter.SetColor(1.0, 0.0, 0.0)); 
     */ 

     /* 
     * Actually draw the line "Hello World!" on to the PdfPage at 
     * the position 2cm,2cm from the top left corner. 
     * Please remember that PDF files have their origin at the 
     * bottom left corner. Therefore we substract the y coordinate 
     * from the page height. 
     * 
     * The position specifies the start of the baseline of the text. 
     * 
     * All coordinates in PoDoFo are in PDF units. 
     * You can also use PdfPainterMM which takes coordinates in 1/1000th mm. 
     * 
     */ 

     painter.SetTransformationMatrix(1,0,0,-1,0,pPage->GetPageSize().GetHeight()); 

     painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 56.69, "Hello World!"); 

     painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 96.69, "Hello World!"); 

     /* 
     * Tell PoDoFo that the page has been drawn completely. 
     * This required to optimize drawing operations inside in PoDoFo 
     * and has to be done whenever you are done with drawing a page. 
     */ 
     painter.FinishPage(); 

     /* 
     * Set some additional information on the PDF file. 
     */ 
     document.GetInfo()->SetCreator (PdfString("examplahelloworld - A PoDoFo test application")); 
     document.GetInfo()->SetAuthor (PdfString("Dominik Seichter")); 
     document.GetInfo()->SetTitle (PdfString("Hello World")); 
     document.GetInfo()->SetSubject (PdfString("Testing the PoDoFo PDF Library")); 
     document.GetInfo()->SetKeywords(PdfString("Test;PDF;Hello World;")); 

     /* 
     * The last step is to close the document. 
     */ 

#if MEMDOCUMENT 
     document.Write("outputex.pdf"); //save page change 
#else 
     document.Close(); 
#endif 


    } catch (const PdfError & e) { 
     /* 
     * All PoDoFo methods may throw exceptions 
     * make sure that painter.FinishPage() is called 
     * or who will get an assert in its destructor 
     */ 
     try { 
      painter.FinishPage(); 
     } catch(...) { 
      /* 
      * Ignore errors this time 
      */ 
     } 

     throw e; 
    } 
} 
+0

は、このようないくつかのコードを追加します。また、あなたは正確に何を変えましたか? – DomTomCat

+0

元のサンプルとの主な違いは、あなたのコード( '#define MEMDOCUMENT 1'で)は、新しいPDFを作成するのではなく、既存の最初のページの内容を追加して既存のPDFを編集し、新しいページ。このような状況では、既存のコンテンツがグラフィックスの状態を変更した可能性があるという事実に対処する必要があります。現在の変換マトリックスを変更して物事を上下に反転させ、その変更はあなたの行動に影響を与えます。テキストも反転されて反転します。 – mkl

+0

@mkl私は何かが違うと思う。しかし、私はグラフィックスの状態を変更する方法を知りませんし、現在の変換行列を変えて逆さまにするように変更しました... –

答えて

1

感謝、MKLの助けを借りて、問題が解決されていました。

Reflection effect.podofoソースコードに変換行列があるので、問題は、テキストや行をpdfドキュメントに追加する前に変更することができます。あなたが実際の問題と何を期待についての詳細情報をご提供しなければならない//

 painter.SetTransformationMatrix(1,0,0,-1,0,pPage->GetPageSize().GetHeight()); // set Reflection effect 
     painter.Save(); 

     painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 56.69, "Hello World!"); 

     painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 96.69, "Hello World!" 
関連する問題