EldoS | Feel safer!

Software components for data protection, secure storage and transfer

[Java] Custom signature widget for PDF signing

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#36229
Posted: 03/14/2016 13:08:27
by Mickaël Bénès (Standard support level)
Joined: 02/26/2013
Posts: 74

Hello.

I've done some research so I can already create a signature with a custom image background + text. But I still got some questions about stretching, positioning and sizing of image/text in the widget.

  • What is the unit used to position an image ? Points ? Millimeters ?
  • Is it the same to set the dimensions of an image ?
  • It it the same with text ?
  • How to calculate the stretchX & stretchY values of an image when AutoStretchBackground isn't working ? Let's say I use a widget of 200 * 100 with an image of 250 * 150. Can I calculate it with these numbers or do I need something else ? I've seen in a topic that the inner layer of a signature widget has a dimension of 66 * 66. Should I use that ?

Thank you.
#36232
Posted: 03/14/2016 13:51:08
by Dmytro Bogatskyy (EldoS Corp.)

Thank you for contacting us,

Quote
What is the unit used to position an image ? Points ? Millimeters ?

From the PDF standard:
Quote
The minimum page size should be 3 by 3 units in default user space; the maximum should be 14,400 by 14,400 units. In versions of PDF earlier than 1.6, the size of the default user space unit was fixed at 1⁄72 inch, yielding a minimum of approximately 0.04 by 0.04 inch and a maximum of 200 by 200 inches. Beginning with PDF 1.6, the size of the unit may be set on a page-by-page basis; the default remains at 1/72 inch.


Quote
But I still got some questions about stretching, positioning and sizing of image/text in the widget.


To customize text in the signature widget you may use TElPDFSignatureWidgetProps.CustomText property that will add a custom text in a desired position and set TElPDFSignatureWidgetProps.HideDefaultText property to true to disable a default text (header, timestamp, signature info), for example:
Code
Sig.WidgetProps.HideDefaultText = true;
Sig.WidgetProps.CustomText.Add("Custom text", OffsetX, OffsetY, FontSizeX, FontSizeY);
// where OffsetX and OffsetY coordinates in the custom viewport, should be from 0 to 66
// the actual coordinates will be: OffsetX = RealOffsetX * 66.0 / WidgetWidth
// if widgetHeight not equal to widgetWidth the font will be stretched
// to compensate font stretching you may set fontsizeX = fontsizeY * widgetHeight / widgetWidth

Additionally, you may add the foreground images using TElPDFSignatureWidgetProps.AddImage() method. How the image and text is overlapped depends on the order they were added.
Quote
How to calculate the stretchX & stretchY values of an image when AutoStretchBackground isn't working ?

What do you mean by auto stretch background is not working? Do you need to partially stretch background in the signature widget?
#36238
Posted: 03/15/2016 09:17:35
by Mickaël Bénès (Standard support level)
Joined: 02/26/2013
Posts: 74

Quote
Dmytro Bogatskyy wrote:
The minimum page size should be 3 by 3 units in default user space; the maximum should be 14,400 by 14,400 units. In versions of PDF earlier than 1.6, the size of the default user space unit was fixed at 1⁄72 inch, yielding a minimum of approximately 0.04 by 0.04 inch and a maximum of 200 by 200 inches. Beginning with PDF 1.6, the size of the unit may be set on a page-by-page basis; the default remains at 1/72 inch.
Perfect, thank you !

Quote
Dmytro Bogatskyy wrote:
To customize text in the signature widget you may use TElPDFSignatureWidgetProps.CustomText property that will add a custom text in a desired position and set TElPDFSignatureWidgetProps.HideDefaultText property to true to disable a default text (header, timestamp, signature info), for example:
Code
Sig.WidgetProps.HideDefaultText = true;
Sig.WidgetProps.CustomText.Add("Custom text", OffsetX, OffsetY, FontSizeX, FontSizeY);
// where OffsetX and OffsetY coordinates in the custom viewport, should be from 0 to 66
// the actual coordinates will be: OffsetX = RealOffsetX * 66.0 / WidgetWidth
// if widgetHeight not equal to widgetWidth the font will be stretched
// to compensate font stretching you may set fontsizeX = fontsizeY * widgetHeight / widgetWidth
OK that's what I've seen in another thread so for that I'm good.

Quote
Dmytro Bogatskyy wrote:
What do you mean by auto stretch background is not working? Do you need to partially stretch background in the signature widget?
Haha if you say that it means there's something wrong that I did when I tried to add a background image some weeks ago. It seems to work fine now with AutoStretch.

Thanks for your help !
#36599
Posted: 04/29/2016 04:44:34
by Mickaël Bénès (Standard support level)
Joined: 02/26/2013
Posts: 74

Hello.

I come back to you because I experience difficulties to add an image in the signature widget. At first we used the background to do ut but in the end it doesn't respond entirely to our (the clients) needs.

So, what I want is being able to add an image (no matter the size) to the wigdet, from the top-left corner and calculate the correct dimensions so that the image isn't stretched (too much).

I tried different things but didn't manage to do it correctly. Could you help me please ?

Here's my code :
Code
int widgetWidth      = 200;   // Largeur du widget de signature.
int widgetHeight   = 100;   // Hauteur du widget de signature.
int widgetOffsetX   = 300;
int widgetOffsetY   = 50;

sign.getWidgetProps().setPrint( true );
sign.getWidgetProps().setHideDefaultText( true );
sign.getWidgetProps().setAutoSize( false );
sign.getWidgetProps().setAutoPos( false );
sign.getWidgetProps().setOffsetX( widgetOffsetX );
sign.getWidgetProps().setOffsetY( widgetOffsetY );
sign.getWidgetProps().setWidth( widgetWidth );
sign.getWidgetProps().setHeight( widgetHeight );
sign.getWidgetProps().setRotate( sigRotate );

// Récupération de l'image.
BufferedImage bufImg      = ImageIO.read( urlImgPades );
ByteArrayOutputStream baos   = new ByteArrayOutputStream();
TElPDFImage img            = new TElPDFImage();

// Création de l'image PDF.
ImageIO.write( bufImg, "jpg", baos );
img.setData( baos.toByteArray() );
img.setImageType( TSBPDFImageType.pitJPEG );
img.setWidth( bufImg.getWidth() );
img.setHeight( bufImg.getHeight() );

AppletAWS.println( "Récupération effectuée." );
AppletAWS.println( "- width : " + img.getWidth() );
AppletAWS.println( "- height : " + img.getHeight() );

AppletAWS.println( "\nAjout de l'image au widget..." );

sign.getWidgetProps().setBackgroundStyle( TSBPDFWidgetBackgroundStyle.pbsNoBackground );
sign.getWidgetProps().addImage( img, 0, 0, img.getWidth(), img.getHeight() );

AppletAWS.println( "Ajout effectué.\n" );

baos.flush();
baos.close();

// ADDING TEXT


Thanks !
#36602
Posted: 04/29/2016 05:29:17
by Dmytro Bogatskyy (EldoS Corp.)

Hi,

Quote
So, what I want is being able to add an image (no matter the size) to the wigdet, from the top-left corner and calculate the correct dimensions so that the image isn't stretched (too much).

The internal dimension of the signature widget is always fixed and has dimension 66x66 where the origin (0,0) is bottom-left corner. All coordinates and sizes of the custom text or foreground images are related to this "viewport".
For example, to add a foreground image that has the same aspect ration, but is stretched at maximum to match the widget height you would need to use the following code:
Code
sign.getWidgetProps().addImage( img, 0, 0, 66 * img.getWidth() / img.getHeight() * widgetHeight / widgetWidth, 66 );
#36613
Posted: 05/02/2016 08:17:56
by Mickaël Bénès (Standard support level)
Joined: 02/26/2013
Posts: 74

Thanks to that code I manage to build something pretty neat, thanks a lot !

One more thing, is there a way to add a border surrounding the widget signature ? Maybe with TElPDFSignatureWidgetProps.CustomAppearance ?
#36616
Posted: 05/02/2016 10:01:22
by Dmytro Bogatskyy (EldoS Corp.)

Hi,

Quote
One more thing, is there a way to add a border surrounding the widget signature ? Maybe with TElPDFSignatureWidgetProps.CustomAppearance ?

The TElPDFSignatureWidgetProps.CustomAppearance property set custom widget data and replaces the text and images added by other properties.
There is no property to add a border surrounding the widget, however you can use TElPDFSignatureWidgetProps.CustomText property to add not only the text, but a custom pdf graphic operators into the signature widget, for example:
Code
TElPDFSignatureWidgetText t = new TElPDFSignatureWidgetText();
SignatureEntry.WidgetProps.CustomText.Add(t);
t.CustomData = "1.0 0.0 0.0 rg\r\n";

In this sample, rg is non-stroking color operator that changes the color of the text to red. It applies to the custom text that added after this operator.
In the similar way you can add graphics operators that draws black square (border), see "8.5 Path Construction and Painting" from http://wwwimages.adobe.com/content/da...0_2008.pdf
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

Topic viewed 2263 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!