I can't import com.itextpdf.text.Document class
11,546
You say:
I'm using com.itextpdf:itext-pdfa:5.5.9 library
That is wrong for two reasons:
- itext-pdfa is an addon to iText that is meant for writing or manipulating PDF/A documents. It requires the core iText libary. Read about the different parts of iText on the official web site: https://developers.itextpdf.com/itext-java
- You say you want to use iText on Android, but you are referring to iText for Java. iText for Java contains classes that are not allowed on Android (
java.awt.*
,javax.nio
,...). You should use the Android port for iText, which is called iTextG: https://developers.itextpdf.com/itextg-android
It's as if you're using iText without having visited the official iText web site. How is that even possible?
Author by
micdo94
Updated on June 04, 2022Comments
-
micdo94 almost 2 years
I'm building an android app and I want to use iText for creating pdf file, but I can't use Document class. As I seen in tutorials, there should be import com.itextpdf.text.Document for using Document class. For this app, I'm using com.itextpdf:itext-pdfa:5.5.9 library. I want to create a simple pdf file with 2 paragraphs, something like this:
try{ File pdfFolder = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOCUMENTS), "pdfdemo"); if (!pdfFolder.exists()) { pdfFolder.mkdir(); } Date date = new Date() ; String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(date); File myFile = new File(pdfFolder + timeStamp + ".pdf"); OutputStream output = new FileOutputStream(myFile); Document document = new Document(); PdfAWriter.getInstance(document, output); document.open(); document.add(new Paragraph(mSubjectEditText.getText().toString())); document.add(new Paragraph(mBodyEditText.getText().toString())); document.close(); }catch (Exception e) {}
'
Could anyone help me with this problem? What am I doing wrong?
-
Robert about 5 yearsThe question doesn't say anything about Gradle, why do you assume the OP uses Gradle?