2016-06-01 5 views
0

podofo를 사용하여 pdf 문서를 수정하는 데 문제가 발생했습니다. 시간이 있다면 해결하도록 도와주세요!수정할 때 출력 텍스트가 세로로 뒤집 혔음

http://podofo.sourceforge.net/download.html에 podofo 소스가 있으며 Windows 7 x86에서 컴파일 된 것으로 podofo의 기능이 매우 유용하다는 사실을 발견했습니다.

그러나 "helloworld.cpp"예제에서 뭔가를 변경하면 pdf 문서를 수정하고 다른 파일 이름으로 저장하기위한 약간의 코드가 변경됩니다!

로컬 pdf 문서 파일 (로컬 pdf 문서가 Office Word 2007의 Windows COM 인터페이스를 사용하는 Word 문서에서 저장 됨)을 기능으로 사용하면 새 파일이 성공적으로 출력되지만 출력 텍스트는 수직으로 뒤집 힙니다. 출력 텍스트의 Y pos는 수직으로 뒤집 힙니다.

(일부 사람들은 nn과 같은 상황에서 기존 콘텐츠가 그래픽 상태를 변경했을 수 있다는 사실을 알고 있어야합니다. 예를 들어 현재 변환 행렬이 변경되었을 수 있습니다. 그러나 그럴 수는 있지만 기능을 찾을 수 없습니다. 그래픽 상태를 변경하고 현재의 변환 행렬)

이이 사진을 스크린 샷입니다 변경에, 나는 출력 텍스트가 수직으로 뒤집 이유를 알고하지 않습니다

screenshot

을 홀수가 잘 작동입니다 예 : "helloworl"로 만든 문서 "output.pdf"를 통과했을 때 d ".

시간이 있다면 해결해주세요. 정말 고마워요!

내 변경된 코드는 다음과 같습니다 MKL의 도움으로 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

감사가, 문제가 해결되었다.

문제는 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!"