Adding itextg to gradle

2019-08-15 06:23发布

问题:

I want to add itextg via gradle to avoid having to maintain a set of library jars. Maybe it's me but I can't find the correct gradle compile statement anywhere.

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.itextg:itextg:5.4.3'
}

Regular itext works just fine but I'm trying to do stuff with images.

compile 'com.itextpdf:itextpdf-5.5.6'

回答1:

I think that's because we released iText as a jar on Maven Central (which Gradle also uses as a repository) and also as a download from various sites (GitHub, SourceForge); but iTextG only as a download on various sites, not on Maven Central. iTextG uses the same namespace as iText: com.itextpdf:itextpdf so having it on Maven Central too would create conflicts. Something like com.itextg:itextg simply does not exist (as far as I know - and I am supposed to know because I am QA Engineer at iText Software). In fact, the main difference between iText and iTextG, is that we have stripped all AWT dependencies from iTextG. For the rest they are exactly the same codebase.

So, to finally answer your question after all this background information: you'll have to download the iTextG jar and manually add it to your libs folder.

As of iText 5.5.9, you can add this to your Gradle file:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.itextpdf:itextg:5.5.9'
}