How read a pdf file and change TableCell height after reading it using itext api

I have created a pdf form file using itext ( see class CreatingFormClass ) with itext PdfPTable and PdfPCell. It is done successfully .
Now I  read this pdf file and filling this pdf file(see class FillingFormClass  ) and at this point i want to change  PdfPCell height () according to Items.
It is possible or Not???
My code is given below.
Thanx in advance
public class FillPdfFormMainClass {
public static  String RESULT1 = "E:/BlankForm.pdf";
    public static  String RESULT2 = "E:/FilledForm.pdf";
    public static void main(String[] args) throws DocumentException, IOException {
        String empName="Rakesh Kumar Verma";
                // This part is Dynamic. It can be 1 item Or can be 25 items
        String listOfItem="Item 1 \n Item 2 \n Item 3\n Item 4 \n Item 5 \n Item 6 \n Item 7 \n Item 8 \n Item 9";
        CreatingFormClass example = new CreatingFormClass(0);
        example.createPdf(RESULT1);
        FillingFormClass class1 = new FillingFormClass();
        class1.manipulatePdf(RESULT1, RESULT2,empName,listOfItem);
public class CreatingFormClass implements PdfPCellEvent {
    protected int tf;
    public CreatingFormClass(int tf) {
        this.tf = tf;
    public void createPdf(String filename) throws DocumentException, IOException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfPCell cell;
        PdfPTable table = new PdfPTable(2);
        table.setWidths(new int[]{1, 2});
        table.addCell("Name:");
        cell = new PdfPCell();
        cell.setCellEvent(new CreatingFormClass(1));
        table.addCell(cell);
        table.addCell("Item List:");
        cell = new PdfPCell();
        cell.setCellEvent(new CreatingFormClass(2));
        cell.setFixedHeight(60);
        table.addCell(cell);
        document.add(table);
        document.close();
    public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
        PdfWriter writer = canvases[0].getPdfWriter();
        TextField text = new TextField(writer, rectangle, String.format("text_%s", tf));
        text.setBackgroundColor(new GrayColor(0.95f));
        switch (tf) {
            case 1:
                text.setText("Enter your name here...");
                text.setFontSize(8);
                text.setAlignment(Element.ALIGN_CENTER);
                break;
            case 2:
                text.setFontSize(8);
                text.setText("Enter Your Address");
                text.setOptions(TextField.MULTILINE);
                break;
        try {
            PdfFormField field = text.getTextField();
            writer.addAnnotation(field);
        } catch (IOException ioe) {
            throw new ExceptionConverter(ioe);
        } catch (DocumentException de) {
            throw new ExceptionConverter(de);
public class FillingFormClass {
    public void manipulatePdf(String src, String dest,String empName,String listOfItem) throws IOException, DocumentException {
        PdfReader reader = new PdfReader(src);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(String.format(dest, empName)));
        AcroFields form = stamper.getAcroFields();
        form.setField("text_1", empName);
        form.setField("text_2", listOfItem);
        stamper.close();
        reader.close();

Hi,
I am facing the same problem. Please help me out. I just want to read a PDF file as bytes from one location and write it as another pdf file in some other location with a diolog box prompting to open or save in the location where we want.
I executed the following code:
try{
File report =new File(location);
BufferedInputStream in=new BufferedInputStream(new FileInputStream(report));
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + report.getName());
OutputStream outs = response.getOutputStream();
int readlen;
byte buffer[] = new byte[ 256 ];
while( (readlen = in.read( buffer )) != -1 )
outs.write( buffer, 0, readlen );
outs.flush();
outs.close();
in.close();
response.setStatus(HttpServletResponse.SC_OK);
} catch (FileNotFoundException fileNotFoundException) {
PrintWriter out= response.getWriter();
out.print("<center><Font color = 'RED'><b>"+PxDSLUtils.getApplicationProperty("label.error.CTM_E017")+"</b></Font></center>");
Though it prompts with open, save dialog box when i try to open directly or when i save it some where locally and then open it i am getting the following message " File is repaired ot damaged.Operation failed." Any idea about what can be done??? Its very urgent.Please suggest.
I am not convetin to string just reading and writng as bytes itself.
Thanks in advance,
Mani

Similar Messages

  • Hello, in former Versions it was available to mark text in a pdf file and change it. How do I have

    Hello, in further Versions it was available to mark text in a pdf file and change it. How do I have to act, to do the same in Acrobat XI? Also I need to now, how can I import a graphic file into a pdf to add my handwrote signature or a picture of mine? Please help me soon. It is urgent.

    Moving the discussion to Acrobat Forums

  • Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still us

    Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still use Flash Player...
    Is there anyo who can help me with this? I asked in the shop and I was told "yes of course" , but when I contacted Sony directly I was advised to check with Adobe as apparently in the recent months Adobe and Sony haven't been getting along anymore...

    You may be mixing up two entirely different Adobe products.
    1. Adobe Flash Player. Needed to view web pages designed with Flash. Not needed to view PDF files. Not available for Android (not just Sony).
    2. Adobe Reader. Reads PDF files. However, the Android can also read most PDF files without needing Adobe Reader.

  • I HATE my new MACBOOK PRO, it will not let me open any PDF files and I downloaded the ADOBE READER three freaking times and it keeps saying that all the files are corrupt. I would rather have my 2008 Dell at this point. what is wrong with this thing

    I HATE my new MACBOOK PRO, it will not let me open any PDF files and I downloaded the ADOBE READER three freaking times and it keeps saying that all the files are corrupt or damaged. I would rather have my 2008 Dell at this point. what is wrong with this thing

    Perhaps the PDF files are corrupted.
    Hit the command key and spacebar, a blue Spotlight in the upper right hand corner appears, now type Preview and press return on the Preview program.
    Now you can try opening the PDF's from the file menu and see what's going on.
    If they are corrupted, perhaps they are trojans from your Windows PC or gotten from a bad location online.
    Download the free ClamXav and run a scan on the possibly infected folder.

  • Right clicking PDF files and printing those with Acrobat Reader X

    We have a Windows XP computer with Adobe Acrobat 7 Professional and Acorbat Reader X.
    Now when we open PDF files they open with Acrobat Reader X wich is fine.
    But when we try selecting PDF files and right click Print them they print with Acrobat 7 Professional.
    The problem is with Adobe Acrobat Professional 7 it doesn't print all the files we selected.
    We select 50 files and only about 10 are printed and those are always random.
    So is there anyway to enable the print option to print with Acrobat Reader X ?

    This is not a desirable situation. Adobe recommends against having Reader and Acrobat on the same machine, unless they're both version X, exactly because it can cause this kind of conflicts.

  • How to read in a file and change the column attributes

    Hi,
    I'm new to java and i'm stuggling to find a way to read in a text file and perform calculations on the data, such as to normalise it.
    What in want to do is normalise the data by finding the greatest value in a column and then divide all the other values in the column with that value.
    I know how to read a file in and store each line in a vector but for this problem i think i need to store each column in an array, but i'm not sure how to do this.
    Can anyone help please?
    Thanks

    Hi,
    I'm new to java and i'm stuggling to find a way to
    read in a text file and perform calculations on the
    data, such as to normalise it.
    What in want to do is normalise the data by finding
    the greatest value in a column and then divide all
    the other values in the column with that value.
    I know how to read a file in and store each line in a
    vector but for this problem i think i need to store
    each column in an array, but i'm not sure how to do
    this.
    Can anyone help please?
    ThanksI think this should work but I wrote it out without completely thinking about it (hopefully to get things started).
    So if you had this:
    age height earnings
    0 2 100
    1 3 50
    2 1 0
    For the age column you'd take 2 as the largest and then divide 0 and 1 by two to get 0, .5.
    First build up test files that seperate the columns in different ways. With spaces, tabs, and the ASCI Control character for null ( I think it's 0 ). Your program should detect
    numbers and spaces, tabs control character, commas and periods (for money). Because numbers don't have spaces it should be easy to keep track of which column
    you're in.
    Store each line into a 3D String array with each index containing a String built up from the chars scanned in on each line, when a blank area is found followed by another
    number iterate the column index. When you come to the end of the line set column == 0 and row+1.
    private String[][][] test = new String[2][6][1];
    20     3      11      14      44       0
    4      5       7      80      91      49
    test[0][0][0] would be row 1 col 1 value 1 ((20))
    test[0][1][0] would be r1, c2, v1 ((3))
    test[1][0][0] would be r2, c1, v1 ((4))
    test[1][2][0] would be r2, c3, v1 ((7))
    test[1][5][0] would be r2, c6, v1 ((49))
    package source.Final;
    import javax.swing.*;
    import java.io.*;
    public class S7
         public static void main(String[] args)
              getContents();
              System.exit(0);
         public static void getContents()
              String lineSep = System.getProperty("line.separator");
              char c = ' ';
              int iterator = 0;
              int i = 0;
              int charNum = 1;
              int lineCount = 1;
             //declared here only to make visible to finally clause
             BufferedReader input = null;
             BufferedWriter out = null;
             try {
                         String line = null;
                          * This implementation reads / writes one line at a time
                          * using the buffered reader / writer Java classes.
                         input = new BufferedReader( new FileReader( "C:\\Scan file test\\Read\\test1.txt" ));
                           out = new BufferedWriter( new FileWriter( "C:\\Scan file test\\Read\\test2.txt" ));
                         //input = new BufferedReader( new FileReader( "C:\\Scan file test\\Read\\booked_policies1.txt" ));
                           //out = new BufferedWriter( new FileWriter( "C:\\Scan file test\\Write\\booked_policies1.txt" ));
                         //input = new BufferedReader( new FileReader( "C:\\Scan file test\\Read\\booked_policies2.txt" ));
                           //out = new BufferedWriter( new FileWriter( "C:\\Scan file test\\Write\\booked_policies2.txt" ));
                         //input = new BufferedReader( new FileReader( "C:\\Scan file test\\Read\\booked_policies3.txt" ));
                           //out = new BufferedWriter( new FileWriter( "C:\\Scan file test\\Write\\booked_policies3.txt" ));
                         out.write( "Character\tLine Number\tCharacter Number\tAscii Value" + lineSep );                     
                              while (( line = input.readLine()) != null)
                              i = 0;
                              charNum = 1;
                              iterator = 0;
                              while( i < line.length() )
                                               c = line.charAt(iterator);                                             
                                            if( (int)c == 0 || (int)c == 9 )
                                                 break;
                                            else if( c >= '[' && c <= '_')
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            else if( c <  ' ' )// && (int)c != 0 && (int)c != 9  )
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            else if( c >  ';' && c <= '@' && c != '=')
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            else if( c >= '!' && c < '"' )
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            else if( c >  'z' && c < '~' )
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            else if( c == '%' )
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            else if( c >  '~' )
                                                 {out.write( "["+c+"]\t\t"+"["+lineCount+"]\t\t"+"["+charNum+"]\t\t\t"+"["+(int)(c)+"]"+lineSep );}
                                            charNum += 1;
                                               iterator += 1;
                                               i++;
                                    lineCount += 1;
             catch (FileNotFoundException ex) {ex.printStackTrace();     System.out.println("File not found.");}
                 catch (IOException ex){ex.printStackTrace();               System.out.println("IO Error.");}
             finally{ try{ if( input != null ) input.close();                if( out != null ) out.close();}
                    catch (IOException ex){ex.printStackTrace();        System.out.println("IO Error #2.");}
        }

  • How to install pdf files and read them in nokia 63...

    tried copyin pdf file in nokia 6300 and tried opening it d phone..but it came as file format not supported..help me..

    sorry, your phone is 6300, idont attention to it.
    your phone dosnt have os(s40) with this information and you cant to install this program.
    General 2G Network GSM 900 / 1800 / 1900
    GSM 850 / 1800 / 1900 - US version
    Announced 2006, November
    Status Available. Released 2007, January
    Size Dimensions 106.4 x 43.6 x 11.7 mm, 56 cc
    Weight 91 g
    Display Type TFT, 16M colors
    Size 240 x 320 pixels, 31 x 41 mm
    - Downloadable wallpapers, screensavers
    Ringtones Type Polyphonic (64 channels), MP3
    Customization Download, order now
    Vibration Yes
    Memory Phonebook 1000 entries, Photocall
    Call records 20 dialed, 20 received, 20 missed calls
    Card slot microSD (TransFlash), up to 2GB, buy memory
    - 7.8 MB of user memory
    Data GPRS Class 10 (4+1/3+2 slots), 32 - 48 kbps
    HSCSD Yes
    EDGE Class 10, 236.8 kbps
    3G No
    WLAN No
    Bluetooth Yes, v2.0
    Infrared port No
    USB Yes, miniUSB
    Features Messaging SMS, MMS, Email, Instant Messaging
    Browser WAP 2.0/xHTML
    Games Yes + Downloadable, order now
    Colors Silver, Black, Red-Silver, White-Silver
    Camera 2 MP, 1600x1200 pixels, video(QCIF)
    - Java MIDP 2.0
    - FM stereo radio
    - Push to talk
    - MP3/MP4/AAC/AAC+/eAAC+ player
    - Voice memo
    - Voice command
    - T9
    - Calendar
    - Calculator
    - Built-in handsfree
    Battery Standard battery, Li-Ion 860 mAh (BL-4C)
    Stand-by Up to 348 h
    Talk time Up to 3 h 30 min
    NOKIA means:Night Of King In Alone

  • How to reassociate PDF files in IE from Acrobat to Reader

    Hi all,
    How can I change program associated to open PDF in Internet Explorer. I have installed both Adobe Reader and Adobe Acrobat and at the moment Acrobat is the one which opens PDFs in IE. I wish to change it to Reader. I have associated PDF files within Reader in windows but IE still seems to remember old setting and open PDFs in Browser window using Acrobat.
    I have Uninstalled Acrobat and then IE opens PDFs in Reader but when I intall Acrobat back IE automatically reverts back to Acrobat. Changed association of PDFs in control panel folder options but still same issue.
    HELP

    For several years I have used this tweak from Reinhard Francke.
    And I have submitted it in this forum several times.
    This registry key decides, which program opens pdf in IE:
    The value shall be the full path to the exe. E.g:
    HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe
    (Default) = "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
    Remarks:
    The example is regarding using the reader (AcroRd32.exe)
    Its not an "official" recommandation to install both Acrobat and Adobe Reader
    By me, I have only used it up to versions 7.
    Good luck.

  • How to remove a hidden text in pdf file with Acrobat Pro 9. How to save pdf file and remove hidden text?

    I
    I made this file in indesign, the highlited empty spaces indicates that their is a hidden text and it pop up when searching for some words in pdf file. so how can I save pdf file to keep only the seen text ???

    Dear lrosenth,
    I went through some codes/suggestions in internet and I found that I need to have cmap file and cid font file for the respective font since pdf doesn't support unicode fonts directly.
    Can you help me to know where can I get cmap file and cid font file for tamil language font Latha(TrueType) microsoft font.
    Regards,
    Safiq

  • I notice the new version does not automoatically fire up Adobe for PDF files and hence I have had to stop using it. How can I fix this, I use Mac

    I did the upgrade and adobe no longer starts up when I load a PDF file. This is frustrating and I have had to stop using Firefox

    https://support.mozilla.com/en-US/kb/Using+the+Adobe+Reader+plugin+with+Firefox
    https://support.mozilla.com/en-US/kb/Opening+PDF+files+within+Firefox

  • How to RENAME the file in UNIX-Appl. server, after READING it?

    Hi Experts,
    Following is my requirement,
    What we are wanting here is the functionality added to this program that once the UNIX file is processed, that it can be closed and then renamed on the Application server with the yyyymmdd extension.  For example, the program reads and processes the My_file.csv file today.  Once it's finished, it then closes the file and renames it as My_file20080610.csv.  By doing this, it will prevent the same file from being run the next day in case the new file is not sent. 
    So, pls. let me know that, How to RENAME is file in the UNIX - Appl. server, after reading it? obviuosly I closes it at the end.
    thanq

    Hi Srinivas,
    You can create a My_file20080610.csv. Write the content from My_file.csv into My_file20080610.csv. Then using DELETE DATASET delete the file My_file.csv.
    Thanks
    Romit

  • On Adobe Acrobat Pro, how do I take a PDF file and convert it into an excel file?

    I am not sure how to take a PDF file and change it into an excel file. I have Adobe Acrobat Pro. Thanks!

    Using Acrobat XI Pro.
    File - Save As Other - Spreadsheet - Microsoft Excel Workbook
    Be well...

  • Default for opening pdf files keeps changing back to 'save file' after I set it to open in firefox

    Since upgrading to the latest Firefox version, my options for opening adobe pdf files have changed. I set it to 'use Adobe Acrobat in Firefox', it works absolutely fine, then some time over the next few days it changes itself back to 'save file'. Then I have to open options and change it again. This happened to me some years back with a much earlier version of Firefox - I can't remember how it was resolved, I think it just stopped doing it after a while. But it is most irritating!

    I echo the request for Help! I've added Options to my Toolbar so I can more easily change "Save File" to "Use Adobe Acrobat (in Firefox)" as the default. Why does Firefox keep reverting to the save file default?

  • Make Acrobat the default reader for pdf-files.

    Since some time (probably after I installed Mavericks) pdf-files are by default opened
    in Preview. To open them in Adobe Acrobat, I can right-click the pdf-file, choose Acrobat,
    and indicate that Acrobat should be the default reader for pdf-files.
    This works, and after logout and login, it does still work.
    But after a reboot, Preview is again the default reader.
    Also, if in Finder I right-click a pdf-file, and via Get Info I configure Acrobat
    to be the default reader for the specific file and all other pdf-files (by clicking
    Change All), this only works for the current session. After a reboot Preview again is the
    default.
    How can I make Acrobat Reader the default reader for pdf-files, and make this setting
    permanent?
    Where is this setting saved?
    Regards,
    Kees.

    I finally solved this, but I still don't understand how.
    To begin with I have 2 hard-drives in my iMac. The OS is on the primary HD, and data are on the secondary drive. My Home directory too is on this secondary HD.
    To check whether the location of the Home directory might be the problem, I copied the Home directory to the primary HD, changed the path in my profile, and did a reboot.
    The next step was to configure Adobe Acrobat as the default reader for pdf-files. To my surprise,  after rebooting, Acrobat still was the default reader for pdf-files.
    So it looks as if this problem has something to do with the location of the Home directory.
    The original Home directory was still present on the secondary  HD,  So the next step was to change in my profile the path to the Home directory again (pointing again to the original Home directory on the second HD), do a reboot and delete the copy of the Home directory on the primary HD.
    So now the situation was back to as it was before: the Home directory on the second HD.
    To my surprise now Acrobat still was the default reader for pdf-files.
    And I could also change the default reader to Preview, and back to Acrobat, and this setting was saved across reboots.
    I'm curious to what solved this problem, and where the setting of the default pdf-reader, or more general, the default application for file types, is stored.
    So I hope that someone who reads this, can shed some light on this.

  • 1.is it possible to read a .xls file and load it into an oracle table

    1.is it possible to read a .xls file and load it into an oracle table, using oracle database or oracle forms i.e. either utl_file, or text_io, or any other oracle tool.
    As far as I know we need a csv file or a txt ( tab delimited) file ?
    2.Are there any windows tools for the same

    Hi,
    If you want to use the DDE package to read the XLS file then yes, you will neeed to know the number of rows and columns in the input file.
    i.e. How will you know :
    1) How many columns are there in the input file.
    If I have a XLS file with the following data :
    R1C1 R1C2 R1C3 R1C4 R1C5 R1C6 R1C7
    xxx xx x
    Where R represents row and C represents column, then how will you know the each row has 7 columns. If you know the answer upfront, then it's not a issue.
    Using the DDE apprach, you will have to specify the RowNum and the ColumnNo of each idividual cells to read/write data from xls sheet.
    Look at the syntax in my ealier post.
    using the other approch (i.e. comma delimited text file - CSV file) , you need not know the number of columns as you can loop thru the input record till the last column is read.
    All you have to do is to look for the 'n' occurances of the field delimiter say ',', do a substr from the current position to the point where the ',' was found.
    This process is to be repeated in a loop till all columns are read.
    The TEXT_IO package can trap for EOF (End Of File).
    Hope I made myself clear.
    -- Shailender Mehta --

Maybe you are looking for