This article will demonstrate how to create spot color to PDF file using Spire.PDF in Java.
import com.spire.pdf.*;
import com.spire.pdf.colorspace.*;
import com.spire.pdf.graphics.*;
import java.awt.*;
import java.awt.geom.Point2D;
public class SpotColor {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Add a page
PdfPageBase page = pdf.getPages().add();
//Define the spot color "MySpotColor" from the built-in color.
PdfRGBColor pdfRGBColor = new PdfRGBColor(new Color(148,0,211));
PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MySpotColor",pdfRGBColor);
//Apply the spot color while drawing content on the page.
PdfSeparationColor color = new PdfSeparationColor(cs, 1f);
PdfSolidBrush brush = new PdfSolidBrush(color);
page.getCanvas().drawString("Tint=1.0", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(160, 160));
//Draw pie with spot color(DarkViolet)
page.getCanvas().drawPie(brush, 148, 200, 60, 60, 360, 360);
page.getCanvas().drawString("Tint=0.7", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(230, 160));
color = new PdfSeparationColor(cs, 0.7f);
brush = new PdfSolidBrush(color);
page.getCanvas().drawPie(brush, 218, 200, 60, 60, 360, 360);
page.getCanvas().drawString("Tint=0.4", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(300, 160));
color = new PdfSeparationColor(cs, 0.4f);
brush = new PdfSolidBrush(color);
page.getCanvas().drawPie(brush, 288, 200, 60, 60, 360, 360);
page.getCanvas().drawString("Tint=0.1", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(370, 160));
color = new PdfSeparationColor(cs, 0.1f);
brush = new PdfSolidBrush(color);
page.getCanvas().drawPie(brush, 358, 200, 60, 60, 360, 360);
//Save the document
pdf.saveToFile("output/drawContentWithSpotColor.pdf");
}
}
Effective screenshot after adding spot color in PDF in Java application:

