Commit 2668e978 authored by kimia's avatar kimia

PDF writer

parents
Pipeline #429 failed with stages
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class PDFWriteTest {
public static void main(String args[]){
try {
Document document = new Document();
OutputStream outputStream =
new FileOutputStream(new File("D:\\TestFile.pdf"));
PdfWriter.getInstance(document, outputStream);
document.open();
document.add(new Paragraph("Hello world, " +
"this is a test pdf file."));
//Close document and outputStream.
document.close();
outputStream.close();
System.out.println("Pdf created successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package PDFReaderTest;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import java.io.FileInputStream;
import java.io.IOException;
public class PDFReaderTest {
public static void main(String[] args) {
PdfReader pdfReader = null;
try {
pdfReader = new PdfReader(new FileInputStream("Lab6.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
int pages = pdfReader.getNumberOfPages();
for (int i = 1; i <= pages; i++) {
String pageContent = null;
try {
pageContent = PdfTextExtractor.getTextFromPage(pdfReader, i);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Content on Page " + i + ": " + pageContent);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment