How to add an image into a spot colour channel for a PDF document using ABCpdf?

arvind.d

While using ABCpdf programmatically, I found the need to add a new image into a specific custom colour channel (known as spot colours) in a PDF file. Usually these type of channels are used in the printing industry to add specialty colours such as gold, silver, etc onto the printed material and instructs the printing machine to use special inks during the process. Each spot colour channel can contain only 1 colour (with varying intensities based on their alpha value).

The problem comes with figuring out how to do that easily using ABCpdf. While the documentation does have a sample code for this using the AddColorSpaceSpot function in combination with the AddText function, there is no indication on how to accomplish this using an image. Any attempt at replacing AddText with AddImage is futile as it only adds the image as a normal RGB or CMYK object.

The sample code from the documentation reads:

Doc theDoc = new Doc();
theDoc.Rect.Inset(20, 20);
theDoc.FontSize = 300;
theDoc.ColorSpace = theDoc.AddColorSpaceSpot("GOLD", "0 0 100 0");
for (int i = 1; i <= 10; i++) {
  theDoc.Color.Gray = 255 / i;
  theDoc.AddText(theDoc.Color.Gray.ToString());
  theDoc.Rect.Move(25, -50);
}
theDoc.Save(Server.MapPath("docaddcolorspacespot.pdf"));
theDoc.Clear();

Based on the above code I tried the following in a console app:

Doc theDoc = new Doc();
theDoc.Rect.Inset(10, 10);
theDoc.ColorSpace = theDoc.AddColorSpaceSpot("Gold", "0 0 100 0");
theDoc.FontSize = 300;
theDoc.Color.Gray = 255;
theDoc.AddText("My Text");
theDoc.Save($"output/spot_test_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.pdf");
theDoc.Clear();

All works well up to now, the text "My Text" is present in the output PDF file in the correct "Gold" channel that was added.

So I replace the line theDoc.AddText("My Text"); with theDoc.AddImage("images/gradient_alpha.png")' expecting it to add this image into the current colour space that I created, but it didn't work.

Manually creating a new colour space, image object and pixmap object did not work either:

Doc theDoc = new Doc();

var cs = new ColorSpace(theDoc.ObjectSoup, ColorSpaceType.Separation);
cs.Doc.Color.String = "0 0 100 0";
cs.Doc.Color.Name = "Gold";
theDoc.ColorSpace = cs.ID;

var image = new XImage();
image.SetFile("images/gradient_alpha.png");
PixMap px = PixMap.FromXImage(theDoc.ObjectSoup, image);
px.Recolor(cs);

theDoc.AddImage(px.GetBitmap());

So, how do we correctly add an image into a spot colour channel? Read the answer below to find out!

arvind.d

To accomplish this, you need to add the image as an object into the document via AddImageObject and extract it as a PixMap from the document's ObjectSoup container and apply a Recolor on the PixMap with the destination colour space.

Here is the final code that I managed to use successfully:

Doc theDoc = new Doc();
theDoc.ColorSpace = theDoc.AddColorSpaceSpot("Gold", "0 0 100 0");
ColorSpace goldSpotColor = (ColorSpace)theDoc.ObjectSoup[theDoc.ColorSpace];

XImage image = XImage.FromFile("images/gradient_alpha.png", new XReadOptions());

int theID = theDoc.AddImageObject(image, true);
int imageID = theDoc.GetInfoInt(theID, "XObject");
PixMap thePM = (PixMap)theDoc.ObjectSoup[imageID];

thePM.Recolor(goldSpotColor);

theDoc.Save($"output/spot_test_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.pdf");
theDoc.Clear();

At first sight, it seems way too much steps to take for achieving what we want but ABCpdf is a low-level PDF manipulation library that is very powerful. The documentation is extensive but not always explicit so a lot of reading and experimentation is expected.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to add an image as a header/footer in Markdown for a PDF document

分類Dev

How can we add '.svg' formatted image in pdf using itext library in java/struts2

分類Dev

Scribus spot color PDF

分類Dev

How to add a json in a nested array of a mongodb document using Spring?

分類Dev

How to add map inside document in firestore using flutter?

分類Dev

Add an image in a specific position in the document (.docx) with Python?

分類Dev

How to add security properties of pdf while generating PDF from HTML using javascript?

分類Dev

How channel work in using channel to find prime number problem?

分類Dev

How to Add dynamic image on body of Email using phpmail

分類Dev

How to remove a label in <li> element and add image using tritium?

分類Dev

How to add image at right bottom div using css

分類Dev

How to manually set colour of dots in R using tmap

分類Dev

Adding an alpha channel to a Monochrome Image using Open CV Python

分類Dev

Using a diverging colour scheme

分類Dev

How to add a field with specific datatype ( list, object) in an existing mongoDB document using python

分類Dev

How do I add a selection between two tags in a html document using Visual Studio Code?

分類Dev

Add image to HeaderFooter using Axlsx

分類Dev

Background Image not showing in PDF using WKHTMLTOPDF

分類Dev

How to download current screen as PDF and Image using html2canvas JS?

分類Dev

How could I implement image channel drop with the python lib of pillow

分類Dev

Add Digital Signature to a PDF using IText 7

分類Dev

Share issue when using PDFKit to create a PDF document

分類Dev

Flutter Firebase - How to Add User uid to Document

分類Dev

how to add and delete a sub document in MongoDB shell?

分類Dev

pdf.js: Get the text colour

分類Dev

Add all sizes of image asset in Android Studio with a PDF or Vector file

分類Dev

How to add text above the image?

分類Dev

NodeJS Pdfmake how to add an image

分類Dev

How to add a background image to string?

Related 関連記事

  1. 1

    How to add an image as a header/footer in Markdown for a PDF document

  2. 2

    How can we add '.svg' formatted image in pdf using itext library in java/struts2

  3. 3

    Scribus spot color PDF

  4. 4

    How to add a json in a nested array of a mongodb document using Spring?

  5. 5

    How to add map inside document in firestore using flutter?

  6. 6

    Add an image in a specific position in the document (.docx) with Python?

  7. 7

    How to add security properties of pdf while generating PDF from HTML using javascript?

  8. 8

    How channel work in using channel to find prime number problem?

  9. 9

    How to Add dynamic image on body of Email using phpmail

  10. 10

    How to remove a label in <li> element and add image using tritium?

  11. 11

    How to add image at right bottom div using css

  12. 12

    How to manually set colour of dots in R using tmap

  13. 13

    Adding an alpha channel to a Monochrome Image using Open CV Python

  14. 14

    Using a diverging colour scheme

  15. 15

    How to add a field with specific datatype ( list, object) in an existing mongoDB document using python

  16. 16

    How do I add a selection between two tags in a html document using Visual Studio Code?

  17. 17

    Add image to HeaderFooter using Axlsx

  18. 18

    Background Image not showing in PDF using WKHTMLTOPDF

  19. 19

    How to download current screen as PDF and Image using html2canvas JS?

  20. 20

    How could I implement image channel drop with the python lib of pillow

  21. 21

    Add Digital Signature to a PDF using IText 7

  22. 22

    Share issue when using PDFKit to create a PDF document

  23. 23

    Flutter Firebase - How to Add User uid to Document

  24. 24

    how to add and delete a sub document in MongoDB shell?

  25. 25

    pdf.js: Get the text colour

  26. 26

    Add all sizes of image asset in Android Studio with a PDF or Vector file

  27. 27

    How to add text above the image?

  28. 28

    NodeJS Pdfmake how to add an image

  29. 29

    How to add a background image to string?

ホットタグ

アーカイブ