2015-01-13 4 views
1

PoDoFo 라이브러리의 폴란드어 문자 인코딩에 문제가 있습니다.PoDoFo C++ PDF 라이브러리, 폴란드어 문자

이 코드가 '우치'

#include <podofo/podofo.h> 

using namespace PoDoFo; 

int main(int argc, char *argv[], char *env[]) { 
    PdfStreamedDocument document("polish.pdf"); 
    PdfPainter painter; 
    PdfPage* pPage; 


    pPage = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4)); 
    painter.SetPage(pPage); 
    PdfFont* pFont = document.CreateFont("Helvetica"); 
// PdfFont* pFont = document.CreateFont("Helvetica", new PdfIdentityEncoding(0, 0xffff, true)); 
    PdfString pString("Polish word: Łódź"); 
// PdfString pString(reinterpret_cast<const pdf_utf8*>("Polish word: Łódź")); 

    painter.SetFont(pFont); 
    painter.DrawText(100.0, pPage->GetPageSize().GetHeight()-100.0, pString); 
    painter.FinishPage(); 
    document.Close(); 

    return 0; 
} 

출력에서 ​​PDF 단어의 잘못된 인코딩을 생성

폴란드어 단어 : 나는 변화를 시도했습니다 Å † Ã3dÅo

소스 문자열 인코딩 (샘플 코드에서 주석 처리 된 행 사용), 모두 실패했습니다.

누군가 PoDoFo 라이브러리를 사용하여 비 ASCII 문자가 포함 된 PDF 문서를 만드는 방법을 설명 할 수 있습니까?

+0

두 가지 명백한 오류가 있습니다. PDF 렌더러가 UTF8을 파싱 할 수있을 것으로 기대하고 있습니다 (사용자가 알고 있는지 여부에 관계없이 사용하고있는 UTF8). 둘째, 내장 된 Helvetica에 폴란드 문자가 포함될 것으로 기대하고 있습니다. 자세한 내용은 http://stackoverflow.com/questions/26631815/cant-get-czech-characters-while-generating-a-pdf를 참조하십시오. – usr2564301

+0

@Jongware 나는 내 코드를 수정했고 폴란드어 문자가있는 임베드 된 글꼴을 추가하려고 시도했다. Liberation-Serif 코드는 다음과 같다. PdfFont * pFont = document.CreateFontSubset ("LiberationSerif", false, false, PdfEncodingFactory :: GlobalWinAnsiEncodingInstance (), "fonts/LiberationSerif-Regular.ttf"); 성공하지 못했습니다 ... – Markoj

답변

1
#include <podofo/podofo.h> 

using namespace PoDoFo; 

int main(int argc, char *argv[], char *env[]) { 
    PdfStreamedDocument document("polish.pdf"); 
    PdfPainter painter; 
    PdfPage* pPage; 


    pPage = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4)); 
    painter.SetPage(pPage); 
    const PdfEncoding* pEncoding = new PdfIdentityEncoding(); // required for UTF8 characters 
    PdfFont *pFont = document.CreateFont("LiberationSerif", false, false, pEncoding); // LiberationSerif has polish characters 
    PdfString pString(reinterpret_cast<const pdf_utf8*>("Polish word: Łódź")); // Need to cast input string into pdf_utf8 
    painter.SetFont(pFont); 
    painter.DrawText(100.0, pPage->GetPageSize().GetHeight()-100.0, pString); 
    painter.FinishPage(); 
    document.Close(); 

    return 0; 
} 

이 코드는 저에게 효과적입니다.