Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to use named SpotColor #181

Open
Crowdedlight opened this issue Aug 2, 2024 · 5 comments
Open

option to use named SpotColor #181

Crowdedlight opened this issue Aug 2, 2024 · 5 comments

Comments

@Crowdedlight
Copy link

I have an application where I need to use a named spotcolor with the name "Cut". As the printer requires that to cut the right lines.

It seems like this library makes spotcolours behave like CMYK colours and does not give an option to name it?

Would it be something that could be added?

I would consider looking into implementing it myself, but would need some pointers on how the library currently exports the spotcolor to pdf. Unsure if it already handles the custom colorspace for spotcolors and is just missing the naming, or it sees spotcolors as CMYK like the CMYK color and would need to figure out how to implement spot colours related to PDF specification.

@fschutt
Copy link
Owner

fschutt commented Aug 5, 2024

To be fair, I haven't worked with spot colors. The library just converts them into a Stream of lopdf::Operation:

printpdf/src/color.rs

Lines 22 to 52 in fbc7d69

fn from(val: PdfColor) -> Self {
use lopdf::Object::*;
// todo: incorporate ICC profile instead of just setting the default device cmyk color space
let (color_identifier, color_vec) = {
use self::PdfColor::*;
match val {
FillColor(fill) => {
let ci = match fill {
Color::Rgb(_) => OP_COLOR_SET_FILL_CS_DEVICERGB,
Color::Cmyk(_) | Color::SpotColor(_) => OP_COLOR_SET_FILL_CS_DEVICECMYK,
Color::Greyscale(_) => OP_COLOR_SET_FILL_CS_DEVICEGRAY,
};
let cvec = fill.into_vec().into_iter().map(Real).collect();
(ci, cvec)
}
OutlineColor(outline) => {
let ci = match outline {
Color::Rgb(_) => OP_COLOR_SET_STROKE_CS_DEVICERGB,
Color::Cmyk(_) | Color::SpotColor(_) => OP_COLOR_SET_STROKE_CS_DEVICECMYK,
Color::Greyscale(_) => OP_COLOR_SET_STROKE_CS_DEVICEGRAY,
};
let cvec = outline.into_vec().into_iter().map(Real).collect();
(ci, cvec)
}
}
};
Operation::new(color_identifier, color_vec)
}

here, when you call set_fill_color, it calls Operation::from:

self.add_operation(PdfColor::FillColor(fill_color));

So idk, maybe spot colors need different handling. I haven't read the PDF reference on this topic.

@fschutt
Copy link
Owner

fschutt commented Aug 5, 2024

You could create an API like this:

PdfDocument::create_named_spotcolor(&mut document, ...) -> SpotColorRef { }

enum PdfColor {
   ...
   NamedSpot(SpotColorRef),
}

impl From<SpotColorRef> for lopdf::Operation {
  fn from(s: SpotColorRef) -> { 
      lopdf::Operation::Reference(PDF_FILL_COLOR, Object::Reference(s.inner.clone())) 
  }
}

https://docs.rs/lopdf/latest/lopdf/enum.Object.html

@Crowdedlight
Copy link
Author

Thanks for the pointers!

I will have a look at it and see if I can get it working. Seems like a good way to go about it.

@TheOriginalAyaka
Copy link

Any updates on this?

@Crowdedlight
Copy link
Author

Crowdedlight commented Sep 15, 2024

Any updates on this?

Sorry, priority work came in, so I had to put my attempt on the backburner. I solved my issue here and now by opening the generated pdf in illustrator and manually set it to spot color. I hope to get some time in coming months to give it a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants