Hi,

 

My apologies for this basic question, but I'm just starting with PDFBox and
can't make heads nor tale from it (at the moment). I found a website
(http://radixcode.com/category/pdfbox/) which had example code I wanted to
start out with. But when I copied the first code into Eclipse my Eclipse
complained about some of the imports. I have included the example code below
my text. 

 

As I start with PDFBox I need some documentation to help me start. As I use
PDFBox 2.0.0 I cannot find any examples. Does anyone know of websites with
some explanation? Or would it be smarter to use PDFBox 1.8.11 (which also
has no example of a working example as far as I could see)?

 

Thanks,

Macamba

 

Example code from http://radixcode.com/category/pdfbox/ 

 

import java.io.FileInputStream;

import org.apache.pdfbox.pdmodel.PDDocument;

import org.apache.pdfbox.pdmodel.PDPage;

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;

// The following import org.apache.pdfbox.pdmodel.graphics.xobject cannot be
resolved

import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;

// The following import org.apache.pdfbox.pdmodel.graphics.xobject cannot be
resolved

import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;

 

/**

*

* @author azeem

*/

 

public class Main {

 

    public static void main(String[] args) {

 

        String fileName = "pdfWithImage.pdf";

        String imageName = "Logo.jpg";

 

        try {

 

            PDDocument doc = new PDDocument();

            PDPage page = new PDPage();

 

            doc.addPage(page);

 

            PDXObjectImage image = new PDJpeg(doc, new
FileInputStream(imageName));

 

            PDPageContentStream content = new PDPageContentStream(doc,
page);

 

            content.drawImage(image, 180, 700);

 

            content.close();

 

            doc.save(fileName);

 

            doc.close();

 

        } catch (Exception e) {

            System.err.println(e.getMessage());

        }

    }

}

 

Reply via email to