4

PDF からテキストを抽出するときに、font-size も抽出する必要があります。まず、次のように抽出しました。

iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(
  curBaseline[Vector.I1],
  curBaseline[Vector.I2],
  topRight[Vector.I1],
  topRight[Vector.I2]);

これでは、正確なフォントサイズを取得できません。その後、使ってみrenderinfo.gs.fontsize;ました。これrenderinfo.gs.fontsizeで、正確なフォントサイズのテキストがいくつか得られますが、正確なフォントサイズが得られないものはほとんどありません。フォントサイズを取得する場所は「1.0」です。私が使用している方法が正しいと誰かに教えてもらえますか。いいえの場合、iTextSharp を使用してフォント サイズを抽出する他の方法があります。iTextSharp 5.4 バージョンを使用しています。前もって感謝します。

  using System;
    using System.Collections;
  // code java to C# conversion   
    public void renderText(TextRenderInfo renderInfo)
    {
        LineSegment curBaseline = renderInfo.Baseline;
        LineSegment curAscentline = renderInfo.AscentLine;
        Rectangle rect = new Rectangle(curBaseline.StartPoint.get(ArrayList.I1), curBaseline.StartPoint.get(ArrayList.I2), curAscentline.EndPoint.get(ArrayList.I1), curAscentline.EndPoint.get(ArrayList.I2));

        try
        {
            Console.Write("  [{0,6:F2}, {1,6:F2}, {2,6:F2}] \"{3}\" ({4} at {5,6:F2})\n", rect.Width, rect.Height, getEffectiveFontSize(renderInfo), renderInfo.Text, renderInfo.Font.FullFontName[0], getFontSize(renderInfo));
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            Console.Write(e.StackTrace);
        }
    }

    float getEffectiveFontSize(TextRenderInfo renderInfo) throws System.ArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, NoSuchMethodException
    {
        Method convertHeight = typeof(TextRenderInfo).getDeclaredMethod("convertHeightFromTextSpaceToUserSpace", float.TYPE);
        convertHeight.Accessible = true;
        return (float?)convertHeight.invoke(renderInfo, getFontSize(renderInfo));
    }

    float getFontSize(TextRenderInfo renderInfo) throws SecurityException, NoSuchFieldException, System.ArgumentException, IllegalAccessException
    {
        Field gsField = typeof(TextRenderInfo).getDeclaredField("gs");
        gsField.Accessible = true;
        GraphicsState gs = (GraphicsState) gsField.get(renderInfo);
        return gs.FontSize;
    }
4

1 に答える 1

-3

これが役に立つことを願っています

`
Font arial = FontFactory.GetFont("Arial", 28, Color.GRAY);
Font verdana = FontFactory.GetFont("Verdana", 16, Font.BOLDITALIC, new Color(125, 88, 15));
Font palatino = FontFactory.GetFont("palatino linotype italique",BaseFont.CP1252, BaseFont.EMBEDDED,
  10,
  Font.ITALIC,
  Color.GREEN
  );
Font smallfont = FontFactory.GetFont("Arial", 7);
Font x = FontFactory.GetFont("nina fett");
x.Size = 10;
x.SetStyle("Italic");
x.SetColor(100, 50, 200);`

フォントサイズの設定に使用できます

于 2013-05-03T10:23:08.160 に答える