pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clifford <cliffo...@paprika-software.com>
Subject Re: PDPattern PDFBOX-1094
Date Thu, 10 Nov 2016 09:46:19 GMT
This is my problem:-

PDPage page = new PDPage();
PDColorSpace cs = PDColorSpace.create(COSName.PATTERN,page.getResources());
//or even dose not matter which one you choose
//PDColorSpace cs = new PDPattern(null, PDDeviceRGB.INSTANCE);
page.getResources().put(COSName.getPDFName("R9"), cs);
COSName cn = page.getResources().add(cs);


The above code is just to prove there is a bug, and I do not do this.

from the above code:-

cn should equal "R9" is dose not it equals "cs2". And there is another 
resource item added.

when using class PDPageContentStream and calling method public void 
setNonStrokingColor(PDColor color) throws IOException

with PDColor having it colour space set too cs from the above code 
inside setNonStrokingColor it calls getName against the colour space for 
PDColor and inside getName it dose the equivalent of the last line of 
code from above

so the code it writes to the PDF file is

q
   /cs2 cs
   0.6 0.89804 0.6 /Patten1 scn
   402.00864 419.82635 68.9668 16.31381 re
   f
Q

which is wrong as it should be
q
   /R9 cs
   0.6 0.89804 0.6 /Patten1 scn
   402.00864 419.82635 68.9668 16.31381 re
   f
Q

inside class PDResources method public COSName add(PDColorSpace 
colorSpace) calls private COSName add(COSName kind, String prefix, 
COSObjectable object) and in this method there is a line  if (dict != 
null && dict.containsValue(object.getCOSObject()))

the object is the original cs (PDColorSpace from above code) and it dose 
is not find a result for getCOSObject() which is the COSArray with the 
COSName.PATTERN in it.


On 10/11/2016 06:19, Tilman Hausherr wrote:
> Slightly simpler version of example, works only with the recent commit 
> that sets the correct defaults for PDTilingPattern:
>
>
>
> import java.io.IOException;
> import java.io.OutputStream;
> import org.apache.pdfbox.cos.COSName;
> import org.apache.pdfbox.cos.COSStream;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDPage;
> import org.apache.pdfbox.pdmodel.PDPageContentStream;
> import org.apache.pdfbox.pdmodel.PDResources;
> import org.apache.pdfbox.pdmodel.common.PDRectangle;
> import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
> import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
> import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
> import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
> import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
> import org.apache.pdfbox.util.Charsets;
>
> /**
>  *
>  * @author Tilman Hausherr
>  */
> public class CreatePatterns
> {
>     public static void main(String[] args) throws IOException
>     {
>         PDDocument doc = new PDDocument();
>         PDPage page = new PDPage();
>         doc.addPage(page);
>         page.setResources(new PDResources());
>
>         PDPageContentStream pcs = new PDPageContentStream(doc, page);
>
>
>         // Colored pattern
>         PDColorSpace patternCS1 = PDColorSpace.create(COSName.PATTERN, 
> page.getResources());
>
>         // Table 75 spec
>         PDTilingPattern tilingPattern1 = new PDTilingPattern();
>         tilingPattern1.setBBox(new PDRectangle(0, 0, 10, 10));
> tilingPattern1.setPaintType(PDTilingPattern.PAINT_COLORED);
> tilingPattern1.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING);
>         tilingPattern1.setXStep(10);
>         tilingPattern1.setYStep(10);
>
>         COSName patName1 = page.getResources().add(tilingPattern1);
>         //TODO Problem: there's no way to create something like a 
> PDPageContentStream
>         OutputStream os1 = 
> tilingPattern1.getContentStream().createOutputStream();
>         os1.write("1 0 0 RG 0 0 m 10 10 l 
> s".getBytes(Charsets.US_ASCII));
>         os1.close();
>
>         PDColor pdColour1 = new PDColor(
>                 new float[0],
>                 patName1,
>                 patternCS1);
>
>
>         pcs.addRect(0, 0, 500, 700);
>         pcs.setNonStrokingColor(pdColour1);
>         pcs.fill();
>
>         // Uncolored pattern
>         PDTilingPattern tilingPattern2 = new PDTilingPattern();
>         tilingPattern2.setBBox(new PDRectangle(0, 0, 10, 10));
> tilingPattern2.setPaintType(PDTilingPattern.PAINT_UNCOLORED);
> tilingPattern2.setTilingType(PDTilingPattern.TILING_NO_DISTORTION);
>         tilingPattern2.setXStep(10);
>         tilingPattern2.setYStep(10);
>
>         COSName patName2 = page.getResources().add(tilingPattern2);
>         OutputStream os2 = 
> tilingPattern2.getContentStream().createOutputStream();
>         os2.write("0 10 m 10 0 l s".getBytes(Charsets.US_ASCII));
>         os2.close();
>
>         PDColorSpace patternCS2 = new PDPattern(null, 
> PDDeviceRGB.INSTANCE); //TODO weird - factory can't be used?
>         PDColor pdColour2 = new PDColor(
>                 new float[]{0,1,0},
>                 patName2,
>                 patternCS2);
>
>
>         pcs.addRect(100, 100, 500, 500);
>         pcs.setNonStrokingColor(pdColour2);
>         pcs.fill();
>
>
>         pcs.close();
>         doc.save("patterns.pdf");
>         doc.close();
>     }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

-- 

*Kind regards*

*Clifford Dann
Paprika*


T +44 (0)1732 811601
www.paprika-software.com <https://www.paprika-software.com%3C>
Latters House, High Street, Hadlow, Tonbridge, Kent, TN11 0EF, United 
Kingdom

Agency Software Worldwide Ltd.    Registered in England and Wales 01665695


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message