Changing the font size on PoDoFo::PdfFont

30 Views Asked by At

I'm trying to create a searchable PDF from images that have been OCRed and in PoDoFo 0.9.22 I was able to do it with the code below. I would increase/decrease the font size till I had the correct size that matched my image. But as of 0.10.x (I'm trying to use 0.10.3) there is no GetFontSize anywhere and PdfFont does not have SetFontSize. How can I achieve the same thing in the new version?

Thanks

void PrintTextOnPage(PoDoFo::PdfPainter& mPainter, PoDoFo::PdfFont* pFont, const TRectD& pageBB, const PoDoFo::PdfString aText, const TRectD& txtBB)
{
    const PoDoFo::PdfFontMetrics* fontMetrics = pFont->GetFontMetrics();
    float fontSize = pFont->GetFontSize();
    double tmpW = fontMetrics->StringWidth(aText);

    while (tmpW < txtBB.Width)
    {
        fontSize += 1.0;
        pFont->SetFontSize(fontSize);
        tmpW = fontMetrics->StringWidth(aText);
    }
    while (tmpW > txtBB.Width)
    {
        fontSize -= 0.5;
        pFont->SetFontSize(fontSize);
        tmpW = fontMetrics->StringWidth(aText);
    }
    mPainter.DrawText(txtBB.Left, (pageBB.Height) - (txtBB.Top + txtBB.Height), aText);
}
1

There are 1 best solutions below

2
273K On

Replace

float fontSize = pFont->GetFontSize();

and

pFont->SetFontSize(fontSize);

with

double fontSize = mPainter.GetFontSize();

and

mPainter.SetFont(pFont, fontSize);

Finding the text GetFontSize in the sources was easy.