Extract PDF text by coordinates

前端 未结 6 755
半阙折子戏
半阙折子戏 2021-02-04 20:03

I\'d like to know if there\'s some PDF library in Microsoft .NET being able of extracting text by giving coordinates.

For example (in pseudo-code):

<         


        
6条回答
  •  伪装坚强ぢ
    2021-02-04 20:52

    It's not open source, but hopefully this helps you (and potentially anyone else using ABCPDF!)

    I did this earlier today by looping over the available fields in the PDF. This means that the PDF you are using needs to be created properly and you need to know the field name that you want to get the text for (you could work this out by adding a breakpoint and looping through the available fields).

    WebSupergoo.ABCpdf6.Doc newPDF = new WebSupergoo.ABCpdf6.Doc();
    newPDF.Read("existing_file.pdf");
    
    foreach ( WebSupergoo.ABCpdf6.Objects.Field field in newPDF.Form.Fields )
    {
        if ( field.Name == "Text1" )
        {
            // update "Text1"
            field.Value = "new value for Text1";
        }
    }
    
    newPDF.Save("new_file.pdf");
    
    newPDF.Clear();
    

    In the example, "Text1" is the name of the field that is being updated. Note I am also providing an example for saving out updated field(s).

    Hopefully that at least gives you an idea of how to approach this problem.

提交回复
热议问题