Thank you, that worked! Looks like there are some general rules that I need to become familiar with.
-----Original Message----- From: Tilman Hausherr [mailto:[email protected]] Sent: Tuesday, August 5, 2014 5:22 PM To: [email protected] Subject: Re: Gradient paint here's the stream of the correct PDF: 1 0 1 rg 100 100 100 100 re f /sh1 sh incorrect PDF #1: /sh1 sh1 0 1 rg 100 100 100 100 re f incorrect PDF #2: 1 0 1 rg 100 100 100 100 re f /sh1 sh0 0 1 rg 100 200 100 100 re f ===> add a newline or a space after "/sh1 sh" I'll clarify this in the sample code. Tilman Am 05.08.2014 04:56, schrieb Eric Inman: > The code below works for me and the gradient appears. > > However, if I try to fill a rectangle by following > > contentStream.appendRawCommands("/sh1 sh"); > > with > > contentStream.setNonStrokingColor(Color.MAGENTA); > contentStream.fillRect(100,100,100,100); > > then the gradient no longer appears nor does the rectangle. If I put the > rectangle code before the appendRawCommands call, then both the rectangle and > the gradient appear. > > In this simple example, switching the order is an acceptable solution, but in > the real application that I'm working on, I need to do these operations in > either order. Is that possible? > > Thanks > > -----Original Message----- > From: Tilman Hausherr <[email protected]> > Sent: Wed, 16 Jul 2014 04:42:47 GMT > To: [email protected] > Subject: Re: Gradient paint > > For the 1.8 version the code is slightly different: > > PDDocument document = new PDDocument(); > PDPage page = new PDPage(); > document.addPage(page); > > // shading attributes > COSDictionary dict = new COSDictionary(); > dict.setInt(COSName.SHADING_TYPE, 2); > dict.setName(COSName.COLORSPACE, "DeviceRGB"); > COSArray coords = new COSArray(); > coords.add(COSInteger.get(100)); > coords.add(COSInteger.get(400)); > coords.add(COSInteger.get(400)); > coords.add(COSInteger.get(600)); > dict.setItem(COSName.COORDS, coords); > > // function with attributes > COSDictionary fdict = new COSDictionary(); > fdict.setInt(COSName.FUNCTION_TYPE, 2); > COSArray domain = new COSArray(); > domain.add(COSInteger.get(0)); > domain.add(COSInteger.get(1)); > COSArray c0 = new COSArray(); > c0.add(COSFloat.get("1")); > c0.add(COSFloat.get("0")); > c0.add(COSFloat.get("0")); > COSArray c1 = new COSArray(); > c1.add(COSFloat.get("0.5")); > c1.add(COSFloat.get("1")); > c1.add(COSFloat.get("0.5")); > fdict.setItem(COSName.DOMAIN, domain); > fdict.setItem(COSName.C0, c0); > fdict.setItem(COSName.C1, c1); > fdict.setInt(COSName.N, 1); > dict.setItem(COSName.FUNCTION, fdict); > > PDShadingType2 shading = new PDShadingType2(dict); > > // create and add to shading resources > page.setResources(new PDResources()); > Map<String, PDShadingResources> shadings = new > HashMap<String, PDShadingResources>(); > shadings.put("sh1", (PDShadingResources) shading); > page.getResources().setShadings(shadings); > > // invoke shading from content stream > PDPageContentStream contentStream = new > PDPageContentStream(document, page, true, false); > contentStream.appendRawCommands("/sh1 sh"); > contentStream.close(); > > document.save("shtest.pdf"); > document.close(); > > >

