【问题标题】:Applying a pantone color to a font in iText7将 pantone 颜色应用于 iText7 中的字体
【发布时间】:2017-03-27 09:18:28
【问题描述】:

我正在评估 iText7 是否足以在未来的项目中使用。

有人可以在 iText7 上为我提供一个关于如何创建并将 pantone 颜色应用于字体的清晰示例吗?

我曾经在另一个 PDF 库上进行开发,在这种情况下,我会将“R G B H S B”值提供到一个数组中,创建我的色彩空间,然后在任何地方使用这个色彩空间。我似乎无法在 itext7 上执行此操作。

我想在 pdf 上使用 pantone 颜色“PANTONE 485 C”和以下 RGB HSB 值编写字体:

  • H: 255
  • S: 251
  • 乙:248
  • R: 220
  • G: 36
  • 乙:31

我找到的大多数示例都是针对 iText5 的(在 iText7 中已删除的函数和类)

提前致谢

【问题讨论】:

  • 如果这是一个商业项目,请与您当地的 iText 销售办事处联系。他们很乐意为您设置试用许可证,并且您可以直接向 iText 开发人员提问。
  • 我有一个试用许可证,因为我只是在评估这是否符合我的目的。我被告知要在 stackoverflow 上提问。
  • 这看起来很奇怪。你能告诉我你为哪家公司申请了这个许可证吗?然后我可以向我们的销售团队询问更多信息。
  • 让我更清楚我之前所说的话。支持/销售团队中没有人告诉我在 stackoverflow 中提问。如果我的答案在 stackoverflow 中没有得到回答,该网站会提示这样做。如果试用用户可以联系 itext 开发人员,我想知道如何更快。
  • 如果您正在对此进行测试以评估商业可行性,您可以联系我们的销售团队。他们会为你安排好一切。包括访问我们的 Jira 票务系统。如果您转到itextpdf.com 并向下滚动,您应该会看到所有销售办事处的列表。只需联系您所在地区的人。

标签: c# itext7


【解决方案1】:

要在 PDF 中使用 Pantone 颜色,应将其定义为分离颜色空间。

string dest = @"C:\publish\Pantone.pdf";
string text = "This text is PANTONE 485 C.";
using (var fileStream = new FileStream(dest, FileMode.Create))
{
    var pdfDoc = new PdfDocument(new PdfWriter(fileStream));
    using (var doc = new Document(pdfDoc))
    {
        PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);

        var alternateSpace = new DeviceRgb(220, 36, 31);
        var tintTransform = new PdfFunction.Type2(
            new PdfArray(new[] { 0.0f, 1f }),
            null,
            new PdfArray(new[] { 1f, 1f, 1f }),
            new PdfArray(new[] { alternateSpace.GetColorValue()[0], alternateSpace.GetColorValue()[1], alternateSpace.GetColorValue()[2] }),
            new PdfNumber(1f));

        var pantone = new Separation("PANTONE 485 C", alternateSpace.GetColorSpace(), tintTransform, 1f);
        doc.Add(new Paragraph(text).SetFontColor(pantone).SetFont(font).SetFontSize(12f));
    }
}

【讨论】:

    【解决方案2】:

    我有这个 java sn-p。 到 C# 的映射应该是相当不错的。

    public static void main(String[] args) throws FileNotFoundException {
    
        // color definition
        Color color = new DeviceRgb(220,36,31);
    
        // set up IO
        PdfWriter writer = new PdfWriter(new File(System.getProperty("user.home"), "stackoverflow.pdf"));
        PdfDocument pdf = new PdfDocument(writer);
        Document doc = new Document(pdf);
    
        // add paragraph in desired color
        Paragraph para = new Paragraph("I want to write a font on a pdf using pantone color \"PANTONE 485 C\" with the following values of RGB HSB");
        para.setFontColor(color);
        doc.add(para);
    
        // close IO
        doc.flush();
        doc.close();
    }
    

    【讨论】:

    • 首先感谢您的回复。您添加的是 RGB 颜色而不是 Pantone 颜色。这不适用于打印机。需要在 Acrobat Pro 上检测到“分离颜色”。我看到了一个 itext7 示例,其中有人在圆形上执行此操作。但我不能将此专色应用于字体。
    • 我可能弄错了(鉴于我对色彩空间的了解有限),但考虑到有一种方法可以将 RGB 映射到 HSB,反之亦然),第二对值似乎相当不必要的。 en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
    【解决方案3】:

    这里是创建 RGB 专色的 C# 方法

    using iText.Kernel.Colors;
    using iText.Kernel.Pdf.Function;
    using iText.Kernel.Pdf;
    private Separation SpotColor(string name, int r,int g,int b)
    {
        var alternateSpace = new DeviceRgb(r, g, b);
        var tintTransform = new PdfFunction.Type2(
            new PdfArray(new[] { 0.0f, 1f }),
            null,
            new PdfArray(new[] { 1f, 1f, 1f }),
            new PdfArray(new[] { alternateSpace.GetColorValue()[0], alternateSpace.GetColorValue()[1], alternateSpace.GetColorValue()[2]}),
            new PdfNumber(1f));
    
        var spot = new Separation(name, alternateSpace.GetColorSpace(), tintTransform, 1f);
        return spot;
    }
    

    然后您可以使用此方法将专色添加到您的画布,就像在此代码中一样。我正在为 perf 切割设置专色,对于许多切割机来说,该专色要求使用红色 RGB 将专色称为“CutContourPerf”

    iText.Kernel.Pdf.Canvas.PdfCanvas canvas = new PdfCanvas(page);
    canvas.SetStrokeColor(SpotColor("CutContourPerf", 255, 0, 0));
    

    【讨论】:

      猜你喜欢
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2013-05-10
      • 2014-11-11
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      相关资源
      最近更新 更多