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

Similar Messages

  • Having trouble merging powerpoint or word files in single PDF in acrobat X professional on mac book pro

    Hi
    I am having trouble merging word and poerpoint files into single PDF by acrobat X professional on a mac book pro. Error says its not supported format. Why is that? It works perfectly on windows. Is the feature of merging office files not enabled in Mac version of software?

    Hi Adam,
    Welcome to the forums. They've really helped my Mac learning-curve since first getting a Mac in late April.
    It sounds to me from reading the different ways you want to use your computer that you would be very well suited for the Macbook. I have the Macbook Pro but I got it about 3 weeks before the Macbooks came out. And I was quite upset. I use my computer mainly for word editing, watching DVDs and picture management. I will have to admit the 15.4" screen is great for side-by-side document editing, but aside from that, I would think that for my needs the Macbook would have been perfect.
    For the money I spent on the low end Macbook Pro I could have gotten the fastest Macbook with 2GB RAM. Instead I have the slowest MBP with only 512MB of RAM which was painfully slow when multitasking. I upgraded to 1GB and it was a huge difference.
    But really... I never use the video card. And since I love the portability of the Macbook Pro, another 2 inches off the body would be AMAZING since the 15" is a little big...
    That's my 2 cents.

  • Break a single pdf into single pdf's

    I have a 250 page pdf.  each page represents a departments information.  Is there a way to break apart that pdf into single pdf's but using part of the file to name the pdf?
    for example, if the first report has a title that contains department 123, I could extract that page and name it department 123.
    The only want I know how to break a pdf into multiple pages is to use the document / extract pages and select Extract pages as seperate files.  But when I do this it uses the name of the exiting file and adds a number to it.
    Also, i was just reading up on creating bookmarks. is there a way to set one bookmark and apply that across all other pages?
    Thanks

    Re extracting and renaming pages: This is done with a script, but it can
    only be done if your pages are consistent and the script can identify the
    text that is to be used for the file name. If you wish, you can send me
    some sample files by email ([email protected]), or share them somewhere and
    post the link here, and I'll let you know if I think it's possible.
    Re bookmarks: What do you mean, exactly? You mean you want to copy&paste a
    bookmark? No, that's not possible. But bookmarks can also be generated with
    a script.

  • Cannot combine PDFs into single PDF in Acrobat XI for Mac

    I've been attempting to combine about 20 PDF files into a single PDF.  When I select this option from the file drop down menu or try and select it after launching Adobe Acrobat Pro, nothing happens.  There are no updates available for this software, so I'm confused as to what's causing the problem.  Thanks for any insight/advice!

    Hey,
    You might try combining the PDF files using 'Create> PDF Portfolio' option and let me know if it works or not.
    Please let me know.
    Regards,
    Anubha

  • Multiple pdfs into single pdf

    Hi All,
    I have a report which output some records. Each selected record will produces a PDF as output.
    When am selecting multiple records other one .... am getting the PDF output one after the other
    instead of getiing in a single PDF.
    Could you please tell me how to proceed with this.
    The LOGIC am using in the program
    Am appending each PDF data using the FM CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    Into an internal table.
    Now,am passing this internal table to the FM GUI_DOWNLOAD
    and again passing this to the FM WS_EXECUTE.
    But the output which am getting is only one PDF(i.e it is overlapping the one pdf data witht he another one).
    Thank you.
    Regards,
    Padmasri.

    Hi,
    Follow these steps,
    get the otf of each output and then append it to the same internal table ( with otf entries of all the pages )
    Then at last convert this otf into PDF.
    To get the OTF format and converting it into PDF there are many threads available in SDN, please search it.

  • How to combine PDFs into a single PDF and preserve links between original PDFs within single PDF

    Acrobat Pro can combine multiple PDF files into one PDF file.
    However, during this process not all links are supported.
    Links within the individual PDF files that are combined seem to work in the single resulting PDF file.
    Links that were between the individual PDF files when combined do not seem to work in the single resulting PDF file.
    Combining the PDF files should support the links that were btween the original individual PDF files in the resulting single PDF file.
    How can this be done?

    Sorry, not possible.

  • Merge Word and PDF to Single PDF via C#

    Hi,
    This sounds like a relatively simple operation and yet I have been unable to find a good code sample that can get this done programattically. I would like to avoid using anything other than the free SDK from Adobe. Basically I just want to take a word document and a PDF document and produce 1 PDF document. Can I do this via the menus in Acrobat - YES, but I need to do it via code in a single step without user interaction. This will be a straightforward client side only app. Can anyone help me here and I apologize in advance is this is too simple.
    Thanks,
    John

    Hi SuneelKumar.
    This forum is to discuss problems of C# development. Your question is not related to the topic of this forum.
    For Asp.net issue
    You'll need to post it in the dedicated ASP.Net Forum
    http://forums.asp.net
    for more efficient responses, where you can contact ASP.NET experts.
    For WPF issue
    You'll need to post it .NET Framework  > Windows Presentation Foundation (WPF)
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Problem Printing to Large Format Printers From SGD

    I am having a problem printing to large format printers when using the PDF printing option for SGD. The SDG Universal PDF Viewer recognizes the print format that I specify but on the client device side the pdf that is produced is always Letter size. If a larger format is speciied the client side pdf displays a small portion of it - almost as if it were clipped at the Letter size. Has anyone experienced this. Is it an SGD problem per se or is it an issue with the Ghostscript configuration and if so is ther a way I can change the config?
    I am running 4.6.2 in an RHEL5 environment. The application server I am primarily working with is Windows Server 2008. The printers I have tried to print larger formats to are HP CLJ 2800 PS (Tabloid size), HP Designjet Z6100 (E size), and HP DesignJet 4020ps(E size). In all cases the plot appears to have been clipped into a Letter size format on the client device side.
    Thanks,
    Edited by: Odog314 on Jul 12, 2012 3:15 PM

    You may have encountered a limitation with the GARO driver, especially if it is connected to the USB port of the Express. We have an iPF8100 but it is connected directly to our network via Ethernet so I've never tested the printer via USB. But if the driver is anything like the consumer inkjet drivers, there is often issues with the driver determining the printer model on the end of the USB and this stops the printer queue creation.
    Have you tried connecting the printer via Ethernet to the Express and then seeing if you can add the printer queue? You will have to set an IP address in the machine if DHCP is not enabled.
    PaHu

  • Merge Files In Single PDF

    I have Acrobat 9 Pro (Windows XP) and am new at using the progam.
    I had merged a few jpegs into a single PDF file but the originals did not remain in its original location in my computer.
    Would someone be able to tell me if this is normal for this program?
    Is there a revert feature to get the originals back?
    Any help is appreciated. Thanks.
    jean

    I added files to the "Merge files into single PDF" menu and then clicked "Combine files". Went back to check in computer file and noticed the originals were not there. Would "combine files" mean deleting them? as I did not click any other button.
    I was able to retrieve my jpegs from the single PDF file by exporting them back to its destination, as Bill said, so I have my originals back.
    Thanks for your help.
    jean

  • How do I create a single PDF file with multiple pages?

    Hi, I occasionally need merge several jpg images into a single pdf file with multiple pages (one Jpg per page). I have tried doing this on Preview, and by selecting all the pages I want to include in my document and trying to save to Pdf through the "Print" function, but every time it only saves the first page.
    Can anyone tell me if there is a way to save multple-page pdf files without having to purchase a specific program (i to this too infrequently to justify the cost)?
    Thanks very much,

    This works for me...
    Open first image in Preview View > Sidebar. Drag the other images into Sidebar, then select all.
    From File menu > print selected images. Choose PDF > Save as PDF
    -mj

  • Multiple documents in single PDF

    Hi. I'm using Adobe Livecycle PDF generator. Is that possible with this product to merge multiple converted documents into a single PDF file?
    Shuold I use Assembler instead? Does Assembler convert the documents into pdf like generator do?

    I think you would need both Assembler and PDF Generator to convert then join. I've wondered the same thing about the PDFG API, but I'm pretty certain it's not possible to perform even simple PDF file joins.
    Perhaps you could look at doing it the other way round? i.e. join the files then convert... (perhaps via postscript or something?)

  • Breaking a pdf into multiple pdf's

    I have a 250 page pdf.  each page represents a departments information.  Is there a way to break apart that pdf into single pdf's but using part of the file to name the pdf?
    for example, if the first report has a title that contains department 123, I could extract that page and name it department 123.
    The only want I know how to break a pdf into multiple pages is to use the document / extract pages and select Extract pages as seperate files.  But when I do this it uses the name of the exiting file and adds a number to it.

    You will have to select a subforum, e.g. Creating, Editing & Exporting PDFs, or Acrobat SDK (since you probably need to write the functionality you want by yourself).

  • Problems merging files into a single PDF

    Hello,
    I have a problem whenever I merge multiple files to one PDF.
    Sometimes the files with smaller images simply lump together onto one page!
    For example, if I merge three files... an 8 1/2" x 11" and two business cards,
    I'll get the 8 1/2" x 11" on the first page, but the two business cards lump
    together on the second page, when I want them separated onto
    page two and three.
    How do I tell Acrobat exactly where I want the files to go when it merges them?
    Thank you!!

    Thank you,
    What happened is, when I told it to create single PDF document from the three images, it behaved as if it made a three page document, by representing each image (including the two business cards)
    in the page view column as a separate page. (good)
    So it showed there, that I had created three pages, and you could click on any one of them in the pages panel column
    But the view of the three images was on two pages, regardless of which page you clicked on in the page view column
    The two business cards are, technically, thrown together on page two.
    If you clicked on page two or three in the page view column, (either business card) you got the same view on "page two", which was one page with the two business cards on it.

  • Merge files in Portfolio into single PDF, preserving order

    Hello, I am using Acrobat X.
    I have ordered a large number of files in a PDF portfolio into a desired sequence.
    Now, to make it easy to print the collection, I would like to merge them into a single PDF. When I use Create>Combine Files into a Single PDF, my sort order is ignored and the files are combined in an alphatebical sort by file name. Now I could repeat the entire process of manual sorting that I undertook in forming the Portfolio in the Combine Files list, but that will be take up a lot of time and doesn't seem like the smart way to do it.
    Can someone suggest how to do this merge the way I want it, automatically?

    I've developed a tool that might help you solve this problem.
    Merge PDF Files in True Numeric Order: http://try67.blogspot.com/2011/05/merge-pdf-files-in-true-numeric-order.html

  • Gaps inbetween letters of full words when Merging files to single PDF (Adobe Acrobat 9.0 Standard)

    I've raised a Bug Report although it says that I may not be contacted so thought someone else might have encountered this issue and hopefully knows what causes it and how to fix. Any advise would be greatly appreciated. Heres a copy of the Bug Report details...
    ******BUG******
    Concise problem statement:
    An intermitent issue is occuring when merging multiple files into a single PDF in Adobe Acrobat 9.0 Standard, the resulting PDF file has gaps inbetween the letters of actual words. For example the word "document" may appear in part of the PDF as "doc ument". This seems to affect various parts of the final PDF file.
    Setup: Windows XP SP2, Adobe Acrobat 9.0, Microsoft Office Standard Edition 2003
    Steps to reproduce bug:
    I am currently unable to replicate the issue on demand but this has happened three times since installing Adobe Acrobat 9.0 a month ago. The most recent occurance happened when merging 6 Microsoft Word Documents. It is a real problem due to the fact that every PDF created needs to be carefully checked and in some cases these PDFs have hundreds of pages.
    The steps used are:
    1) Open Adobe Acrobat 9.0
    2) Click File
    3) Combine
    4) Merge Files into a single PDF
    5) Add Files (select the required files)
    6) Combine Files (which then processes and creates single PDF)
    Results:
    A single PDF is then created and as mentioned is occasionally affected by this issue of random gaps appearing within words.
    Expected results:
    A single PDF with the same formatting and layout as the original files.

    Thanks for the response.
    I have checked though the Word documents that were used in the most recent merge. They don't have any spaces at these areas or strange formatting. I turned on the Show/Hide option to confirm if there was anything odd but I could not see anything. The formatting (Ctrl+D) shows the default font Arial, Regular, font 12.
    The interesting thing is that if it occurs and attempt another file merge the gaps are no longer there. Which makes me think this is unlikely to be the documents and formatting being used and more likely to be a bug in Adobe Acrobat.
    Is there anything else that might be of use to know?

Maybe you are looking for

  • How can i stop firefox from exiting while i'm gathering advertising credits

    '''bold text''I receive hundred's of emails from various websites (members) each time i clik on one of these emails,I receive a certain amount of credits that i use to advertise with or promote my business. I promote through these websites credit mai

  • Help in using  Jasper Report  in JSC !

    Hi, I am new to this forum and Studio creator as well. I made a Web Application with creator.Now i need to make reports of the data in my web application. I have heard of Jasper Report. But I am unable to find out ,from where to start with in Creator

  • How to populate data in the table DBERCHV

    Hi Experts, When I create Bill document, it is not creating entry in table DBERCHV (Consumption History). Is there have any configuration or other way to populate this table with Billing data. Also, I noticed, tables like DBERCHZ1, DBERCHZ3 and DBERC

  • File Browse Item questions..

    Hi all.. Please help me with these questions on ""file_browse"" item. I have a file browse item on a page, like in the following app. http://apex.oracle.com/pls/apex/f?p=62812:1 1) when the user select a file with the browse button,we will get the ""

  • Infotype Screen

    Hi all of you. I developed an infotype of Module PA. this screen has around 130 fields.To enter the data into all of the fields user should scroll the screen.At below i use one checkbox,will let some fields into change mode while checking the box. Af