Trouble printing Digital Signature - pdfsharp

I have created a pdf document using ModelDoc. After creating it, I am using PDFSharp to insert a digital signature in the document.
The digital signature is seen properly and I am also able to perform normal task of signature validation.
However, the digital signature is not printed when I print the document. I have already tried using "Document and markup" and "Document and stamps".
However, the signature is still not being printed. Here is the code for digital signature.
void ISignatureAppearanceHandler.DrawAppearance(XGraphics gfx, XRect rect)
{
string signtext = "This is a digital signature";
XFont font = new XFont("Verdana", 8.0, XFontStyle.Regular);
XPoint xPoint = new XPoint(0.0, 0.0);
gfx.DrawRectangle(
XBrushes.LightBlue, xPoint.X,
xPoint.Y, rect.Width, rect.Height
);
XTextFormatter xTextFormatter = new XTextFormatter(gfx);
xTextFormatter.DrawString(
signtext, font,
new XSolidBrush(
XColor.FromKnownColor(XKnownColor.Black)
),
new XRect(
xPoint.X, xPoint.Y, rect.Width, rect.Height
),
XStringFormats.TopLeft
);
}

Try Printing your text before initiating PdfSignatureHandler it worked fine for me.
private static void SignExisting()
{
double height = 40;
double width = 200;
double x = 0;
double y = 0;
PdfDocument pdfDocument = PdfReader.Open(path);
PdfPage pp = pdfDocument.Pages[0];
var cert = GetCertificate();
string signtext = "Digitaly Signed by " + cert.GetNameInfo(X509NameType.SimpleName, false);
XGraphics gfx = XGraphics.FromPdfPage(pp);
XFont font = new XFont("Arial", 10, XFontStyle.Regular);
gfx.DrawString(signtext, font, XBrushes.Black, new XRect(x, pp.Height - y, pp.Width, pp.Height), XStringFormats.TopLeft);
gfx.DrawString("Date: " + DateTime.Now.ToString(), font, XBrushes.Black, new XRect(x, pp.Height - y, pp.Width, pp.Height), XStringFormats.TopLeft);
PdfSignatureOptions options = new PdfSignatureOptions
{
ContactInfo = cert.GetNameInfo(X509NameType.SimpleName, false),
Location = cert.Subject,
Reason = "",
Rectangle = new XRect(x, y, width, height),
AppearanceHandler = new SignAppearenceHandler()
};
PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(cert, null, options);
pdfSignatureHandler.AttachToDocument(pdfDocument);
Stream stream = new MemoryStream();
pdfDocument.Save(stream);
}

Related

Pick video from gallery with size limit in android

My requirement is pick video from gallery less than 25MB and show in my layout in android App.
Please try the below line of code to get the every video limit
String[] projection = new String[] {
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.DURATION,
MediaStore.Video.Media.SIZE
};
Cursor cursor = getApplicationContext().getContentResolver().query(
collection,
projection,
selection,
selectionArgs,
sortOrder
)
int sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
while (cursor.moveToNext()) {
int size = cursor.getInt(sizeColumn);
videoList.add(new Video(contentUri, name, duration, size));
}
Another way of get this using when in case of intent or ur need
File file = new File(parent,"test.mp4" );
Uri uri=Uri.fromFile(file);
long lengthSize = file.length();
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = fis.read(buf)) > 0) {
fos.write(buf, 0, len);
}
lengthSize = file.length();

Can't change font in Flex - Spark RadioButton

I am trying to change the font size and family of a spark Radiobutton I create in run time:
var radio:RadioButton = new RadioButton;
radio.layoutDirection = "rtl";
var format:TextFormat = new TextFormat();
format.font = "Tahoma";
format.color = 0x336699;
format.size = 13;
radio.setStyle("embedFonts", true);
radio.setStyle("textFormat", format);
radio.label = text;
radio.groupName = "radiogrp_" + index.toString();
hgrp.addElement(radio);
No matter what I try, the font stays the same. Both family and size remain default.
Thanks.
Define a nice TextFormat and then use it with setStyle:
attribFormat = new TextFormat(null, fontsize, 0x000000, null, null,null,null,null,"left");
myRadio.setStyle("textFormat", attribFormat);
Hope it helps!
Try
var radio:RadioButton = new RadioButton;
radio.layoutDirection = "rtl";
radio.setStyle("embedFonts", true);
radio.setStyle("fontFamily", "Tahoma");
radio.setStyle("color", 0x336699);
radio.setStyle("fontSize", 13);
I try this it works
var radio:RadioButton = new RadioButton();
radio.addEventListener(FlexEvent.CREATION_COMPLETE, onRadioAddHandler);
radio.label = "Some text";
radio.x = 200;
this.addElement(radio);
Handler
private function onRadioAddHandler(event:Event):void {
var radio:RadioButton = RadioButton(event.target);
radio.layoutDirection = "rtl";
radio.setStyle("fontFamily", "Tahoma");
radio.setStyle("color", 0x336699);
radio.setStyle("fontSize", 25);
}

web api post image with custom data

I am trying to post some custom data with image to web api. Please take a look at the method below.
public void Post(FlyerDetails FlyerDetails)
{
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
foreach (string file in httpRequest.Files)
{
var filePath = HttpContext.Current.Server.MapPath("~/Flyers/" + httpRequest.Files[file].FileName);
Bitmap bmp = new Bitmap(httpRequest.Files[file].InputStream);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawString(FlyerDetails.Message, new Font(FlyerDetails.FontColor, FlyerDetails.FontSize), Brushes.DarkRed, new PointF(0, 0));
g.Flush();
bmp.Save(filePath);
}
}
}
Now the problem is when i keep this method with parameter and post the data from fiddler it shows me 415 Unsupported Media Type error . If i remove the parameter then it is working fine. But i really need to pass the data along with the posted image.
Can any one suggest a good way to accomplish this ?
Thanks
After searching a lot i figured out the way to upload the data along with the image. Here is the revised version of the code. Hope that it will helpful to someone.
public async Task<HttpResponseMessage> Post()
{
var streamProvider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/Flyers/"));
await Request.Content.ReadAsMultipartAsync(streamProvider);
var response = Request.CreateResponse(HttpStatusCode.Created);
var filePath = "";// file path
if (System.IO.File.Exists(filePath))
{
string extension = Path.GetExtension(filePath);
Bitmap bmp = new Bitmap(filePath);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
Color brushColor = System.Drawing.ColorTranslator.FromHtml(streamProvider.FormData["FontColorCode"]);
g.DrawString(streamProvider.FormData["FontFamily"], new Font(brushColor.Name, Convert.ToInt32(streamProvider.FormData["FontSize"])), new SolidBrush(brushColor), new PointF(0, 0));
g.Flush();
bmp.Save(HttpContext.Current.Server.MapPath("~/" + Guid.NewGuid() + extension));
response.Headers.Location = new Uri(new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority) + "/Flyers/" + Guid.NewGuid() + extension);
}
return response;
}
NOTE : One should post the data as mutipart-formdata.
this line also gets a post parameter along with uploaded file:
string value = HttpContext.Current.Request.Params.Get("key");

How to make return the result of (need to bind image to view) webapi to getjson?

I am working on webapi. I had optimized the images and saving in folder here. I had uploaded images into one folder before uploading in to the destination folder.
I am optimizing a single image in to 3 different sizes (large, thumbnail, medium) but image sizes are saved in one folder, now I need to make return those images to view page and bind to view page. How can I do that? I am new to webapi.
Here my controllers
public Task<HttpResponseMessage> Post()
{
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var uploadFolder = HostingEnvironment.MapPath("~/App_Sprites/UploadFolder");
uploadFolder = Path.Combine(uploadFolder, DateTime.Now.ToString("yyyyMMddhhmmssfff"));
Directory.CreateDirectory(uploadFolder);
var streamProvider = new PreserveFilenameMultipartFileStreamProvider(uploadFolder);
return Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>
{
foreach (var uploadedFile in Directory.GetFiles(uploadFolder))
{
var thumbnail = Path.Combine(uploadFolder, "thumb-" + Path.GetFileName(uploadedFile));
var medium = Path.Combine(uploadFolder, "medium-" + Path.GetFileName(uploadedFile));
var large = Path.Combine(uploadFolder, "large-" + Path.GetFileName(uploadedFile));
ImageTools.Resize(uploadedFile, thumbnail, 80, 80);
ImageTools.Resize(uploadedFile, medium, 48, 48);
ImageTools.Resize(uploadedFile, large, 128, 128);
}
return Request.CreateResponse(HttpStatusCode.Accepted);
});
}
}
and my class file
public class ImageTools
{
public static void Resize(string original, string output, int width, int height)
{
using (var image = Image.FromFile(original))
using (var thumbnail = new Bitmap(width, height))
using (var graphics = Graphics.FromImage(thumbnail))
{
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.DrawImage(image, 0, 0, width, height);
ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
EncoderParameters encoderParameters;
encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
thumbnail.Save(output, info[1], encoderParameters);
}
}
}
and class file for save
public class PreserveFilenameMultipartFileStreamProvider : MultipartFileStreamProvider
{
public PreserveFilenameMultipartFileStreamProvider(string rootPath)
: base(rootPath)
{
}
public override string GetLocalFileName(HttpContentHeaders headers)
{
return headers.ContentDisposition.FileName.Replace("\"", "");
}
}
finally my layout page
#using (Html.BeginRouteForm("DefaultApi", new { httproute = "", controller = "Upload" }, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="image" multiple="multiple" accept="image/*" />
<button type="submit">Upload</button>
}
Here I had the images in folder now I need to save those images as well. I need bind those in my layout page how could I do that?
as of above question i have example sight that helps more follow and look for as above question to implement the coding for your implement
http://www.codeproject.com/Articles/379980/Fancy-ASP-NET-MVC-Image-Uploader?msg=4389108#xx4389108xx
as of above question no problem i think it is increasing with quality option you just have to do simple just decrease the quality make upload image and check it once
public static void Resize(string original, string output, int width, int height)
{
using (var image = Image.FromFile(original))
using (var thumbnail = new Bitmap(width, height))
using (var graphics = Graphics.FromImage(thumbnail))
{
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.DrawImage(image, 0, 0, width, height);
ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
EncoderParameters encoderParameters;
encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 80L);
thumbnail.Save(output, info[1], encoderParameters);
}
}

Flex, Problem when jpegencoding two bitmaps in sequence

I am creating this "drawing application", where the user can click "preview" and it will take what they made, draw a bitmap, and then I want to split that bitmap into left and right images. I create the first bitmap, encode it as a jpeg, and then use that to cut the left and right out using copypixels. I then reform the images together with a space inbetween in one canvas, and draw that canvas. Everything works fine up there.
When I go to encode the new bitmap, and then offer it to save out, the saved image is blank. I have tested everything up to that point and it all works fine. I see the images on screen, I can save out the first bitmap fine.. but the second one is always blank. Here is some sample code, possibly someone can help me out.
_mainBmd = new BitmapData(_jacketWidth, _jacketHeight);
_mainBmd.draw(_imageHolder);
startEncode(_mainBmd);
private function startEncode(imageBitmapData:BitmapData):void
{
var encoder:JPEGAsyncEncoder = new JPEGAsyncEncoder(100);
encoder.PixelsPerIteration = 150;
encoder.addEventListener(JPEGAsyncCompleteEvent.JPEGASYNC_COMPLETE, encodeDone);
encoder.encode(imageBitmapData);
}
private function encodeDone(event:JPEGAsyncCompleteEvent):void
{
_leftBmd = new BitmapData(sideWidth, sideHeight);
var lRect:Rectangle = new Rectangle(0,0, sideWidth, sideHeight);
var lPoint:Point = new Point(0,0);
_leftBmd.copyPixels(_mainBmd, lRect, lPoint);
_rightBmd = new BitmapData(sideWidth, sideHeight);
var bWidth:Number = 200;
var sWidth:Number = 111;
var rRectWidth:Number = (bWidth/2 + sWidth) * Constants.print_dpi;
var rRect:Rectangle = new Rectangle(rRectWidth, 0, sideWidth, sideHeight);
var rPoint:Point = new Point(0, 0);
_rightBmd.copyPixels(_mainBmd, rRect, rPoint);
var lbm:Bitmap = new Bitmap(_leftBmd);
var rbm:Bitmap = new Bitmap(_rightBmd);
//now combine the two images into one holder with a space in the middle
//left Image
var l_Image:Image = new Image();
l_Image.source = lbm;
//right image
var r_Image:Image = new Image();
r_Image.source = rbm;
var newRender:Canvas = new Canvas();
newRender.clipContent = false;
newRender.minHeight = 0;
newRender.minWidth = 0;
newRender.addChild(l_Image);
r_Image.x = 500;
newRender.addChild(r_Image);
fcBMD = new BitmapData(renderW, renderH);
fcBMD.draw(newRender);
startEncode2(fcBMD);
}
private function startEncode2(imageBitmapData:BitmapData):void
{
var encoder:JPEGAsyncEncoder = new JPEGAsyncEncoder(100);
encoder.PixelsPerIteration = 150;
encoder.addEventListener(JPEGAsyncCompleteEvent.JPEGASYNC_COMPLETE, encode2Done);
encoder.encode(imageBitmapData);
}
private function encode2Done(event:JPEGAsyncCompleteEvent):void
{
_data = event.ImageData;
}
private function onSaveRenderClick(e:MouseEvent):void //save button listener
{
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(Event.SELECT, onSaveComplete);
fileRef.save(_data, 'testImage.jpg');
}
Is there a special reason why you go trough all the loops of creating a Canvas holder and adding Images?
Why not use copyPixels directly on the final BitmapData that you want to encode:
var backgroundColor:uint = 0xffffff;
fcBMD = new BitmapData(renderW, renderH, false, backgroundColor);
var lPoint:Point = new Point(0,0);
var lRect:Rectangle = new Rectangle(0,0, sideWidth, sideHeight);
fcBMD.copyPixels(_mainBmd, lRect, lPoint);
var rRect:Rectangle = new Rectangle(rRectWidth, 0, sideWidth, sideHeight);
var rPoint:Point = new Point(renderW - sideWidth, 0);
fcBMD.copyPixels(_mainBmd, rRect, rPoint);
startEncode2(fcBMD);

Resources