0

I'm writing an ASP.NET (C#) application that uses iTextSharp to embed an image (a signature to be more specific) into an AcroForm . I achieved a decent result collecting the image from an external media (a USB Wacom tablet) and resizing it to fit in the acroform signature placeholder (that's half the size the picture taken from the tablet). I'm not fully satisfied of the result since the tablet collect the signature with a gross resolution (I think no more than 75 dpi) and thus resizing it (even with the most conservative algorithm) give a little fuzzy/rough image ... it's perfectly readable but not good looking in my opinion. I tough then that, maybe, chaging the DPI of the image instead changing it's size would retain all the original definition and thus give a better result when rendered inside the PDF. How can I achieve this result? I mean there's a simple way using iTextSharp to insert an image and setting it's DPI or I have to preprocess the image and changing the DPI prior embedding it? Is it possibile to define an AcroForm field that holds images instead text?

@BrunoLowagie of course I can, that's the code::

            using (Stream _sInputPdfStream = new FileStream(_sTempNomeFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (Stream _sInputImageStream = new FileStream(sImagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (Stream _sOutputPdfStream = new FileStream(_sOutputNomeFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                var _rReader = new PdfReader(_sInputPdfStream);
                var _sStamper = new PdfStamper(_rReader, _sOutputPdfStream);
                var _cContent = _sStamper.GetOverContent(1);

                iTextSharp.text.Image _iImage = iTextSharp.text.Image.GetInstance(_sInputImageStream);
                _iImage.SetAbsolutePosition(400, 0);
                _cContent.AddImage(_iImage);
                _sStamper.Close();
            }

Of course the sImagePath value is the path of the image I just uploaded to be 'attached' to the PDF.

Best Regards, Weirdgyn

weirdgyn
  • 886
  • 16
  • 47
  • iTextSharp doesn't reduce the number of pixels in an image. The DPI depends entirely on the dimensions you define for the image when you add it to the PDF. Hence I don't understand your question about "changing the DPI" because you can never add pixels to increase the DPI. You can only display the pixels in a rectangle that is smaller than the one you currently have. Is that what you want to do? Please clarify. – Bruno Lowagie May 22 '15 at 14:34
  • If the dimensions of the image stay constant, you'll get the identical output. Why aren't use collecting the list of line segments and using a polygonal path? You could even collect pressure build a polygon that reflects the pen better (and will likely take up less space) and will scale with fewer artifacts. – plinth May 22 '15 at 14:40
  • @Bruno In the form I'm using the signature placeholder is quite narrow. If I add the picture with its original size (as the tablet capture it) it would not fit in such placeholder. Thus I'm scaling the picture prior 'attaching' it in the PDF. Thus lead to a loss of resolution of the image. I would like to avoid to resize the image and attach it without scaling it but, as I stated before in this way it will not fit in the placeholder. The only way then is to change the dpi of the picture but I don't know if there's a way to do so and anyway I don't know if iTextSharp would allow me to do that. – weirdgyn May 22 '15 at 14:42
  • @plinth this a very good suggestion but I have to get a lot more into the tablet handling process that something that's beyond my control at the present time. – weirdgyn May 22 '15 at 14:49
  • You say *it would not fit in such placeholder*, but that's not an argument, is it? iText automatically scales the image to fit into the placeholder. If it's to big, this scaling operation will *increase the resolution*. This more or less calls for the code: what are you doing? Show us your code, because I don't think you're doing it right. – Bruno Lowagie May 22 '15 at 15:00
  • @Bruno ... sorry probably I used a term that overlay with a PDF / iTextSharp feature... with placehodler I mean the place I need the image to fit in it's not a 'real' element of the PDF form .. just an abstraction of mine. Anyway if there's a way to define this (and fill it ttrough iTextSharp) please let me know. – weirdgyn May 22 '15 at 15:04
  • 1
    First of all: I don't like *fake* signatures, yet that is what you want to produce: instead of a *real* digital signature, you want to add a raster image that looks like a signature. That's flat-catching. Secondly: when you talk about a placeholder for an image, I think of the common way to do this: a button field of which you want to replace the icon to scale and position an image as explained in the free eBook [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html). See also http://stackoverflow.com/a/16056852/1622493 – Bruno Lowagie May 22 '15 at 15:39
  • @BrunoLowagie as a matter of fact Wacom Signature SDK is just based upon a signature bitmap embedding.. (in a PDF also). And anyway the customer ask for the digitized signature so it's not an option. Thanks for the suggestion ! – weirdgyn May 22 '15 at 15:54
  • The answer to this question can be found here: http://stackoverflow.com/questions/16052047/add-image-to-acrofield-in-itext/16056852#16056852 – weirdgyn Jul 11 '16 at 15:51

0 Answers0