Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5882

The pattern created with PDFBox shows inconsistent colors between Safari and Adobe.

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.24, 2.0.32, 3.0.3 PDFBox
    • 2.0.33, 3.0.4 PDFBox, 4.0.0
    • PDModel
    • None

    Description

      The pattern created with PDFBox shows inconsistent colors between Safari and Adobe.

      It appears red in Adobe and Chrome, which is correct.

      It appears blue in Safari, which is incorrect.

      Here is the example code:

      try (PDDocument document = new PDDocument()) {
                  PDPage page = new PDPage();
                  document.addPage(page);
                  
                  try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
                      PDTilingPattern pattern = new PDTilingPattern();
                      pattern.setBBox(new PDRectangle(3, 3));
                      pattern.setPaintType(PDTilingPattern.PAINT_UNCOLORED);
                      pattern.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING);
                      pattern.setXStep(3);
                      pattern.setYStep(3);
                      pattern.setMatrix(Matrix.getScaleInstance(1, 1).createAffineTransform());
                      try (PDPatternContentStream patternContentStream = new PDPatternContentStream(pattern)) {
                          patternContentStream.setLineWidth(0.4f);
                          patternContentStream.moveTo(0, 2);
                          patternContentStream.lineTo(0, 3);
                          patternContentStream.lineTo(2, 3);
                          patternContentStream.lineTo(2, 2);
                          patternContentStream.lineTo(3, 2);
                          patternContentStream.lineTo(3, 0);
                          patternContentStream.lineTo(2, 0);
                          patternContentStream.lineTo(2, 1);
                          patternContentStream.lineTo(1, 1);
                          patternContentStream.lineTo(1, 2);
                          patternContentStream.closePath();
                          patternContentStream.fill();
                      } catch (IOException e) {
                          throw new RuntimeException(e);
                      };
                      COSName patternName = page.getResources().add(pattern);
                      PDPattern pdPattern = new PDPattern(page.getResources(), PDDeviceRGB.INSTANCE);
                      PDColor pdColor = new PDColor(Color.RED.getComponents(null), patternName, pdPattern);
                      contentStream.setNonStrokingColor(pdColor);
                      contentStream.addRect(100, 500, 400, 200);
                      contentStream.fill();
                  }
      
                  document.save("excel_pattern_fill.pdf");
              }
      

      *Safari:*

      Adobe:

      The exported pdf file : excel_pattern_fill.pdf

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            tilman Tilman Hausherr
            berylbai bai yuan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment