How to draw a vertical gradient in iTextSharp?

I am trying to draw a vertical gradient at the bottom of an iTextSharp PDF:

PdfShading shading 
    = PdfShading.SimpleAxial(pdfWriter, 0, document.PageSize.Height, 
                             document.PageSize.Width, 0, BaseColor.WHITE, BaseColor.GREEN);
PdfShadingPattern pattern = new PdfShadingPattern(shading);
pdfContentByte.SetShadingFill(pattern);
pdfContentByte.Rectangle(0, 0, document.PageSize.Width, 70);
pdfContentByte.Fill();

This creates a gradient in the exact position. I want it to be created, but the gradient is horizontal on the left (white) and on the right (green).

I want the gradient to be vertical from top to bottom (white) to bottom (green).

Changing the coordinates, as some of them did ( does iTextsharp support multicolor diagonal gradients? ), Did not solve the problem. I also tried to rotate the document, but that didn't work.

+4
source share
1 answer

. Java - :

public void createPdf(String dest) throws IOException, DocumentException {
    Rectangle pageSize = new Rectangle(150, 300);
    Document document = new Document(pageSize);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    PdfShading shading = PdfShading.simpleAxial(writer,
            0, pageSize.getHeight(),
            0, 0,
            BaseColor.WHITE, BaseColor.GREEN);
    PdfShadingPattern pattern = new PdfShadingPattern(shading);
    PdfContentByte canvas = writer.getDirectContent();
    canvas.setShadingFill(pattern);
    canvas.rectangle(0, 0, pageSize.getWidth(), pageSize.getHeight());
    canvas.fill();
    document.close();
}

. GradientTopToBottom.

?

enter image description here

+1

Source: https://habr.com/ru/post/1621419/


All Articles