pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Shading of an elliptic form
Date Tue, 14 Oct 2014 16:16:55 GMT
You can do this by using a transformation matrix with different x and y 
scales.

See PDFBOX-2217, it has a sample PDF.

Note that correct rendering is not yet supported.


Tilman

Am 14.10.2014 um 17:39 schrieb klaus.graaf@lhsystems.com:
>
> Hello,
>
> I'm validating the use of pdfbox 1.8.6 for the creation of a pdf file 
> for an editor.
>
> Therefore I need to create a shading within an ellipse, which looks 
> like the following:
>
> I wrote a test program, which creates a *circular* shading:
>
> *public**static**void*main(String[] args) {
>
> /testLinearGradient/();
>
> /testCircularGradient/();
>
> }
>
> *public**static**void*testCircularGradient() {
>
> *try*{
>
> *float*width = 600.0f;
>
> *float*height = 600.0f;
>
> PDRectangle sizePDF = *new*PDRectangle(width, height);
>
>            PDDocument document = *new*PDDocument();
>
>             PDPage page = *new*PDPage(sizePDF);
>
> document.addPage(page);
>
> // shading attributes
>
> COSDictionary dict = *new*COSDictionary();
>
> dict.setInt(COSName./SHADING_TYPE/, 3);
>
> dict.setName(COSName./COLORSPACE/, "DeviceRGB");
>
>              COSArray coords = *new*COSArray();
>
> coords.add(COSInteger./get/(300)); //x1
>
> coords.add(COSInteger./get/(300)); //y1
>
> coords.add(COSInteger./get/(300)); //x2
>
> coords.add(COSInteger./get/(300)); //y2
>
> *int*radius = 300;
>
> coords.add(COSInteger./get/(radius)); //r1
>
> coords.add(COSInteger./get/(0)); //r2
>
> 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"));  //color 1 red
>
> c0.add(COSFloat./get/("0"));
>
> c0.add(COSFloat./get/("0"));
>
>              COSArray c1 = *new*COSArray();
>
> c1.add(COSFloat./get/("0")); // _color_ 2 _blue_
>
> c1.add(COSFloat./get/("0"));
>
> c1.add(COSFloat./get/("1"));
>
> fdict.setItem(COSName./DOMAIN/, domain);
>
> fdict.setItem(COSName./C0/, c0);
>
> fdict.setItem(COSName./C1/, c1);
>
> fdict.setFloat(COSName./N/, 1.0f);
>
> dict.setItem(COSName./FUNCTION/, fdict);
>
>              PDShadingType3 shading = *new*PDShadingType3(dict);
>
> // create and add to shading resources
>
> page.setResources(*new*PDResources());
>
> _Map_ shadings = *new*_HashMap_();
>
> _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("c:\\pdfCircularGradient.pdf");
>
>           document.close();
>
>         } *catch*(Exception e) {
>
>             System./out/.println(" error creating pdf file."+ 
> e.toString());
>
>         }
>
>       }
>
> Does anyone has an idea, how I can change the program, so it will 
> create an elliptic shading.
>
> Is an elliptic shading supported by the pdf specification?
>
> Thanks
>
> Klaus Graaf
>
> Sitz der Gesellschaft / Corporate Headquarters: Lufthansa Systems AS 
> GmbH, Norderstedt, Registereintragung / Registration: Amtsgericht 
> Norderstedt 3688NO
> Geschaeftsfuehrung / Management Board: Bernd Appel
>
>


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