Hi, please send both pdf files to me directly (tilman at snafu dot de) and I'll answer publicly.

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();




Reply via email to