[
https://issues.apache.org/jira/browse/PDFBOX-5882?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17887515#comment-17887515
]
Tilman Hausherr edited comment on PDFBOX-5882 at 10/8/24 8:28 AM:
------------------------------------------------------------------
That's because {{Color.RED.getComponents(null)}} returns a 4 component array,
which includes the alpha, so this appears as {{1 0 0 1 /p1 scn}} in the PDF (4
components instead of 3). I suspect Safari uses the last 3 components, while
the others including PDFBox use the first 3. Use {{new float[] \{1,0,0\}}}
instead.
was (Author: tilman):
That's because {{Color.RED.getComponents(null)}} returns a 4 component array,
which includes the alpha, so this appears as {{1 0 0 1 /p1 scn}} in the PDF (4
components instead of 3). I suspect Safari uses the last 3 components, while
the others including PDFBox use the first 3. Use {{new float[] {1,0,0}}}
instead.
> The pattern created with PDFBox shows inconsistent colors between Safari and
> Adobe.
> -----------------------------------------------------------------------------------
>
> Key: PDFBOX-5882
> URL: https://issues.apache.org/jira/browse/PDFBOX-5882
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.24
> Reporter: bai yuan
> Priority: Major
> Attachments: excel_pattern_fill.pdf,
> image-2024-10-08-16-04-32-344.png, image-2024-10-08-16-04-49-033.png
>
>
> 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:
> {code:java}
> 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");
> }
> {code}
> **Safari:**
> !image-2024-10-08-16-04-32-344.png!
> Adobe:
> !image-2024-10-08-16-04-49-033.png!
> The exported pdf file : excel_pattern_fill.pdf
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]