2011-11-08 9 views
0

私は自分のパフォーマンスプロジェクトの1つとしてPOCをやっています。現在、私はOutOfMemoryErrorに直面しています。最初に、DOMを使用してXMLファイルをロードし、XSLを使用してXMLファイルをPDFに変換しようとしました。このフォーラムのコメントの1つを読んだ後、私はSAXパーサに切り替えましたが、それでも同じエラーが出ます。PDFへのJavaの変換

ファイルは30MB、システムメモリは512MBです。

System.out.println("FOP XMLTOPDFConverter\n"); 
      System.out.println("Preparing..."); 

      // Setup directories 
/*   File baseDir = new File("."); 
      File outDir = new File(baseDir, "out"); 
      outDir.mkdirs();*/ 

      // Setup input and output files 
      File xmlfile = new File("C:/Documents and Settings/agarwgau/Desktop/300k/File_0000036357.XML"); 
      File xsltfile = new File("C:/Documents and Settings/agarwgau/Desktop/300k/UCB110037EventList.xsl"); 
      File pdffile = new File("C:/Documents and Settings/agarwgau/Desktop/300k/ResultXML2PDF.pdf"); 

      System.out.println("Input: XML (" + xmlfile + ")"); 
      System.out.println("Stylesheet: " + xsltfile); 
      System.out.println("Output: PDF (" + pdffile + ")"); 
      System.out.println(); 
      System.out.println("Transforming..."); 

      // configure fopFactory as desired 
      FopFactory fopFactory = FopFactory.newInstance(); 

      FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 
      // configure foUserAgent as desired 

      // Setup output 
      OutputStream out = new java.io.FileOutputStream(pdffile); 
      out = new java.io.BufferedOutputStream(out); 

      try { 
       // Construct fop with desired output format 
       Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, 
         foUserAgent, out); 

       // Setup XSLT 
       TransformerFactory factory = TransformerFactory.newInstance(); 
       Transformer transformer = factory 
         .newTransformer(new StreamSource(xsltfile)); 

       // Set the value of a <param> in the stylesheet 
       transformer.setParameter("versionParam", "2.0"); 

       // Setup input for XSLT transformation 
       Source src = new StreamSource(xmlfile); 

       // Resulting SAX events (the generated FO) must be piped through 
       // to FOP 
       Result res = new SAXResult(fop.getDefaultHandler()); 

       // Start XSLT transformation and FOP processing 
       transformer.transform(src, res); 
      } finally { 
       out.close(); 
      } 

      System.out.println("Success!"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      System.exit(-1); 
     } 

    } 
+0

はサクソンを使用してみましたか? –

+1

どのようなOutOfMemoryエラーですか? 「Java Heap space」?その場合は、-Xms(最小ヒープスペース)と-Xmx(最大ヒープスペース)VM引数を使用してヒープのサイズを拡張することができますか? – Jalayn

+0

私は1024までサイズを増やしてから、Java Heap Space OOMemoryを与えてくれました。私もこれを実装しました –

答えて