本文将详细介绍如何使用spire.pdf for 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) {
//新建pdfdocument 对象并添加一个新的页面
pdfdocument pdf = new pdfdocument();
pdfpagebase page = pdf.getpages().add();
//创建专色
pdfrgbcolor pdfrgbcolor = new pdfrgbcolor(new color(148,0,211));
pdfseparationcolorspace cs = new pdfseparationcolorspace("myspotcolor",pdfrgbcolor);
pdfseparationcolor color = new pdfseparationcolor(cs, 1f);
//创建truetype字体
pdftruetypefont font = new pdftruetypefont(new font("arial unicode ms", font.plain, 10), true);
//根据颜色创建画刷
pdfsolidbrush brush = new pdfsolidbrush(color);
//绘入图形及文字并着色
page.getcanvas().drawstring("着色=1.0", font, brush, new point2d.float(160, 160));
page.getcanvas().drawpie(brush, 148, 200, 60, 60, 360, 360);
//将专色透明度设置为0.7,并绘入图片及文字
page.getcanvas().drawstring("着色=0.7", font, 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("着色=0.4", font, 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("着色=0.1", font, 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);
//保存文档
pdf.savetofile("output/drawcontentwithspotcolor.pdf");
}
}
效果图: