(Reposting this to itext-questions, because I asked this on itextsharp-questions and got no answer. Also, itextsharp-questions seems to have a very low volume, maybe it's (almost) dead?)

Hi,

I'm using iTextSharp 4.1.2.0.

I'm trying to apply smasks to an image like it is shown in the attached
example source code. This example is more or less taken from page 341 of
"iText in action" with the difference that the smask for the image is
not created from code but load from a file.

The code runs through fine and the PDF is written, but when I open the
resulting PDF in Adobe Acrobat it says "Errors on this page" and the
transparent object is not displayed. The page displays fine in
Ghostscript 8.64, though...

I have tried to load the mask from the following types of files:

- 8 bit grayscale PNG and 8 bit BMP: The above behaviour
- 24-bit RGB PNG: iText says "this image cannot be used as a mask"
- 8 bit grascale PNG with alpha channel: iText says "Key error"

Which file format should I try next?

When I create the smask in code instead of loading it from a file
everything works fine.

Any ideas?


Markus

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using NUnit.Framework;

using iTextSharp.text;
using iTextSharp.text.pdf;

namespace iText_Test_Namesspace
{
    [TestFixture]
    public class iText_Test
    {
        [Test]
        public void TestSmask()
        {
            Document doc = new Document();

            PdfWriter writer = PdfWriter.GetInstance(
                doc, new FileStream("c:\\stuff\\test.pdf", FileMode.Create));

            doc.Open();

            for (int i = 0; i < 40; i++)
                doc.Add(new Paragraph("This is some example text - this is some 
example text"));

            PdfContentByte cb = writer.DirectContent;

            Image shadowImage = Image.GetInstance(1, 1, 3, 8, new byte[] { 255, 
0, 0});

            // This works
            //Image shadowSmask = Image.GetInstance(5, 1, 1, 8, new byte[] { 
128, 192, 255, 192, 128}); ;

            // This doesn't
            Image shadowSmask = 
Image.GetInstance("c:\\stuff\\shadow_smask.png");

            shadowSmask.MakeMask();
            shadowImage.ImageMask = shadowSmask;

            shadowImage.SetAbsolutePosition(10, 600);
            shadowImage.ScaleAbsolute(300, 200);
            cb.AddImage(shadowImage);

            doc.Close();
        }
    }
}


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to