title: How set page size to European A4 in itext
body: <p>I am using the following code to merge pdf. But it is giving me a margin problem. It is leaving more margin on top, left &amp; bottom &amp; less margin in right then the original document.
  i tried to set margins also but it did not work.
  please help me out with this
  or can u help me set page size to European A4</p>
  
  <pre><code> public class Pdf_Merge {
    public static void main(String[] args) {
      try {
        List&lt;InputStream&gt; pdfs = new ArrayList&lt;InputStream&gt;();
        pdfs.add(new FileInputStream("file1.pdf"));
        pdfs.add(new FileInputStream("file2.pdf"));
        OutputStream output = new FileOutputStream("Output_file.pdf");
        System.out.println("Created");
        Pdf_Merge.concatPDFs(pdfs, output, true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  
    public static void concatPDFs(List&lt;InputStream&gt; streamOfPDFFiles, OutputStream    
    outputStream, boolean paginate) {
  
      Document document = new Document(PageSize.A4);
      try {
      List&lt;InputStream&gt; pdfs = streamOfPDFFiles;
      List&lt;PdfReader&gt; readers = new ArrayList&lt;PdfReader&gt;();
      int totalPages = 0;
      Iterator&lt;InputStream&gt; iteratorPDFs = pdfs.iterator();
  
      // Create Readers for the pdfs.
        while (iteratorPDFs.hasNext()) {
          InputStream pdf = iteratorPDFs.next();
          PdfReader pdfReader = new PdfReader(pdf);
          readers.add(pdfReader);
          totalPages += pdfReader.getNumberOfPages();
        }
        // Create a writer for the outputstream
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
  
  
        document.open();
  
        PdfContentByte cb = writer.getDirectContent(); // Holds the PDF
     // data
  
        PdfImportedPage page;
        int currentPageNumber = 0;
        int pageOfCurrentReaderPDF = 0;
        Iterator&lt;PdfReader&gt; iteratorPDFReader = readers.iterator();
  
    // Loop through the PDF files and add to the output.
        while (iteratorPDFReader.hasNext()) {
          PdfReader pdfReader = iteratorPDFReader.next();
  
      // Create a new page in the target for each source page.
          while (pageOfCurrentReaderPDF &lt; pdfReader.getNumberOfPages()) {
            document.newPage();
            pageOfCurrentReaderPDF++;
            currentPageNumber++;
            page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
            cb.addTemplate(page, 0, 0);
  
         // Code for pagination.
            if (paginate) {
            cb.beginText();
            cb.endText();
  
           }
         }
          pageOfCurrentReaderPDF = 0;
       }
        outputStream.flush();
  
        document.close();
        outputStream.close();
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (document.isOpen())
         document.close();
        try {
          if (outputStream != null)
           outputStream.close();
        } catch (IOException ioe) {
          ioe.printStackTrace();
        }
      }
    }
  }
  </code></pre>