IText (Java2PDF) problem

Maby this isnt the right place for this quesstion but...
I have a very strange problem.
I'm using a servlet to generate PDF file on the web with iText...
The Application Server is runing on WebSphere 6 ND and has 2 network cards..
One is for the local network and the other goes into a Cisco routher..
The users in the local network can print and view the PDF without any problems,
but everyone who logins into the system throw the routher cannot view or print PDF's.
The big question is does anybody knows what port is the iText using to send the data for the PDF on web.
my application is set at port 9080
tnx

Hello All ,
i found the root cause for the above problem....
please help me out...
when i write the code like :
pdfReader = new PdfReader(baos.toByteArray());
writer.addPage(writer.getImportedPage(pdfReader, 2));
writer.addPage(writer.getImportedPage(pdfReader, 1));i can check/uncheck the radio buttons which is in page number 2 and now the page 1 is read only,but when i write
pdfReader = new PdfReader(baos.toByteArray());
writer.addPage(writer.getImportedPage(pdfReader, 1));
writer.addPage(writer.getImportedPage(pdfReader, 2));Now on the page 1 read/write but page 2 i can not.
Any suggestions would be appreciated...
thanks in advance

Similar Messages

  • Problem in merging large collection of PDF  in single pdf at a time-itext

    hi
    i am using itext library for PDF generation.My problem is ,when i merge the large number of PDFs which is already
    generated, in a single PDF ,i got 'Out of Memery' exceptions,but when i doing this with limited number of PDFs
    they are concated as a single PDF .so what shall i do to overcome Out of memory exceptions.because,our client wants to print the mass PDF ,which may have more than 1000 PDFs on a single merged PDF .if any possible,when i merge the single PDF with already merged PDF one by one at a time when it will be generated,how can i handle I/O streams to open one PDF at a time and merge with already generated PDF on the same time,and how can i append the generating PDF directly on already generated PDF using streams
    This is my java code:
    package javaexamples;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import com.lowagie.text.Document;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.pdf.PdfContentByte;
    import com.lowagie.text.pdf.PdfImportedPage;
    import com.lowagie.text.pdf.PdfReader;
    import com.lowagie.text.pdf.PdfWriter;
    public class ConcatPDFs {
              public static void main(String[] args) {
              try {
              List pdfs = new ArrayList();
              Document document     = new Document();
              OutputStream output = new FileOutputStream("E:\\templates\\out\\Merged PDF\\merge.pdf",true);
              PdfWriter writer      = PdfWriter.getInstance(document, output);
              pdfs.add(new FileInputStream("E:\\templates\\out\\07J439HF_FINAL_EVALU.pdf"));
              pdfs.add(new FileInputStream("E:\\templates\\out\\07J440HF_FINAL_EVALU.pdf"))*;*//it may be increased over thousand paths.
              ConcatPDFs.concatPDFs(document,writer,pdfs, true);
              output.flush();
              document.close();
              output.close();
              } catch (Exception e) {
              e.printStackTrace();
              public static void concatPDFs(Document document,PdfWriter writer,List streamOfPDFFiles, boolean paginate) {
              try {
              List pdfs = streamOfPDFFiles;
              List readers = new ArrayList();
              int totalPages = 0;
              java.util.Iterator iteratorPDFs = pdfs.iterator();
              // Create Readers for the pdfs.
              while (iteratorPDFs.hasNext()) {
              InputStream pdf = (FileInputStream)iteratorPDFs.next();
              PdfReader pdfReader = new PdfReader(pdf);
              readers.add(pdfReader);
              totalPages += pdfReader.getNumberOfPages();
              // Create a writer for the outputstream
              document.open();
              BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
              PdfContentByte cb = writer.getDirectContent(); // Holds the PDF
              // data
              PdfImportedPage page;
              int currentPageNumber = 0;
              int pageOfCurrentReaderPDF = 0;
              Iterator iteratorPDFReader = readers.iterator();
              // Loop through the PDF files and add to the output.
              while (iteratorPDFReader.hasNext()) {
              PdfReader pdfReader = (PdfReader)iteratorPDFReader.next();
              // Create a new page in the target for each source page.
              while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
              document.newPage();
              pageOfCurrentReaderPDF++;
              currentPageNumber++;
              page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
              cb.addTemplate(page, 0, 0);
              // Code for pagination.
              if (paginate) {
              cb.beginText();
              cb.setFontAndSize(bf, 9);
              cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "" + currentPageNumber + " of " + totalPages, 520, 5, 0);
              cb.endText();
              pageOfCurrentReaderPDF = 0;
              } catch (Exception e) {
              e.printStackTrace();
              } finally {
                   System.out.println("SUCCESS");
              /*try {
              if (outputStream != null);
              //outputStream.close();
              } catch (IOException ioe) {
              ioe.printStackTrace();
    thanks in advance
    regards
    Oasisdeserts

    thanks for your reply,
    i already tried open and close the output stream and Input Stream to read and write every PDF,but i conflicted that that last PDF only is written in the final merged PDF.so what can i do to this every time the new PDF is to take to merge with already merged PDF.
    i want know about CODE TAGS
    As per your succession,
    for(int i =0 ;i<200;i++){
                   output = new FileOutputStream("E:\\templates\\out\\Merged PDF\\merge.pdf",true);
                   document.open();
                   String value     = "E:\\templates\\out\\07J439HF_FINAL_EVALU.pdf";
                   ConcatPDFs.concatPDFs(document,writer,value, true);
                   output.flush();
                   document.close();
                   output.close();
    thanks
    regards
    Edited by: oasisdesert on Oct 22, 2008 3:03 AM

  • Problem in opening PDF files using Reader 8 when created with iText 2.1.3

    We are facing problem in using IText version 2.1.3. We are using Acrobat Reader 8.1 for viewing the PDF documents. In our Shell program we are splitting and merging the pdf documents using IText. The pdf document works correctly and is readable for documents with one page while it fails for documents with multiple pages.Also please note that it works fine with the older Arcobat reader version say version 7.0 and below but since business has migrated to acrobat higher version we expect IText to work in sync.
    We have already raised a bug with the iText and got the information from them stating that the problem is due to the over nesting of XObjects, which has a threshold value of 50 and was discarded in earlier versions but got flagged in Acrobad Reader 8. Also note that we have reported a bug with the adobe development team.
    We tried working with other Java PDF tools (jPDFProces), to manupulate the pdf files but were facing the same problem. Hence we understand that the problem is with Adobe Reader 8 as the manupulated pages are being viewed in Adobe Reader 7, but fails to read in Adobe Reader 8.
    Kindly provide us with a solution.
    Thanks and Regards,
    Kiran R
    Sonata software.com
    www.sonata-software.com

    Conte Pietro
    [email protected]
    Buon Giorno
    Ho un problema riguardo Adobe Reader.
    La vecchia versione Adobe 8.1.1 non mi apre più i files in formato PDF.
    Ho provato ad installare l'ultima versione Adobe 9 , arriva fino ad un passo dal completamento ma non riesce a terminare. mi da il seguente errore:
    ERROR 1714 The older version of Adobe Reader 9 cannot be removed.
    Contattare l'assistenza!
    Ho cancellato tutti i riferimenti Adobe dal DeskTop, dal Pannello di Controllo e dal FILES Programmi, ma niente!
    Vi sarei grato se potete mandarmi un dettagliato help per riuscire a completare l'installazione.
    Grazie
    [email protected]
    [email protected]

  • Problem signing PDF from smart card - BouncyCastle, IAIK Wrapper, iText

    Hello!
    I need to sign and timestamp a PDF document with a smartcard. I'm using Java 1.6, iText to manage PDF, BouncyCastle to deal with cryptography and the free IAIK WRAPPER to access the smartcard.
    I've already searched the Internet to solve my problem, read the PDF specifications about the signature and followed snippets that should've worked, but after a couple of weeks I still don't have working code, not even for the signature. All the tries I made yield messages like "Signature has been corrupted" or "Invalid signature" (I can't remember the exact messages, but they're not in English anyway :D ) when I verify the signature in Adobe Reader.
    My first goal was to use an encapsulated signature, using filter Adobe.PPKLITE, subfilter adbe.pkcs7.sha1 and a DER-Encoded PKCS#7 object as content.
    Among the tries I made, I used code such as (I don't include all modifications, just the ones I deem closer to the right approach):
         // COMMON - START
         ///// selectedKey is a iaik.pkcs.pkcs11.objects.Key instance of the private key I'm taking from the SC
         RSAPrivateKey signerPrivKey=(RSAPrivateKey)selectedKey;
         CertificateFactory certificateFactory=CertificateFactory.getInstance("X.509");
         ///// correspondingCertificate is a iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate instance of the certificate I'm taking from the SC
         byte[] derEncodedCertificate=correspondingCertificate.getValue().getByteArrayValue();
         X509Certificate signerCert=(X509Certificate)certificateFactory.generateCertificate(new ByteArrayInputStream(derEncodedCertificate));
         Provider provider=new BouncyCastleProvider();
         Security.addProvider(provider);
         ///// session is an instance of iaik.pkcs.pkcs11.Session
         session.signInit(Mechanism.SHA1_RSA_PKCS, signerPrivKey);
         File theFile = new File("C:\\toSign.pdf");
         FileInputStream fis = new FileInputStream(theFile);
         byte[] contentData = new byte[(int) theFile.length()];
         fis.read(contentData);
         fis.close();          
         PdfReader reader = new PdfReader(contentData);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PdfStamper stp = PdfStamper.createSignature(reader, baos, '\0');
         PdfSignatureAppearance sap = stp.getSignatureAppearance();
         // COMMON - END
         java.security.cert.X509Certificate[] certs=new java.security.cert.X509Certificate[1];
         CertificateFactory factory=CertificateFactory.getInstance("X.509");          
         certs[0]=(X509Certificate)factory.generateCertificate(new ByteArrayInputStream(correspondingCertificate.getValue().getByteArrayValue()));
         sap.setSignDate(new GregorianCalendar());
         sap.setCrypto(null, certs, null, null);
         sap.setReason("This is the reason");
         sap.setLocation("This is the Location");
         sap.setContact("This is the Contact");
         sap.setAcro6Layers(true);
         PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_SHA1);
         dic.setDate(new PdfDate(sap.getSignDate()));
         dic.setName(PdfPKCS7.getSubjectFields((X509Certificate)certs[0]).getField("CN"));
         sap.setCryptoDictionary(dic);
         int csize = 4000;
         HashMap exc = new HashMap();
         exc.put(PdfName.CONTENTS, new Integer(csize * 2 + 2));
         sap.preClose(exc);
         MessageDigest md = MessageDigest.getInstance("SHA1");
         InputStream s = sap.getRangeStream();
         int read = 0;
         byte[] buff = new byte[8192];
         while ((read = s.read(buff, 0, 8192)) > 0)
              md.update(buff, 0, read);
         byte[] signature=session.sign(buff);
         CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
         ArrayList list = new ArrayList();
         for (int i = 0; i < certs.length; i++)
              list.add(certs);
         CertStore chainStore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(list), provider);
         generator.addCertificatesAndCRLs(chainStore);
         CMSProcessable content = new CMSProcessableByteArray(md.digest());
         CMSSignedData signedData = generator.generate(CMSSignedDataGenerator.ENCRYPTION_RSA, content, true, provider);
         byte[] pk = signedData.getEncoded();
         byte[] outc = new byte[csize];
         PdfDictionary dic2 = new PdfDictionary();
         System.arraycopy(pk, 0, outc, 0, pk.length);
         dic2.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));
         sap.close(dic2);
         File newOne = new File("C:\\signed.pdf");
         FileOutputStream fos = new FileOutputStream(newOne);
         fos.write(baos.toByteArray());
         fos.close();
    I figured this is the right approach, but I need a way to generate the CMSSignedData instance, which can't be done using addSigner (the only documented way I found), since the private key is not extractable from a smart card...
    Then I decided to give up and try with a detached signature:
         // COMMON - START
         // Same as above
         // COMMON - END
         sap.setSignDate(new GregorianCalendar());
         java.security.cert.X509Certificate[] certs=new java.security.cert.X509Certificate[1];
         CertificateFactory factory=CertificateFactory.getInstance("X.509");          
         certs[0]=(X509Certificate)factory.generateCertificate(new ByteArrayInputStream(correspondingCertificate.getValue().getByteArrayValue()));
         sap.setCrypto(null, certs, null, PdfSignatureAppearance.SELF_SIGNED);
         sap.setSignDate(java.util.Calendar.getInstance());
         sap.setExternalDigest (new byte[8192], new byte[20], "RSA");
         sap.preClose();
         MessageDigest messageDigest = MessageDigest.getInstance ("SHA1");
         byte buff[] = new byte[8192];
         int n;
         InputStream inp = sap.getRangeStream ();
         while ((n = inp.read (buff)) > 0)
              messageDigest.update (buff, 0, n);
         byte hash[] = messageDigest.digest();
         byte[] signature=session.sign(hash);
         PdfSigGenericPKCS sg = sap.getSigStandard ();
         PdfLiteral slit = (PdfLiteral)sg.get (PdfName.CONTENTS);
         byte[] outc = new byte[(slit.getPosLength () - 2) / 2];
         PdfPKCS7 sig = sg.getSigner ();
         sig.setExternalDigest (session.sign(hash), hash, "RSA");
         PdfDictionary dic = new PdfDictionary ();
         byte[] ssig = sig.getEncodedPKCS7();
         System.arraycopy (ssig, 0, outc, 0, ssig.length);
         dic.put (PdfName.CONTENTS, new PdfString (outc).setHexWriting(true));
         sap.close (dic);
         File newOne = new File("C:\\signed.pdf");
         FileOutputStream fos = new FileOutputStream(newOne);
         fos.write(baos.toByteArray());
         fos.close();
    I'm still stuck to the signature process, can anyone please tell me what I'm doing wrong and help me (snippets would be deeply appreciated), maybe even changing approach in order to be able to add a digital timestamp?
    Thank you very much in advance!
    PS: I had also tried to use the SunPKCS11 provider to access the smart card, I gave up for similar problems, but if someone has suggestions using it, they're welcome! :D

    Hello!
    I need to sign and timestamp a PDF document with a smartcard. I'm using Java 1.6, iText to manage PDF, BouncyCastle to deal with cryptography and the free IAIK WRAPPER to access the smartcard.
    I've already searched the Internet to solve my problem, read the PDF specifications about the signature and followed snippets that should've worked, but after a couple of weeks I still don't have working code, not even for the signature. All the tries I made yield messages like "Signature has been corrupted" or "Invalid signature" (I can't remember the exact messages, but they're not in English anyway :D ) when I verify the signature in Adobe Reader.
    My first goal was to use an encapsulated signature, using filter Adobe.PPKLITE, subfilter adbe.pkcs7.sha1 and a DER-Encoded PKCS#7 object as content.
    Among the tries I made, I used code such as (I don't include all modifications, just the ones I deem closer to the right approach):
         // COMMON - START
         ///// selectedKey is a iaik.pkcs.pkcs11.objects.Key instance of the private key I'm taking from the SC
         RSAPrivateKey signerPrivKey=(RSAPrivateKey)selectedKey;
         CertificateFactory certificateFactory=CertificateFactory.getInstance("X.509");
         ///// correspondingCertificate is a iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate instance of the certificate I'm taking from the SC
         byte[] derEncodedCertificate=correspondingCertificate.getValue().getByteArrayValue();
         X509Certificate signerCert=(X509Certificate)certificateFactory.generateCertificate(new ByteArrayInputStream(derEncodedCertificate));
         Provider provider=new BouncyCastleProvider();
         Security.addProvider(provider);
         ///// session is an instance of iaik.pkcs.pkcs11.Session
         session.signInit(Mechanism.SHA1_RSA_PKCS, signerPrivKey);
         File theFile = new File("C:\\toSign.pdf");
         FileInputStream fis = new FileInputStream(theFile);
         byte[] contentData = new byte[(int) theFile.length()];
         fis.read(contentData);
         fis.close();          
         PdfReader reader = new PdfReader(contentData);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PdfStamper stp = PdfStamper.createSignature(reader, baos, '\0');
         PdfSignatureAppearance sap = stp.getSignatureAppearance();
         // COMMON - END
         java.security.cert.X509Certificate[] certs=new java.security.cert.X509Certificate[1];
         CertificateFactory factory=CertificateFactory.getInstance("X.509");          
         certs[0]=(X509Certificate)factory.generateCertificate(new ByteArrayInputStream(correspondingCertificate.getValue().getByteArrayValue()));
         sap.setSignDate(new GregorianCalendar());
         sap.setCrypto(null, certs, null, null);
         sap.setReason("This is the reason");
         sap.setLocation("This is the Location");
         sap.setContact("This is the Contact");
         sap.setAcro6Layers(true);
         PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_SHA1);
         dic.setDate(new PdfDate(sap.getSignDate()));
         dic.setName(PdfPKCS7.getSubjectFields((X509Certificate)certs[0]).getField("CN"));
         sap.setCryptoDictionary(dic);
         int csize = 4000;
         HashMap exc = new HashMap();
         exc.put(PdfName.CONTENTS, new Integer(csize * 2 + 2));
         sap.preClose(exc);
         MessageDigest md = MessageDigest.getInstance("SHA1");
         InputStream s = sap.getRangeStream();
         int read = 0;
         byte[] buff = new byte[8192];
         while ((read = s.read(buff, 0, 8192)) > 0)
              md.update(buff, 0, read);
         byte[] signature=session.sign(buff);
         CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
         ArrayList list = new ArrayList();
         for (int i = 0; i < certs.length; i++)
              list.add(certs);
         CertStore chainStore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(list), provider);
         generator.addCertificatesAndCRLs(chainStore);
         CMSProcessable content = new CMSProcessableByteArray(md.digest());
         CMSSignedData signedData = generator.generate(CMSSignedDataGenerator.ENCRYPTION_RSA, content, true, provider);
         byte[] pk = signedData.getEncoded();
         byte[] outc = new byte[csize];
         PdfDictionary dic2 = new PdfDictionary();
         System.arraycopy(pk, 0, outc, 0, pk.length);
         dic2.put(PdfName.CONTENTS, new PdfString(outc).setHexWriting(true));
         sap.close(dic2);
         File newOne = new File("C:\\signed.pdf");
         FileOutputStream fos = new FileOutputStream(newOne);
         fos.write(baos.toByteArray());
         fos.close();
    I figured this is the right approach, but I need a way to generate the CMSSignedData instance, which can't be done using addSigner (the only documented way I found), since the private key is not extractable from a smart card...
    Then I decided to give up and try with a detached signature:
         // COMMON - START
         // Same as above
         // COMMON - END
         sap.setSignDate(new GregorianCalendar());
         java.security.cert.X509Certificate[] certs=new java.security.cert.X509Certificate[1];
         CertificateFactory factory=CertificateFactory.getInstance("X.509");          
         certs[0]=(X509Certificate)factory.generateCertificate(new ByteArrayInputStream(correspondingCertificate.getValue().getByteArrayValue()));
         sap.setCrypto(null, certs, null, PdfSignatureAppearance.SELF_SIGNED);
         sap.setSignDate(java.util.Calendar.getInstance());
         sap.setExternalDigest (new byte[8192], new byte[20], "RSA");
         sap.preClose();
         MessageDigest messageDigest = MessageDigest.getInstance ("SHA1");
         byte buff[] = new byte[8192];
         int n;
         InputStream inp = sap.getRangeStream ();
         while ((n = inp.read (buff)) > 0)
              messageDigest.update (buff, 0, n);
         byte hash[] = messageDigest.digest();
         byte[] signature=session.sign(hash);
         PdfSigGenericPKCS sg = sap.getSigStandard ();
         PdfLiteral slit = (PdfLiteral)sg.get (PdfName.CONTENTS);
         byte[] outc = new byte[(slit.getPosLength () - 2) / 2];
         PdfPKCS7 sig = sg.getSigner ();
         sig.setExternalDigest (session.sign(hash), hash, "RSA");
         PdfDictionary dic = new PdfDictionary ();
         byte[] ssig = sig.getEncodedPKCS7();
         System.arraycopy (ssig, 0, outc, 0, ssig.length);
         dic.put (PdfName.CONTENTS, new PdfString (outc).setHexWriting(true));
         sap.close (dic);
         File newOne = new File("C:\\signed.pdf");
         FileOutputStream fos = new FileOutputStream(newOne);
         fos.write(baos.toByteArray());
         fos.close();
    I'm still stuck to the signature process, can anyone please tell me what I'm doing wrong and help me (snippets would be deeply appreciated), maybe even changing approach in order to be able to add a digital timestamp?
    Thank you very much in advance!
    PS: I had also tried to use the SunPKCS11 provider to access the smart card, I gave up for similar problems, but if someone has suggestions using it, they're welcome! :D

  • Problem with iText pageEvent.

    I am creating a PDF document using iText and writing some tables to it.
    On page end event of PDFWriter I am creating footer. method :onEndPage(PdfWriter pdfwriter, Document document)
    My problem is that this event is getting called twice.
    so some tables are cut even if whole page is available and they are being written to new page.
    Can anybody pls help me why this happens.?

    Srikant,
    If the code compiled OK and failed with this error at runtime then perhaps the JAR file containing com.trend.iwss.jscan.appscan.runtime.PolicyProps Class is older than the one you compiled the code with.
    You could locate the .JAR file using the Class Finder tool, and deploy it as part of your code as a library.
    Cheers,
    Steve

  • Problem while generating PDF using iText

    Hi:
    I have generated PDF using iText, where i have written all code in sequential flow.
    <code>
    com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.A4, 55, 5, 20, 20);
    OutputStream outputstream = response.getOutputStream();
    PdfWriter.getInstance(document,outputstream);
    </code>
    And i have added all fields in the document.
    But my problem is how to display total pagecount on all pages e.g.1\20 (because i have generated PDF sequentially)
    Also i want to add watermark on all pages.
    So, can any body help me to solve this problem?
    Thank You,
    Balaji

    sabre150 wrote:
    Maybe http://itext-general.2136553.n4.nabble.com/
    Nice pron link in there :/

  • Problem while rendering report generated with iText API

    Hi!
    I am stuck with problem of rendering report generated through iText API.
    What exactly happens is, I have to put an image (.jpg) on my report, when I am generating HTML file using iText API, the image size is normal i.e., as it is taken.
    But when I render it to take print through printer, the size of image is getting short i.e., it prints like an Icon on Paper. What can I do to get the proper image size on paper also?
    The code is as follows, which I have used to render
    public class HTMLPrintRenderer implements Printable {
        ReportAbs objReport;
        JEditorPane editorPane;
        String fileName;
        final int STARTING_PAGESET_NUMBER=0;
        int currentPageSetNumber=STARTING_PAGESET_NUMBER;
        /** Creates a new instance of HTMLPrintRenderer */
        public HTMLPrintRenderer(ReportAbs  objReport) throws Exception{
            this.objReport=objReport;
            this.fileName=ReportsUtility.getReportLocation()+ objReport.getReportFileName();
            if(objReport.isLayoutLandscape()){
                SCALE =600.0/1000;//600.0/850;
            else{
                SCALE =600.0/850;
            init();
        private void init()throws Exception{
            setDocument(STARTING_PAGESET_NUMBER);
        public void setDocument(int pageSetNumber) throws Exception{
            editorPane=new JEditorPane();
            ((AbstractDocument)editorPane.getDocument()).setAsynchronousLoadPriority(-1);
            editorPane.setText("text/html");
            editorPane.setPage("file:"+fileName+"."+pageSetNumber);
            currentPageSetNumber=pageSetNumber;
        int pageCountInPageSet=0;// counter to track number of pages in each pageSet
        int currentPage=-1;
        double pageStartY=0,pageEndY=0;
        final double SCALE;// =600.0/1000;//600.0/850;
        final int HEADER_HEIGHT=30;//50;
        final int FOOTER_HEIGHT=70;
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            Graphics2D graphics2D;
            graphics2D = (Graphics2D) graphics;
            initEditorPane(editorPane,pageFormat);
            ReportPrinterUtility.printPageAttributes(pageFormat);
            /// print custom here... page numbers and page headers may be printed here
            /// meant only for HEADRS and FOOTERS
            ///                 caution... DO NOT ALTER GRAPHICS OBJECT ATTRIBUTES
            /// @author Manoj       
            //TRANSLATE..............must also be reverse translated
            double x=pageFormat.getImageableX();
            double y=pageFormat.getImageableY();
            graphics2D.translate(x,y);
            paintCustomPage(graphics2D,pageFormat);
            //REVERSETRANSLATE
            graphics2D.translate(-x,-y);
            graphics2D.scale(SCALE,SCALE);
            //  V set clipping area
            int headerHeight=HEADER_HEIGHT;
                graphics2D.setClip((int)(pageFormat.getImageableX()/SCALE),
                (int) ((pageFormat.getImageableY()+headerHeight)/SCALE),
                (int) (pageFormat.getImageableWidth()/SCALE),
                (int) ((pageFormat.getImageableHeight()-FOOTER_HEIGHT)/SCALE));
            //  VI set pageStart on editorPane
            if (pageIndex > currentPage) {
                currentPage = pageIndex;
                pageStartY += pageEndY;
                pageEndY = graphics2D.getClipBounds().getHeight();
                pageCountInPageSet++;
            //  VII
            graphics2D.translate(graphics2D.getClipBounds().getX(),
            graphics2D.getClipBounds().getY());
            //  VIII prepare clipping area
            Rectangle allocation = new Rectangle(0,
            (int) -pageStartY,
            (int) (editorPane.getMinimumSize().getWidth()),
            (int) (editorPane.getPreferredSize().getHeight()));
            View rootView=editorPane.getUI().getRootView(editorPane);
            if (printView(graphics2D,allocation,rootView)) {//page exists          
                System.out.println("page exists"+pageCountInPageSet);
                return Printable.PAGE_EXISTS;
            else {// page does not exist
                System.out.println("resetting page parameters");
                pageStartY = 0;
                pageEndY = 0;
                currentPage = -1;
                if(!setupNextPage()){///more pages exist TODO:
                    return Printable.NO_SUCH_PAGE;
                else{//no more pages exist
                    //                call next page
                    pageCountInPageSet=0;//reset to first page in pageSet
                    resetGraphics(graphics2D,pageFormat);
                    return print(graphics2D,pageFormat,pageIndex);
    private void resetGraphics(Graphics2D graphics2D,PageFormat pFormat){
            graphics2D.clearRect(0,0,
            (int)(pFormat.getImageableWidth()/SCALE),
            (int)(pFormat.getImageableHeight()/SCALE));
            graphics2D.translate(-graphics2D.getClipBounds().getX(),
            -graphics2D.getClipBounds().getY());
            graphics2D.scale(1/SCALE, 1/SCALE);
        }

    Hi!
    I am stuck with problem of rendering report generated through iText API.
    What exactly happens is, I have to put an image (.jpg) on my report, when I am generating HTML file using iText API, the image size is normal i.e., as it is taken.
    But when I render it to take print through printer, the size of image is getting short i.e., it prints like an Icon on Paper. What can I do to get the proper image size on paper also?
    The code is as follows, which I have used to render
    public class HTMLPrintRenderer implements Printable {
        ReportAbs objReport;
        JEditorPane editorPane;
        String fileName;
        final int STARTING_PAGESET_NUMBER=0;
        int currentPageSetNumber=STARTING_PAGESET_NUMBER;
        /** Creates a new instance of HTMLPrintRenderer */
        public HTMLPrintRenderer(ReportAbs  objReport) throws Exception{
            this.objReport=objReport;
            this.fileName=ReportsUtility.getReportLocation()+ objReport.getReportFileName();
            if(objReport.isLayoutLandscape()){
                SCALE =600.0/1000;//600.0/850;
            else{
                SCALE =600.0/850;
            init();
        private void init()throws Exception{
            setDocument(STARTING_PAGESET_NUMBER);
        public void setDocument(int pageSetNumber) throws Exception{
            editorPane=new JEditorPane();
            ((AbstractDocument)editorPane.getDocument()).setAsynchronousLoadPriority(-1);
            editorPane.setText("text/html");
            editorPane.setPage("file:"+fileName+"."+pageSetNumber);
            currentPageSetNumber=pageSetNumber;
        int pageCountInPageSet=0;// counter to track number of pages in each pageSet
        int currentPage=-1;
        double pageStartY=0,pageEndY=0;
        final double SCALE;// =600.0/1000;//600.0/850;
        final int HEADER_HEIGHT=30;//50;
        final int FOOTER_HEIGHT=70;
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            Graphics2D graphics2D;
            graphics2D = (Graphics2D) graphics;
            initEditorPane(editorPane,pageFormat);
            ReportPrinterUtility.printPageAttributes(pageFormat);
            /// print custom here... page numbers and page headers may be printed here
            /// meant only for HEADRS and FOOTERS
            ///                 caution... DO NOT ALTER GRAPHICS OBJECT ATTRIBUTES
            /// @author Manoj       
            //TRANSLATE..............must also be reverse translated
            double x=pageFormat.getImageableX();
            double y=pageFormat.getImageableY();
            graphics2D.translate(x,y);
            paintCustomPage(graphics2D,pageFormat);
            //REVERSETRANSLATE
            graphics2D.translate(-x,-y);
            graphics2D.scale(SCALE,SCALE);
            //  V set clipping area
            int headerHeight=HEADER_HEIGHT;
                graphics2D.setClip((int)(pageFormat.getImageableX()/SCALE),
                (int) ((pageFormat.getImageableY()+headerHeight)/SCALE),
                (int) (pageFormat.getImageableWidth()/SCALE),
                (int) ((pageFormat.getImageableHeight()-FOOTER_HEIGHT)/SCALE));
            //  VI set pageStart on editorPane
            if (pageIndex > currentPage) {
                currentPage = pageIndex;
                pageStartY += pageEndY;
                pageEndY = graphics2D.getClipBounds().getHeight();
                pageCountInPageSet++;
            //  VII
            graphics2D.translate(graphics2D.getClipBounds().getX(),
            graphics2D.getClipBounds().getY());
            //  VIII prepare clipping area
            Rectangle allocation = new Rectangle(0,
            (int) -pageStartY,
            (int) (editorPane.getMinimumSize().getWidth()),
            (int) (editorPane.getPreferredSize().getHeight()));
            View rootView=editorPane.getUI().getRootView(editorPane);
            if (printView(graphics2D,allocation,rootView)) {//page exists          
                System.out.println("page exists"+pageCountInPageSet);
                return Printable.PAGE_EXISTS;
            else {// page does not exist
                System.out.println("resetting page parameters");
                pageStartY = 0;
                pageEndY = 0;
                currentPage = -1;
                if(!setupNextPage()){///more pages exist TODO:
                    return Printable.NO_SUCH_PAGE;
                else{//no more pages exist
                    //                call next page
                    pageCountInPageSet=0;//reset to first page in pageSet
                    resetGraphics(graphics2D,pageFormat);
                    return print(graphics2D,pageFormat,pageIndex);
    private void resetGraphics(Graphics2D graphics2D,PageFormat pFormat){
            graphics2D.clearRect(0,0,
            (int)(pFormat.getImageableWidth()/SCALE),
            (int)(pFormat.getImageableHeight()/SCALE));
            graphics2D.translate(-graphics2D.getClipBounds().getX(),
            -graphics2D.getClipBounds().getY());
            graphics2D.scale(1/SCALE, 1/SCALE);
        }

  • Problem in Running a Webdynpro Application Which uses itext.jar

    Hi,
    I have created a Webdynpro DC which uses a DC called xxx_lib which contains the external JAR Files. (itext.jar etc)
    This JAR file is in my library path as well.
    I have added the lib_dc as used DC under the webdynpro DC.
    The Compilation and build went fine without any error. But when in run the Application Under ---> Content Administration --> Webdynpro , I am getting the following Error.
    The initial exception that caused the request to fail, was:
    <b>java.lang.NoClassDefFoundError: com/lowagie/text/Element
    Failed to create delegate .....
    (Hint: Is the corresponding DC deployed correctly? Does the DC contain the component?)</b>
    Please let me know if somebody knows the solution.
    Thanks and Regards,
    Sekar

    Hi Sekar,
    Please look into the link below.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7b8180e5-0601-0010-0c94-9bccb92de9c1
    Goto section 2.2.3.1 Defining Libraries Page No. 75
    It gives you the entire process of creating the library DC and referencing the same in your WebDynpro project.
    Hope this helps.
    Regards,
    Rekha Malavathu

  • IText - problems importing library

    Please, somebody help me!
    Why I can't add the iText (PDF) library within an existing WD Project?
    It seems to be fine, until the time I run it and get the error: "java.lang.NoClassDefFoundError: com/lowagie/text/Phrase ".
    PS.: My WD is not a DC, and I can't change it.
    Thanks !!
    Fabio

    Hi Maksim,
    I didn't understand very well what you said with "It MUST contain "library:" prefix".
    In the Visual Administrator, my library has the name "itext".
    In my project, I've tried everything:
    Sharing Reference: itext
    Sharing Reference: library:itext
    Library Reference: library:text
    But when I deploy, it gives the message "The referenced application can't be started".
    Only when I put "Library Reference: itext" it deploys ok, but still gives the message "java.lang.NoClassDefFoundError: com/lowagie/text/Phrase", on run-time.
    May I have done something wrong??
    Can I create everything again?
    Thank you!
    Regards

  • Problem on print a report in mode character

    hi, i have oracle 8i and reports 6i, my reports it's generate in mode character, when i send to print (printer epson fx1180), the print is bad, (i configure the prt files example: bold esc "E", Unbold esc "F"),
    MY problem is with windows 2000, i send to print on windows 98 and all good, but now i have windows 2000, anybody help me to config the printers file for windows 2000

    You can create a PDF file using the [itext |http://www.lowagie.com/iText/] library
    you can create reports using jasperreports
    you can print the reports and save them as PDF,EXCEL ,HTML and more...
    (jasperreports is using the [itext |http://www.lowagie.com/iText/] library )
    you can edit your reports using ireport
    hope that helps

  • How to construct checkbox in rtf document using iText?

    Hi fiends
    I am developing a rtf document usng iText api ,I am facing problem when i want to draw a check box in the document so is there any way using iText only to draw a checkbox in rtf document?Or iText doesn't allow construct checkbox?please suggest.An example will be appreciated.Thanks in advance.
    Regards soumyanil

    For your kind information this is a site that provides support for JAVA programming and JAVA Servlets related questions.
    You need some information regarding a third party API, so please dont hesitate to contact your vendor.
    The vendor URL: http://itextdocs.lowagie.com/
    The tutorial you need to learn before starting iText is http://itextdocs.lowagie.com/tutorial/
    All the best!

  • Problem with Non-English Fields Output to PDF by JASPER in JDev10.1.3

    I am using jsprx files(designed in i-report) to generate pdf reports out of an oracle database.
    The non-English fields are shown correctly when I output the report into an HTML or when I view it with JasperView.
    If I try making PDF files (JasperExportManager.exportReportToPdfFile) the static fields containing e.g.Arabic/Chineese characters won't be displayed and dynamic fields from the database with non-English contents will be shown as ??? or null.
    I received some suggestions about using PARAMETERS to feed the report instead of FIELDS, which I think can not be helpful in this case and in general.
    I think this should be a common problem. These are the components I am using:
    itext-1.4.7. jar
    commons-digester- 1.7.zip
    jasperreports- 1.2.8.jar
    Any comment or help is appreciated.
    Thanks
    Farbod

    I am using jsprx files(designed in i-report) to generate pdf reports out of an oracle database.
    The non-English fields are shown correctly when I output the report into an HTML or when I view it with JasperView.
    If I try making PDF files (JasperExportManager.exportReportToPdfFile) the static fields containing e.g.Arabic/Chineese characters won't be displayed and dynamic fields from the database with non-English contents will be shown as ??? or null.
    I received some suggestions about using PARAMETERS to feed the report instead of FIELDS, which I think can not be helpful in this case and in general.
    I think this should be a common problem. These are the components I am using:
    itext-1.4.7. jar
    commons-digester- 1.7.zip
    jasperreports- 1.2.8.jar
    Any comment or help is appreciated.
    Thanks
    Farbod

  • Memory Allocation Problems

    My application seems to not free resources the way I would like it to. The main interface consumes somewhere around 40MB. The application has an option to export data to a few PDFs (via itext and JFreeChart). This is handled through a popup JFrame where the user can select options for export. During the export, memory usage spikes to near 105MB, which though concerning, isn't the main problem. Once the export JFrame has been disposed and control is returned the main window, memory usage stays at ~ 105MB and if you export again, the memory usage doesn't budge, leading me to believe that the Objects used during the export aren't being released. I know that memory management is temperamental in Java, but I can't figure out what's going on here.
    Here is an overview of what's happening:
    MainViewer -> SaveView -> ExportFileController:
    I am currently exporting two PDFs: One containing graphs created by JFreeChart and another containing a table created by itext. I've tested them independently and both seem to stay in memory even after I've called document.close() and SaveView.dispose().
    Here is how I'm writing my charts:
    public void writeCharts()
              Iterator chartIter = allCharts.iterator();
              try
                   System.out.println("Writing Charts: Total Number: " + allCharts.size());
                   String outputFile = outputDir.getPath()+"/curvefits.pdf";               
                   writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
                   document.open();
                   while(chartIter.hasNext())               
                        numpages++;
                        JFreeChart currentChart = (JFreeChart)chartIter.next();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(width, height);
                        Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
                        Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
                        System.out.println("Writting Chart: " + currentChart.getTitle().getText());          
                        currentChart.draw(g2d, r2d);
                        g2d.dispose();
                        cb.addTemplate(tp, 0, 0);
                        document.newPage();
                        writer.releaseTemplate(tp);  //I had heap errors before I added this
              catch(Exception e)
                   e.printStackTrace();
              document.close();
              writer.flush();
              writer.close();
              allCharts.clear();
              allCharts.trimToSize();          
              System.gc();    //I'm explicitly trying to free up the resources here
              System.runFinalization();
    }

    warnerja wrote:
    Hard to say.
    Once it loads classes, it won't give that memory back, but any memory used on the heap which is no longer needed may be reclaimed.
    Does it keep climbing on repeated exports, or does it basically peak on one export and remain at that usage level upon repeated exports?It peaks on one export and then remains the same on repeated exports (roughly ~105MB). What scares me is the my test set is relatively small (perhaps as small as 1%) of what this application could be used for. I can do some things to minimize memory usage (like writing one page at a time and then appending so I don't have to keep the whole output stream open) at the expense of speed, but some where there has to be a data structure containing all of the items to be written. If the JVM NEVER gives the memory back then this will pretty much cripple the user's system.

  • Arabic text in my web application using iText..

    Hey Guys,
    I'm using the iText library to produce PDF reports in my web application; platform (ADF 11g and Weblogic 10g). I'm having a problem with rendering arabic text on the page, is there a way to print arabic text outside of a PdfPTable ?? I need to print a simple text like the title of the report , the subtitle and so on... please guys I need an answer...
    Thanks in advance.
    AccadSoft

    gimbal2 wrote:
    sabre150 wrote:
    AccadSoft wrote:
    please guys I need an answer.To get answers about using iText I use "iText In Action, 2nd edition" by the prime author of iText - Bruno Lowagie.Classic way to make money - make the API free and sell the documentation. Also an honorable way to make money IMO.I was using iText before 2004 when the first edition of the book came out ( 4 years or so after the library was first introduced) and it was hard work. PDF is a very complex document format and just using the Javadoc does not really get you anywhere. There are many 'gotchas' in iText and most of the iText tutorials cover only the very basics and pretty much none of the 'gochas'. The book starts off with very simple examples that could be constructed from the Javadoc but then it does move on to the more complex issues. Worth every penny.

  • How to write special characters in PDF using iText

    How to write special characters encoded with UTF-8 in PDF using iText.
    Regards,
    Pandharinath.

    I don't know what your problem is but that's almost certainly the wrong question to ask about it. Java (including iText) uses only Unicode characters. (You may consider some of them to be "special" if you like but Unicode doesn't.) And when it does that, they aren't encoded in UTF-8 or any other encoding.
    So can you describe your problem? That question doesn't make sense.

Maybe you are looking for

  • Concept of free –m command in Linux

    I wanted to know the concept of free –m command as there are different rows of Mem, -/+ buffers/cache & Swap in the output. As an example, it is showing 195 as free Mem in my server but 13850 in the free section of the -/+ buffers/cache. The output n

  • How to list the content of a URL

    Hi All, I am wondering whether the method of listing the content of a URL, is the same as listing a directory on a local system? The listing of a local directory can be achieved with the following code for example:     File dir = new File("directoryN

  • GETWA_NOT_ASSIGNED dump in sap

    Hi experts, I have a problem with ALV list. The case is like below. I added a new field that length is 6 with CHAR type.It was okay. There was no problem with just adding a field. I added thefield with the attribute "EDIT = 'X'".In this case, the GET

  • Imported cd then have more than one album?!

    this is a bit annoying... I burnt one cd onto my itunes and now I have one album with about 20 songs in it and then a few more albums with only 1 song in it... it has tiny varients in names of albums. Please let me know what's the problem! If you nee

  • IPlanet6.1 compatibility with solaris 10

    Hi all, I need to know whether iPlanet 6.1 sp9 32 bit is compatible with solaris 10. Thanks in advance.