Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jul 17, 2019 12:26 pm

Hello!

Is there any possibility to rotate the signature vertically?

Julen
 
Posts: 4
Joined: Wed Jul 17, 2019 12:23 pm

Thu Jul 18, 2019 6:56 am

Hello,

Thanks for your inquiry.
Sorry that there is no direct way to rotate the signature vertically. However, there is an indirect approach, that is rotating a PDF page to add signature firstly and then rotating the page back to draw a template into the final PDF file. Below is my testing code for your reference. Here, I also attached my generated PDF. If there is any question, just feel free to write back.
Code: Select all
 //create a PDF
 PdfDocument doc = new PdfDocument();
 PdfPageBase page = doc.Pages.Add();
 //Rotate page
 page.Rotation = PdfPageRotateAngle.RotateAngle90;
 PdfCertificate digi = new PdfCertificate(@"test.pfx", "123");
 PdfSignature signature = new PdfSignature(doc, doc.Pages[0], digi, "demo_1");
 signature.SignTextAlignment = SignTextAlignment.Center;
 signature.Bounds = new RectangleF(new PointF(200, 200), new SizeF(100, 100));
 signature.DistinguishedName = "DN:";
 signature.NameLabel = "Digital Signed By:";
 signature.Name = "Ankush";
 signature.Date = DateTime.Now;
 signature.Certificated = false;
 signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
 doc.FileInfo.IncrementalUpdate = false;
 MemoryStream stream = new MemoryStream();
 doc.SaveToStream(stream, Spire.Pdf.FileFormat.PDF);
 //load saved stream pdf
 PdfDocument loaddoc = new PdfDocument();
 loaddoc.LoadFromStream(stream);
 //create a new pdf
 PdfDocument newPdf = new PdfDocument();
 PdfPageBase loadpage = loaddoc.Pages[0];
 PdfPageBase newPage = newPdf.Pages.Add(new SizeF(loadpage.Size.Height, loadpage.Size.Width), new PdfMargins(0));
 loadpage.CreateTemplate().Draw(newPage, new PointF(0, 0));
 //draw test string
 PdfBrush brush = PdfBrushes.Black;
 PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic), true);
 newPage.Canvas.DrawString("this is a test!", font1, brush, new Rectangle(new Point(50, 50), new Size(50, 50)));
 newPdf.SaveToFile(@"output.pdf", FileFormat.PDF);

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon Jul 22, 2019 8:22 am

Hi again, I have 2 more questions about PDF signature.

-For what porpouse is the property of the pdfsignature "SignNameFont", the only one that really changes my text is the property "SignDetailsFont"
-My other question is that if I add text and image to a signature, how can I put the image under the text? I think the only possibilities is to put it left or right the text.

Thank you

Julen
 
Posts: 4
Joined: Wed Jul 17, 2019 12:23 pm

Mon Jul 22, 2019 10:11 am

Hello,

Thanks for your feedback, below are my answers to your questions.
1. Kindly note that the property "SignNameFont" is defined to set a font for the string of signature.Name. Like the following code snippet, its purpose is to set TimesRoman font for "Ankush". But this setting doesn't work when doing the initial test. This issue has been logged into our bug tracking system for further investigating and fixing. Once it is fixed, we will let you know. Sorry for the inconvenience caused.
Code: Select all
......
 signature.Name = "Ankush";
 signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 25);
......

2. Actually, the image signature is under the text signature when using SignImageAndSignDetail. You can refer to the following sample code and test a light color image to verify. If there is any question, just feel free to write back.
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"test.pdf");
PdfCertificate cert = new PdfCertificate(@"test.pfx", "123");
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "Signature1");
signature.Bounds = new RectangleF(50, 600, 160, 50);
signature.NameLabel = "Digitally signed by";
signature.Name = "Test User";
signature.DateLabel = "CEO";
signature.Date = DateTime.Now;
Image img = Image.FromFile(@"logo.png");
PdfImage image = PdfImage.FromImage(img);
signature.SignImageSource = image;
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
signature.SignImageLayout = SignImageLayout.Stretch;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
doc.SaveToFile("result.pdf");

Sincerely,
Lisa
E-iceblue support team
Last edited by Lisa.Li on Tue Jul 23, 2019 1:44 am, edited 1 time in total.
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon Jul 22, 2019 10:23 am

Hello,

1. Thanks, I will wait for your fix.

2. But what I am saying is that text starts at half of the signature to the right and the imagen from the left. What i want its to start the text and the image from the left. If you put the image in stretch none you will see better.

Thanks.

Julen
 
Posts: 4
Joined: Wed Jul 17, 2019 12:23 pm

Mon Jul 22, 2019 10:38 am

Hello,

Thanks for your quick response.
To help us provide an accurate solution, please provide a screenshot that shows your desired effect of output. Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon Jul 22, 2019 11:00 am

Hello Lisa,

I add you 2 photos to explain.

The image test.jpg is a grey photo and if you stretch you can see that my text starts from the middle of the signature.

The image test2.jpg the image is a text.

Julen
 
Posts: 4
Joined: Wed Jul 17, 2019 12:23 pm

Tue Jul 23, 2019 3:35 am

Hello,

Thanks for your more information.
When signing text and image, even setting "signature.SignTextAlignment = SignTextAlignment.Left;", I indeed notice that the text starts from the middle of the signature area but not from the left. This issue also has been submitted to our Dev team for further investigating, we will keep you posted if there is any update. Sorry for the inconvenience caused. Besides, as for your text image like test2.jpg, since the font color of the text image is darker than text signature. I suggest that you put the text image signature and text signature in different parts of your signature area. You can refer to the following sample code to have a test. If there is any question, welcome to write back.
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"sample.pdf");
PdfCertificate cert = new PdfCertificate(@"test.pfx", "123");
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "Signature1");
signature.Bounds = new RectangleF(50, 600, 160, 50);
signature.NameLabel = "Digitally signed by";
signature.Name = "Test User";
signature.DateLabel = "CEO";
signature.Date = DateTime.Now;
//set the size of image
Bitmap bitmap = new Bitmap((int)signature.Bounds.Width / 2, (int)signature.Bounds.Height);
Image img = Image.FromFile(@"text.png");
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
    g.Clear(Color.White);
    g.DrawImage(img, new Rectangle(0, 0, (int)signature.Bounds.Width / 2, (int)signature.Bounds.Height), new RectangleF(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
}
PdfImage image = PdfImage.FromImage(bitmap);
signature.SignImageSource = image;
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
signature.SignImageLayout = SignImageLayout.None;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
doc.SaveToFile("result.pdf");

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Dec 06, 2019 2:28 am

Hello,

Hope you are doing well.
Glad to inform that we just released Spire.PDF Pack(Hot Fix) Version:5.12.3 which fixes the issue of setting the property "SignNameFont". Welcome to download and test it.
Our website: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
NuGet: https://www.nuget.org/packages/Spire.PDF/5.12.3
As for the setting "signature.SignTextAlignment = SignTextAlignment.Left;", I got the news from our Dev team that the text starts from the middle of the signature area when signing the picture and text at the same time, this is based on our internal mechanism. Sorry at present we don’t have a better solution to adjust this. If you only sign text, this setting will start from the left the signature area.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon May 29, 2023 5:19 pm

[FunctionName("Sign")]
public async Task<HttpResponseMessage> Sign3(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "Sign")] HttpRequest req,
ILogger log)
{
var file = req.Form.Files["pdfFile"];
if (file == null || file.Length == 0)
{
return new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = new StringContent("No file uploaded.")
};
}

PdfDocument doc;
using (var stream = file.OpenReadStream())
{
doc = new PdfDocument(stream);
}

Demographic dem = new Demographic();
dem.Get("C6D2BE10-EECD-EA11-80D6-005056815184", "", "");
PdfCertificate cert = new PdfCertificate(GetCert());
PdfFormWidget formWidget = doc.Form as PdfFormWidget;

if (doc != null && formWidget != null)
{
var form = (PdfFormWidget)doc.Form;
if (form.FieldsWidget != null && form.FieldsWidget.Count > 1 && form.FieldsWidget[5] is PdfSignatureFieldWidget)
{
var field = form.FieldsWidget[5] as PdfSignatureFieldWidget;
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, field.Name, field);

// Set signature properties
signature.Certificated = true;
signature.GraphicsMode = GraphicMode.SignDetail;
signature.NameLabel = "Signer";
signature.Name = dem.FirstName;
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "845-425-5550";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "Pomona USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "Consent";
signature.DistinguishedNameLabel = "DN:Achieve Behavioral Health";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 5f, FontStyle.Regular));
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
}
}

// Save the signed PDF to a temporary file
var tempFilePath = Path.GetTempFileName();
doc.SaveToFile(tempFilePath);

// Read the signed PDF file as a byte array
byte[] pdfBytes = await File.ReadAllBytesAsync(tempFilePath);

// Create the HttpResponseMessage
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(pdfBytes);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
{
FileName = "signed.pdf"
};

return response;
}
[code][/code]


For some reason my doc isn't returned with the signature can anyone help?

ElimelechSafern
 
Posts: 5
Joined: Thu Mar 30, 2023 5:28 pm

Tue May 30, 2023 7:19 am

ElimelechSafern wrote:[FunctionName("Sign")]

......sample code ......


For some reason my doc isn't returned with the signature can anyone help?


Hi,

Thanks for your inquiry.
In order to assist you further, could you please provide us with a sample test document that you are having issues with? As your code involves some operations specific to the document, providing the document will help us better understand and resolve any problems you may be experiencing. You can share it with us via email (support@e-iceblue.com) or attach it here.

We appreciate your cooperation in this matter, and we look forward to resolving this issue for you as soon as possible.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF