Replacement for Acrobat method AFormAutLib.setButtonIcon - c#

An existing process uses the Adobe Acrobat COM object AFormAutLib to open and fill form items. There are over 500 forms, and they all have a form field of type Button at the top. The method AFormAutLib.setButtonIcon is used to set the path of another PDF file to be used as the image on the button.
I am looking for an alternative. I have looked at iTextSharp, activePDF Tookit, and others, but have been unable to find anything that can replace this functionality.
Thanks in advance.

The solution was to use activePDF Toolkit in a different way...
APToolkitNET.FieldInfo myFI = aTK.FieldInfo(x.Key.ToString(),1);
aTK.PrintImage(logoPath, myFI.Left, myFI.Bottom, myFI.Width, myFI.Height, true, 1);
aTK.DeleteFormField(x.Key.ToString());
The button had the right location and dimensions, so the FieldInfo class is used to get those values. Then PrintImage is called with the path to the image and the locations, before the button is deleted.

Related

print a form with texts in c# that looks like a word document

i am trying to create a contract (document) that I can print like a normal word document.
I have a form which is my 'entry form') where i can type in details such as customer name, amount,date of contract etc. these information is then saved in ms access.
i have another form (which i call 'contract doc'). it has labels in it and the label holds the information i typed in my 'entry form'. I assigned one label to get the values that i entered in the textbox in the entry form.
contractdoc.contract_date_label.Text = contract_date_tb.Text;
contractdoc.deposit_label.Text = deposit_tb.Text;
contractdoc.customer_name_label.Text = customer_name_tb.Text;
i also added labels and typed the rest of the documents body and position them in the 'contract doc form ' to look like an actual contract.
but i dont know how to print it like a document. i iused :
printForm1.Print();
but what happens is, it asks me to save in xls format and only a messege box that says:"printing page 1 of document" with a cancel button.
I hope you can help. thank you in advance
I presume from the name printForm1, that you're using the PrintForm class provided as part of the Visual Basic PowerPack.
In that case, you need to make sure that the PrintAction property is set appropriately. To print to a physical printer, you need to set it to PrintAction.PrintToPrinter. Depending on what printer is configured as the system default, you might also need to set the PrinterSettings property. Then when you call the Print method, it will print to the correct printer.
It's probably prompting you to save the file in XLS format because your system default printer is a virtual one that generates XLS files.

Ranorex test automation issue: Unable to reliably click a button on silverlight web app

We have automated a few test cases using the Ranorex automation framework for a Silverlight web application. These test cases involve clicking buttons in order to invoke certain messages on the screen. In order to grab the button on the screen, we first create an Ranorex button object and then point it to the appropriate element using Ranorexpath. Then, we use the RanorexButton.Click() event to click the button. However, this event is unreliable. It works sometimes and at other times the button is not clicked. When the button is not clicked, we have to run the test case again from the start. What are we doing wrong? If this is a known problem of ranorex, please suggest workarounds.
I was facing the same problem but I am able to resolve the problem by introducing a Validate.Exists(infoObject) just before the click. Please make sure that you pass infoObject of your button or any element in Validate.Exists API.
Example:
Validate.Exists(repo.MyApp.LoginBtnInfo);
var button = repo.MyApp.LoginBtn;
button.Click();
With regards,
Avinash Nigam
I haven't heard about such a problem with Ranorex yet, maybe this is just a timing issue.
You could add a Validate.Exists(yourButton) right before the click, this ensures that the click is performed after the button was successfully loaded.
If it is a WebElement you could also use the PerformClick() method instead of the normal Click() method.
There are also different methods which will ensure that the button is in the visible area and has focus, like the EnsureVisible() or the Focus() method.
You will find the available methods of the used adapter in the online API of Ranorex.
If the Button is not within the area you can see without scrolling, you can use a
var button = repo.Buttons.button1;
button.EnsureVisible();
button.Click();
In this way the button is forced to be watched.
It might as well be an issue with the xpath and element Id-s.
If you have changing element Id-s even when the page is navigated away from and moved back (for example we have this issue with SAP related components) you might need to make a more robust xPath path variable using regular expressions.
Try to find object and parts of the path that do not change (eg. "iFrame id="MainContent"" or "btn id="ID_XXXX_Search_Button"") - ofcourse this will only help if the issue is within this.
Ranorex Regular Expression info can be found here: http://www.ranorex.com/support/user-guide-20/ranorexpath.html#c3294
A quick example of what I'm talking about:
Let's say we have an input field that has a changing ID in it's name:
US_EL.ID_F2B49DB60EE1B68131BD662A21B3432B:V_MAIN._046A-r
And I know that the part in the Id that doesn't change is:
:V_MAIN._046A-r
I can create a path for this searching the element by the ending of the elements' id that doesn't change using regular expression:
/dom[#domain='test.example.com']//iframe[#'identifier']//iframe[#'identifier2']//input[#id**~'^**:V_MAIN._046A-r']
The bold part will specify to search for an input element with an Id that ends with ":V_MAIN._046A-r".
An issue that might arrise from this is if you have elements using partially the same names you might get multiple elements returned for the same path. So it's wise to add a few more certain points to the path (eg. "iframe[#'identifier2']") when this issue arrises.

how to resize a picture programatically and add it to the web site

Hi there
I am working with visual web developer and would a) like to know how I could programatcally add a picture to the website, instead of going to Website and then add existing item. The idea I have is to upload the picture using the file upload control but then I want to have it added so that it can be accessed using a gridview.
b)I would also like to know how to size the picture using C# code obviously so that is displayed at the correct size.
best regards
arian
here is a full project with source code to manipulate images, including resize.
http://www.codeproject.com/KB/web-image/ASPImaging1.aspx
And a sample code only for resize
http://weblogs.asp.net/gunnarpeipman/archive/2009/04/02/resizing-images-without-loss-of-quality.aspx
You can use GetThumbnailImage to easily create a smaller verson of the uploaded image. The code looks something like (it's free typed without a compiler, so there may be some errors):
System.Drawing.Image pic = new System.Drawing.Bitmap(sourceFilename);
System.Drawing.Image thumb = pic.GetThumbnailImage(targetXSize,targetYSize,
new System.Drawing.Image.GetThumbnailImageAbort(this.GetThumbnailImageAbort),
IntPtr.Zero);
thumb.Save(thumbPathName);
I believe the Image implements IDisposable, so you need to remember to Dispose of them when you're done.
The abort parameter can be a function that simply does this (can't remember off the top of my head when it gets called):
bool GetThumbnailImageAbort() {
return false;
}

asp.net Fontdialog problem in web application

I want to display font dialog box in my web application(asp.net). Im using the following code. Its working fine.
Problem:
Dialogbox is getting open but it is behind the page. Even though i closed the application it is still open. It is not binded to the application.
Code:
FontDialog fontDialog = new FontDialog();
fontDialog.ShowColor = true;
DialogResult dR = fontDialog.ShowDialog();
if (dR == DialogResult.OK)
{
txtChange.Font = fntDialog.Font;
}
Edit:
I want to create an application for Entry pages to fill the database.
In this i want to store text and its font size, name and color.
Im my mind there are two options:
Displaying the fonts from the system.(Dropped bcz these entry page application is in the one system and the report page application going to run kiosk). It will create problem if the fonts are not available in the kiosk.
Font dialogbox.(Also creating problem)
Please is there any other good option for this.
Er.... this is NOT a good idea. This dialog will launch on the server, which means if you are accessing this from a remote computer (which is more than likely), you'll never see the dialog, but the server could end up with countless dialog instances popping up.
What use is the fonts dialog in a web application anyway??
EDIT: To be safe, I'd produce a list of known fonts on the system and then simply list them in a drop down box. You've already discovered the problem with enumerating the fonts and attempting to use a dialog.
There are lots of Html font coloring panel free over web , written in javascript. For setting values of Font Sizes you can use a dropdown for the same with your predefined values. While saving , save the value of font size and its concerned data as plain text in db and while fetching apply it.

Render HTML as an Image

I'm generating a coupon based on dynamic input and a cropped image, and I'm displaying the coupon using ntml and css right now, the problem is, printing this has become an issue because of how backgrounds disappear when printing and other problems, so I think the best solution would be to be able to generate an image based on the html, or set up some kind of template that takes in strings and an image, and generates an image using the image fed in as a background and puts the coupon information on top.
Is there anything that does this already?
This is for an ASP.NET 3.5 C# website!
Thanks in advance.
edit: It'd be great if the output could be based on the HTML input, as the coupon is designed by manipulating the DOM using jQuery and dragging stuff around, it all works fine, it's just when it comes to the printing (to paper) it has z-indexing issues.
What you can do is create an aspx page that changes the response type to be in the format you want and then put the image into the stream. I created a barcode generator that does a similar thing. Excluding all the formalities of generating the image, you'll Page_Load will look something like this:
Bitmap FinalBitmap = new Bitmap();
MemoryStream msStream = new MemoryStream();
strInputParameter == Request.Params("MagicParm").ToString()
// Magic code goes here to generate your bitmap image.
FinalBitmap.Save(msStream, ImageFormat.Png);
Response.Clear();
Response.ContentType = "image/png";
msStream.WriteTo(Response.OutputStream);
if ((FinalBitmap != null)) FinalBitmap.Dispose();
and that's it! Then all you have to do in your image is set the URL to be something like RenderImage.aspx?MagicParm=WooHoo or whatever you need. That way you can have it render whatever you want to specify.
You can render html to a bitmap using the WebBrowser control in either a winforms or console application.
An example of this can be found here: http://www.wincustomize.com/articles.aspx?aid=136426&c=1
The above example can be modified to run in ASP.Net by creating a new STAThread and performing an Application.Run on it to start a new message loop.
PHP/Ruby Alternative
If you have accessed this question and are actually looking for soething that will work without Windows, you can try the KHTML library: http://wiki.goatpr0n.de/projects/khtmld
The website has a ridiculous name I admit, but I can assure you it is genuine. Other related pages are: the sourceforge page http://khtml2png.sourceforge.net/
Try PDFSharp...it's not exactly a "take this HTML and make a PDF" but with a small amout of fiddling you can easily make a PDF out of the info you are using to make the HTML.
MARKUP ONLY ALTERNATE SOLUTION
Use SVG and XSLT to transform the html data into an image that can be rendered/saved/etc.
I'll admit that at first it was tedious getting this to work because of all of the coordinates, but well worth the effort once it is running.
There is a very powerful image creation library called GD which I often use with PHP.
I am led to believe there is a wrapper for this library that ASP programmers can use. Try this
Unless the "other problems" are pretty severe, couldn't you just instruct your users to turn on Background Images when printing?
In any case, I'd default to serving a PDF rather than an image, doubly so since it is intended for print.
Just set up your css properly, so that you have a css file targeted at the print medium. It is pretty easy to guarantee that the coupon will always be legible, without worrying about whether they have bg images on or not. Needlesly moving to an image doesn't make any sense, unless there is some reason you don't want it to be machine readable.
I haven't tried to myself, but you should be able to render HTML into an image by using the WebBrowser control and the DrawToBitmap() method inherited from the base Control class.
UPDATE: I tried this myself and there are some caveats. The WebBrowser control doesn't seem to render the web page until the control is show, so the WebBrowser needs to be in a Form and the Form must be shown for the HTML to be rendered and the DocumentCompleted event to be raised.

Categories

Resources