Quantcast

iText - create PDF/A Problem

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

iText - create PDF/A Problem

r.figliuolo

Hi,

I want put the watermark into the pdf, but I receive this error message:

 

java.lang.NullPointerException

       at com.itextpdf.text.pdf.internal.PdfA1Checker.checkPdfObject(PdfA1Checker.java:304)

       at com.itextpdf.text.pdf.internal.PdfAChecker.checkPdfAConformance(PdfAChecker.java:201)

       at com.itextpdf.text.pdf.internal.PdfAConformanceImp.checkPdfIsoConformance(PdfAConformanceImp.java:70)

       at com.itextpdf.text.pdf.PdfWriter.checkPdfIsoConformance(PdfWriter.java:3380)

       at com.itextpdf.text.pdf.PdfWriter.checkPdfIsoConformance(PdfWriter.java:3376)

       at com.itextpdf.text.pdf.PdfDictionary.toPdf(PdfDictionary.java:136)

       at com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)

       at com.itextpdf.text.pdf.PdfWriter$PdfBody.write(PdfWriter.java:424)

       at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:402)

       at com.itextpdf.text.pdf.PdfWriter.addToBody(PdfWriter.java:886)

       at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:398)

       at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:372)

       at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:207)

       at WatermarkPDF.main(WatermarkPDF.java:44)

 

 

public static void main(String[] args) {      

       try {              

            

            PdfReader Read_PDF_To_Watermark = new PdfReader("C:/SampleA.pdf");

            int number_of_pages = Read_PDF_To_Watermark.getNumberOfPages();

           

            PdfAStamper stamp = new PdfAStamper(Read_PDF_To_Watermark, new FileOutputStream("C:/SampleAWM.pdf"),PdfAConformanceLevel.PDF_A_1A);

           

            int i = 0;

            Image watermark_image = Image.getInstance("C:/watermark.jpg");

            watermark_image.setAbsolutePosition(200, 400);

            PdfContentByte add_watermark;           

            while (i < number_of_pages) {

              i++;

              add_watermark = stamp.getUnderContent(i);

              add_watermark.addImage(watermark_image);

            }

            stamp.close();

        }

        catch (Exception i1) {

            i1.printStackTrace();

        }

    }

 

AlmavivA Spa (www.almavivaitalia.it)

Divisione IT - Area Pubblica Amministrazione Centrale e Locale

Via di Casal Boccone, 188/190

00137 - Roma

 

Tel.: 06.39.93.34.79

e-mail: [hidden email]

 

cid:image001.gif@01CC30ED.E0ACDFB0

 


------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Raf Hens
On 28/01/2014 14:10, Figliuolo Rocco wrote:
> I want put the watermark into the pdf, but I receive this error message:

Can you tell us which version of iText you tested with and provide the
PDF that triggered this issue?  If you don't want to make the PDF
publicly available, you can send it to me directly.

Thanks,

Raf Hens
iText Software

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

r.figliuolo
I'm using iText version 5.4.5.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

r.figliuolo
This post has NOT been accepted by the mailing list yet.
Any ideas?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

blowagie
This post has NOT been accepted by the mailing list yet.
We no longer answer questions on Nabble. See http://itextpdf.com/nabble
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Gabriella
Hi
I have the same problem
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

iText mailing list
Gabriella schreef op 20/02/2014 10:17:
> I have the same problem
1. People who aren't on Nabble don't know what you mean by "same".
2. The OP was asked for a sample PDF, but as he didn't provide one, we
can't help him.
3. You didn't describe your problem, nor post a PDF.

My guess: you want to add a watermark to a document that isn't PDF/A-1
Level A and you expect it to be a PDF/A-1 Level A.
It should be obvious that such an expectation is wrong, but once again:
how can we know? You're not sharing your PDF.

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Gabriella
Hi,
this is the code:
public static void main(String[] args) {      

               try {              

                   

                    PdfReader Read_PDF_To_Watermark = new PdfReader("C:/SampleA.pdf");

                    int number_of_pages = Read_PDF_To_Watermark.getNumberOfPages();

                   

                    PdfAStamper stamp = new PdfAStamper(Read_PDF_To_Watermark, new FileOutputStream("C:/SampleAWM.pdf"),PdfAConformanceLevel.PDF_A_1A);

                   

                    int i = 0;

                    Image watermark_image = Image.getInstance("C:/watermark.png");

                    watermark_image.setAbsolutePosition(200, 400);

                    PdfContentByte add_watermark;            

                    while (i < number_of_pages) {

                      i++;

                      add_watermark = stamp.getUnderContent(i);

                      add_watermark.addImage(watermark_image);

                    }
                    Read_PDF_To_Watermark.close();            
                    stamp.close();

                }

                catch (Exception i1) {

                    i1.printStackTrace();

                }

            }



I have attached the PDF/A  and the watermark:

SampleA.pdfwatermark.PNG



when run this code
stamp.close();
there is this Exception:

java.io.IOException: RandomAccessSource not opened
        at com.itextpdf.text.io.MappedChannelRandomAccessSource.get(MappedChannelRandomAccessSource.java:141)
        at com.itextpdf.text.io.FileChannelRandomAccessSource.get(FileChannelRandomAccessSource.java:97)
        at com.itextpdf.text.io.GetBufferedRandomAccessSource.get(GetBufferedRandomAccessSource.java:91)
        at com.itextpdf.text.io.IndependentRandomAccessSource.get(IndependentRandomAccessSource.java:77)
        at com.itextpdf.text.pdf.RandomAccessFileOrArray.read(RandomAccessFileOrArray.java:225)
        at com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:247)
        at com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:241)
        at com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2469)
        at com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2506)
        at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:313)
        at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:207)
        at it.equitaliaservizi.fascicolo.watermark.Test.main(Test.java:50)


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

iText mailing list
On 2/27/2014 11:41 AM, Gabriella wrote:
> Hi,
> this is the code:

It doesn't make sense for me to take a look at your code, because you're
already doing something wrong from the start: your SampleA.pdf claims
that it's PDF/A-1A, but that allegation is wrong. Please find the
Preflight report in attachment. It lists what is wrong with the file.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php

SampleAfixed_report.pdf (731K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Gabriella
Can you give me a PDF/A-1A?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

iText mailing list
On 2/27/2014 2:28 PM, Gabriella wrote:
> Can you give me a PDF/A-1A?
OK, but this is the last favor you can ask from me.
If you need more help, you should consider purchasing a license/support
contract.
You clearly need functionality that is only available in the AGPL
version of iText.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php

SampleAfixed.pdf (394K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Gabriella
Thank you,
but also with this correct pdf A, there is the same error.
However , that is a forum....
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

iText mailing list
On 2/27/2014 3:22 PM, Gabriella wrote:
> but also with this correct pdf A, there is the same error.

There's a bug in your code.
There's a bug in iText.

I've fixed both, but only customers get hotfixes.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Gabriella
Sorry, but I thought that this forum give me back a solution of problem and not   that there is a bug in itex.

Sorry again
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

iText mailing list
On 2/27/2014 3:56 PM, Gabriella wrote:
> Sorry, but I thought that this forum give me back a solution of problem
The main problem is that we see that the AGPL version of iText is used
in many cases where a commercial license is mandatory.

We've had situations where a company discovered that an employee at an
integrator introduced iText without mentioning that a commercial license
was needed. The consequence: the customer decided not to work with that
integrator ever again.

Something similar happened to a start-up: they wanted funding and we
were contacted by the VC during the due diligence process. The start-up
didn't get funding as they didn't use the proper license for iText (and
other software).

The fact that we give quality answers for free on a forum may create the
impression that all the work we do is done for free. That impression
would be wrong.
Especially in this case, I choose to be very strict: you need iText 5
and you have a problem we can solve (*). We can help you if you're a
customer. We can choose not to help you if you're not.

(*) Except for the garbage in, garbage out problem: if you feed iText a
document that isn't PDF/A-1A and you expect it to become a PDF/A-1A
file, then you're doing something wrong.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

Gabriella
I already have iText 5 and a correct PDF/A-1A
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

iText mailing list
On 2/27/2014 5:55 PM, Gabriella wrote:
> I already have iText 5
Yes, but are you a customer?

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
TvT
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

TvT
@Gabriella
Bruno thinks that you violate the AGPL license and use iText in a commercial setting without paying/buying a commercial license - thats why you don't get anymore help.
I don't take sides however if you do so (and Bruno has some inside info on your project/company/your customer) buy a license. If you fully comply with the AGPL license there is no reason for you to get forced to buy a license and I would strongly reject those unfounded allegations. Alternativly you may try to ask your questions at stackoverflow in future...

So what's the problem with your code? (the bug in iText will probably be in the next iText release, can't help you with that)

>Read_PDF_To_Watermark.close();
>stamp.close();

You are closeing the reader before the stamper. That is wrong. If you delete that line it will probably work (can't test it right now).
The reader is implicitly closed when closing the stamper so there is no need to close it explicitely. If you really want to make sure (e.g. a different exeption is thrown before) you can add the following lines at the end:

catch (Exception i1) {
   i1.printStackTrace();
}
finally{
   if(Read_PDF_To_Watermark!=null){
      Read_PDF_To_Watermark.close();
   }
}

Of course you have to define a "PdfReader Read_PDF_To_Watermark=null;" out of the try/catch block for that...


2014-02-27 19:40 GMT+01:00 iText mailing list <[hidden email]>:
On 2/27/2014 5:55 PM, Gabriella wrote:
> I already have iText 5
Yes, but are you a customer?

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
mkl
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iText - create PDF/A Problem

mkl
TvT wrote
The reader is implicitly closed when closing the stamper so there is no
need to close it explicitely.
In the recent past more and more implicit close calls have been removed (as these calls break some use cases). Thus, I would advice to explicitly close the relevant objects.

Regards,   Michael
TvT
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [SPAM] Re: iText - create PDF/A Problem

TvT
thanks for the info - so it makes sense to close the reader after the stamper...


2014-02-28 12:33 GMT+01:00 mkl <[hidden email]>:
TvT wrote
> The reader is implicitly closed when closing the stamper so there is no
> need to close it explicitely.

In the recent past more and more implicit close calls have been removed (as
these calls break some use cases). Thus, I would advice to explicitly close
the relevant objects.

Regards,   Michael



--
View this message in context: http://itext-general.2136553.n4.nabble.com/iText-create-PDF-A-Problem-tp4659694p4659815.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Loading...