You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Macamba <ma...@hermod.nl> on 2016/04/12 14:15:03 UTC

Starting question about PDFBox

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());

        }

    }

}

 


Re: Starting question about PDFBox

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 14.04.2016 um 11:06 schrieb Macamba:
> Thanks for the feedback. (Is it appreciated when you thank someone?)

Yes of course :-)


>
> As far as I know, the site I mentioned is the only site which has some
> explaining about PDFBox. It was helpful that it pressured me to become
> member of this mailing list, ask a question, and be pointed to the SVG
> website
> (https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apach
> e/pdfbox/examples/).


There are also many examples on stackoverflow, and there are several 
people who help. The only downside of stackoverflow is that some 
examples apply to 1.8 only, but this is mostly about how to open a file.

If you can't find what you need, just ask there or here.

Tilman


>
> Michel
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: dinsdag 12 april 2016 18:41
> To: users@pdfbox.apache.org
> Subject: Re: Starting question about PDFBox
>
> Am 12.04.2016 um 14:56 schrieb BREMAUD, CYRIL:
>> Hi,
>> You can find many example with PDFBox 2.0.0 at this link :
>> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/
>> apache/pdfbox/examples/
> Indeed, the examples from the source code downloads are the best way to
> start.
>
> That site is not really helpful. I've put a comment there three days ago and
> it is still in moderation.
> http://radixcode.com/pdfbox-example-code-how-to-extract-text-from-pdf-file-w
> ith-java/
>
> The only good side of this is that this increases my score on stackoverflow
> :-)
>
> Tilman
>
>
>
>> BR
>> Cyril.
>>
>> -----Original Message-----
>> From: Macamba [mailto:macamba@hermod.nl]
>> Sent: Tuesday, April 12, 2016 2:15 PM
>> To: users@pdfbox.apache.org
>> Subject: Starting question about PDFBox
>>
>> 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());
>>
>>           }
>>
>>       }
>>
>> }
>>
>>    
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: Starting question about PDFBox

Posted by Macamba <ma...@hermod.nl>.
Thanks for the feedback. (Is it appreciated when you thank someone?)

As far as I know, the site I mentioned is the only site which has some
explaining about PDFBox. It was helpful that it pressured me to become
member of this mailing list, ask a question, and be pointed to the SVG
website
(https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apach
e/pdfbox/examples/).

Michel  

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: dinsdag 12 april 2016 18:41
To: users@pdfbox.apache.org
Subject: Re: Starting question about PDFBox

Am 12.04.2016 um 14:56 schrieb BREMAUD, CYRIL:
> Hi,
> You can find many example with PDFBox 2.0.0 at this link : 
> https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/
> apache/pdfbox/examples/

Indeed, the examples from the source code downloads are the best way to
start.

That site is not really helpful. I've put a comment there three days ago and
it is still in moderation.
http://radixcode.com/pdfbox-example-code-how-to-extract-text-from-pdf-file-w
ith-java/

The only good side of this is that this increases my score on stackoverflow
:-)

Tilman



> BR
> Cyril.
>
> -----Original Message-----
> From: Macamba [mailto:macamba@hermod.nl]
> Sent: Tuesday, April 12, 2016 2:15 PM
> To: users@pdfbox.apache.org
> Subject: Starting question about PDFBox
>
> 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());
>
>          }
>
>      }
>
> }
>
>   
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm

Posted by Barry Neu <ba...@gmail.com>.
Made the suggested modification and that resolved the issue - not sure how I missed that - thank you.
I had sent the attachments from another email client because I wasn’t aware attachments were being stripped on the other end.

Thanks again.

> On Apr 13, 2016, at 10:43 AM, Tilman Hausherr <TH...@t-online.de> wrote:
> 
> Am 13.04.2016 um 18:37 schrieb Barry Neu:
>> With attachments.
>> 
> 
> "upload" isn't "send it again". However as a mod I had a look at the java:
> 
> 
>    private static PDDocument getTemplate(String urlPath) {
>        InputStream is = null;
>        PDDocument doc = new PDDocument();
>        try {
>            URL url = new URL(urlPath);
>            System.out.println("Connecting to " + url.toString() + " ... ");
>            URLConnection urlConn = url.openConnection();
>            if (!urlConn.getContentType().equalsIgnoreCase("application/pdf")) {
>                  System.out.println("FAILED.\n[Sorry. This is not a PDF.]");
>              }
>            else {
>                is = url.openStream();
>                doc.load(is);
>            }
>        }
>        catch (Exception e) {
>            e.printStackTrace();
>        }
>        finally {
>            if (is != null) {
>                try {
>                    is.close();
>                }
>                catch (Exception e2) {
>                    //file close failed
>                }
>            }
>        }
>        return doc;
>    }
> 
> 
> Please change
> 
> PDDocument doc = new PDDocument();
> ....
> doc.load(is);
> 
> to this:
> 
> PDDocument doc = null;
> ...
> doc = PDDocument.load(is);
> 
> and then try it again :-)
> 
> Tilman
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 13.04.2016 um 18:37 schrieb Barry Neu:
> With attachments.
>

"upload" isn't "send it again". However as a mod I had a look at the java:


     private static PDDocument getTemplate(String urlPath) {
         InputStream is = null;
         PDDocument doc = new PDDocument();
         try {
             URL url = new URL(urlPath);
             System.out.println("Connecting to " + url.toString() + " 
... ");
             URLConnection urlConn = url.openConnection();
             if 
(!urlConn.getContentType().equalsIgnoreCase("application/pdf")) {
                   System.out.println("FAILED.\n[Sorry. This is not a 
PDF.]");
               }
             else {
                 is = url.openStream();
                 doc.load(is);
             }
         }
         catch (Exception e) {
             e.printStackTrace();
         }
         finally {
             if (is != null) {
                 try {
                     is.close();
                 }
                 catch (Exception e2) {
                     //file close failed
                 }
             }
         }
         return doc;
     }


Please change

PDDocument doc = new PDDocument();
....
doc.load(is);

to this:

PDDocument doc = null;
...
doc = PDDocument.load(is);

and then try it again :-)

Tilman




Re: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm

Posted by Branden Visser <mr...@gmail.com>.
The list filters them out. You need to upload them somewhere and provide a link.

On Wed, Apr 13, 2016 at 9:37 AM, Barry Neu <bn...@connectedhealth.com> wrote:
> With attachments.
>
>
> From: Barry Neu
> Date: Wednesday, April 13, 2016 at 10:32 AM
> To: Barry Neu
> Subject: Fwd: PDFBox 2.0 - Loading PDDocument from stream loses track of
> PDAcroForm
>
>
>
> Begin forwarded message:
>
> From: Tilman Hausherr <TH...@t-online.de>
> Subject: Re: PDFBox 2.0 - Loading PDDocument from stream loses track of
> PDAcroForm
> Date: April 13, 2016 at 10:31:17 AM MDT
> To: users@pdfbox.apache.org
> Reply-To: users@pdfbox.apache.org
>
> Am 13.04.2016 um 17:40 schrieb Barry Neu:
>
> Hello.
> Sample Java code and PDF fillable form attached.
>
>
> These didn't go through. Please upload them somewhere.
>
> Tilman
>
> When trying to load the form from a url input stream, it appears the
> PDDocument, and PDDocumentCatalog are instantiated but making a call to
> PDDocumentCatalog.getAcroForm() returns null.
>
> The same PDF template loads fine from the file system and I can fill/flatten
> the form. Thank you in advance for any assistance.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm

Posted by Barry Neu <bn...@connectedhealth.com>.
With attachments.


From: Barry Neu
Date: Wednesday, April 13, 2016 at 10:32 AM
To: Barry Neu
Subject: Fwd: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm



Begin forwarded message:

From: Tilman Hausherr <TH...@t-online.de>>
Subject: Re: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm
Date: April 13, 2016 at 10:31:17 AM MDT
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Reply-To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>

Am 13.04.2016 um 17:40 schrieb Barry Neu:
Hello.
Sample Java code and PDF fillable form attached.

These didn't go through. Please upload them somewhere.

Tilman

When trying to load the form from a url input stream, it appears the PDDocument, and PDDocumentCatalog are instantiated but making a call to PDDocumentCatalog.getAcroForm() returns null.

The same PDF template loads fine from the file system and I can fill/flatten the form. Thank you in advance for any assistance.




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org<ma...@pdfbox.apache.org>
For additional commands, e-mail: users-help@pdfbox.apache.org<ma...@pdfbox.apache.org>



Re: PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 13.04.2016 um 17:40 schrieb Barry Neu:
> Hello.
> Sample Java code and PDF fillable form attached.

These didn't go through. Please upload them somewhere.

Tilman

> When trying to load the form from a url input stream, it appears the PDDocument, and PDDocumentCatalog are instantiated but making a call to PDDocumentCatalog.getAcroForm() returns null.
>
> The same PDF template loads fine from the file system and I can fill/flatten the form. Thank you in advance for any assistance.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org


PDFBox 2.0 - Loading PDDocument from stream loses track of PDAcroForm

Posted by Barry Neu <ba...@gmail.com>.
Hello.
Sample Java code and PDF fillable form attached.
When trying to load the form from a url input stream, it appears the PDDocument, and PDDocumentCatalog are instantiated but making a call to PDDocumentCatalog.getAcroForm() returns null.

The same PDF template loads fine from the file system and I can fill/flatten the form. Thank you in advance for any assistance.



Re: Starting question about PDFBox

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 12.04.2016 um 14:56 schrieb BREMAUD, CYRIL:
> Hi,
> You can find many example with PDFBox 2.0.0 at this link : https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/

Indeed, the examples from the source code downloads are the best way to 
start.

That site is not really helpful. I've put a comment there three days ago 
and it is still in moderation.
http://radixcode.com/pdfbox-example-code-how-to-extract-text-from-pdf-file-with-java/

The only good side of this is that this increases my score on 
stackoverflow :-)

Tilman



> BR
> Cyril.
>
> -----Original Message-----
> From: Macamba [mailto:macamba@hermod.nl]
> Sent: Tuesday, April 12, 2016 2:15 PM
> To: users@pdfbox.apache.org
> Subject: Starting question about PDFBox
>
> 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());
>
>          }
>
>      }
>
> }
>
>   
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: Starting question about PDFBox

Posted by "BREMAUD, CYRIL" <cy...@atos.net>.
Hi,
You can find many example with PDFBox 2.0.0 at this link : https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/

BR
Cyril.

-----Original Message-----
From: Macamba [mailto:macamba@hermod.nl] 
Sent: Tuesday, April 12, 2016 2:15 PM
To: users@pdfbox.apache.org
Subject: Starting question about PDFBox

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());

        }

    }

}

 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org