简体   繁体   中英

issue with upgrading from itext5 to itext5.2

Recently we had to upgrade from itext version 5 to version 5.2 since the latter has support for Chinese languages. However one major change in the newer version is that it no longer supports the TextProvidingRenderListener class in the contsructor of PdfTextExtractor class. There was a class we had customized to utilize this feature :

public class CustomLocationAwarePdfRenderListener
implements TextProvidingRenderListener
{
    public CustomLocationAwarePdfRenderListener( int lineAlignErrorAllowed)
    {
        this.lineAlignErrorAllowed = lineAlignErrorAllowed;
        reset();
    }

However as an outcome there is now no way to use this class and the attribute called lineAlignErrorAllowed which was part of the constructor of the CustomLocationAwarePdfRenderListener . The lineAlignErrorAllowed basically acts as a parameter of scanning the minimum no. of lines before the source is considered as too complex. Any help on this topic would really be appreciated.

Managed to fix this issue after realizing that the LocationTextExtractionStrategy class in the latest itext version is a worthy replacement for the TextProvidingRenderListener . Although this time we had to extend the class. The only other change that was needed is to alter to code to use the now static PdfTextExtractor class by passing an instance of the LocationTextExtractionStrategy to the getTextFromPage . Had a bit of a struggle searching for the latest itext API reference doc, but got them here finally. (Somehow they show up with some different formatting than regular java API docs but one can live with that).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM