title: PDFBox: PDJpeg gets drawn in wrong colors when resized -> Adobe Reader -> Windows XP & 7
body: <p>When creating a PDF using PDFBox and drawing PDJpegs to it, the images' colors are changed / inverted when resizing the PDJpeg(s) before drawing them to the PDF. This issue is only visible on Windows XP and Windows 7 using e.g. Adobe Reader. Preview on Mac or the new PDF preview build in Windows 8 are somehow not affected by this. </p>
  
  <p><strong>Samples:</strong> </p>
  
  <p><a href="http://issues.apache.org/jira/secure/attachment/12575058/Screen%20Shot%20Windows%20XP%20Adobe%20Reader.png" rel="nofollow">Screenshot PDF in Adobe Reader</a> <br>
  <a href="https://issues.apache.org/jira/secure/attachment/12575057/Screen%20Shot%20Mac%20OSX%20Preview.png" rel="nofollow">Same PDF in Mac Preview</a></p>
  
  <p><strong>This is what I do in code:</strong> </p>
  
  <ul>
  <li>Create PDDocument</li>
  <li>Create HashMap of PDJpegs (for caching purpose): 
  <ul>
  <li>Create PDJpegs by BufferedImage initialised through ImageIO.read() </li>
  <li>Resize PDJpegs by calling setHeight() and setWidth() on PDJpegs</li>
  <li>Adding PDJpeg to HashMap</li>
  </ul></li>
  <li>Create PDPage and add it to PDDocument </li>
  <li>Create PDPageContentStream </li>
  <li>Draw some PDJpegs on the PDPage </li>
  <li>Close PDPageContentStream </li>
  <li>Save PDDocument </li>
  <li>Close PDDocument</li>
  </ul>
  
  <p>Method for resizing the PDJpegs:
  <code></p>
  
  <pre><code>private void preparePDFIconCache(List&lt;AbstractDataItem&gt; list) throws IOException {
  
      iconCache = new HashMap&lt;String, PDJpeg&gt;();
  
      for (AbstractDataItem item : list) {
          String iconResourcePath = "/com/graphics/icons/" + item.getIconName();
          URL iconURL = this.getClass().getResource(iconResourcePath);
  
          BufferedImage icon = null;
          if (iconURL != null) {
  
              icon = ImageIO.read(iconURL);
  
          } else {
  
              String myIconResourcePath = SettingsDataModel.getInstance().getMyIconsPath() + File.separator + item.getIconName();
  
              File iconFile = new File(myIconResourcePath);
              if (iconFile.exists()) {
  
                  URL myIconURL = iconFile.toURI().toURL();
  
                  if (myIconURL != null) {
  
                      icon = ImageIO.read(myIconURL);
                  }
              }
  
          }
          if (icon != null) {
  
              PDJpeg pdfIcon = new PDJpeg(currentDocument, icon);
  
              pdfIcon.setHeight(iconWidthXHeight);
              pdfIcon.setWidth(iconWidthXHeight);
  
              iconCache.put(item.getIconName(), pdfIcon);
          }
      }
  }
  </code></pre>
  
  <p></code></p>
  
  <p>If the BufferedImages are resized before initialising the PDJpegs, everything works fine, but they don't look that sharp. </p>
  
  <p>Does anyone have a good solution or experienced the same issue?</p>