title: Android pdf writer APW high resolution images cause out of memory expection
body: <p>I am using <a href="http://sourceforge.net/projects/apwlibrary/" rel="nofollow">android pdf writer</a>
   (apw) in my app successfully for the most part. However, when I try to include a high resolution in a pdf document, I get an out of memory exception. </p>
  
  <p>Immediately before creating the pdf file, the library must have the content itself converted into a string (representing the raw pdf content), which is then converted to a byte array. The byte array is written to the file in a file output stream (see example via website). </p>
  
  <p>The out of memory expection occurs when the string is generated because representing all the pixels of a bitmap image in string format is very memory intensive. I could downsample the image using the android API, however, it is essential that the images are put into the pdf at high resolution (~2000 x 1000). </p>
  
  <p>There are many scanner type apps which seem to be able to able generate pdf high res images, so there must be a way around it, surely. Granted, they may be using other libraries, but surely there is someone who has figured out a way around it with this library given that it is free and therefore popular(?)</p>
  
  <p>I emailed the developer, but there was no response.</p>
  
  <p>Potential solutions (I can think of) include:</p>
  
  <p>Modifying the library to load a string representing e.g. the first 10% of the PDF, and writing to file chunk by chunk. (edit)</p>
  
  <p>Modifying the library to output a stringoutput stream, or other output stream to a temp file (or final file) as the actual pdf content is being written in the pdfwriter object.</p>
  
  <p>However as a relative java noob (and even more of a pdf specification noob), I am unable to understand the library well enough to do this myself.</p>
  
  <p>Has anyone come across this problem and found a way around it? Anyone willing to hazard a suggestion, or take a look at the library itself even to see if there is a fix of some sort.</p>
  
  <p>Thanks for your help.
  nme32</p>
  
  <p><strong>Edit:</strong> </p>
  
  <ol>
  <li><p>Logcat says heap size is in the range on 40 to 60mb before the crash. I understand (do correct me if not) that Android limits the available memory to apps depending on what else is running, though it is in the 50mb ballpark, depending on device.</p></li>
  <li><p>When loading the image, I think APW essentially converts it to bitmap, that is represents the image pixel by pixel then puts it into string format, meaning it doesn't matter which image format you use, it may as well be bitmap.</p></li>
  </ol>