How to set language in TWebBrowser - delphi

I need to set the language in a TWebBrowser component according to some properties of your program.
The problem is that i have to show, for example, dates according to the specific country dateformat. I already tried to find some hints in the docs, but without success.
So my question is:
Is there some possibility to set the language of a TWebBrowser like i can do in a normal instance of Internet Explorer?

We now solved it with a little workaround:
I pass an additional parameter with the URL, describing the language of the User. With this language we decide via Javascript which Formats to use.
Of course this is just a workaround and only possible if you can customize the website to call, but i haven't yet found another solution to manage this with Delphi.
I would be glad to read some other / better / simpler solutions.

Try this e.g. for de = German Language like:
header_string := 'Accept: text/html,application/xhtml+xml,'
+ 'application/xml;q=0.9,image/webp,*/*;q=0.8'
+ chr(13) + chr(10) // Linefeed
+ 'Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4'
+ chr(13) + chr(10); // Linefeed
WebBrowser1.Navigate(url,16,0,header_string);

Related

How to get Elements List from WebView in Delphi?

I Can Browse webpage by TWebView Component in Delphi. Can Fill Elements by javascript command.
Example:
WebView1.ExecuteScript( 'document.getElementsByName("name")[0].value = "' + Edit2.Text + '";');
How do I get Elements List or Tags List with their attributes (ex. Name, ID, ClassName, ref, ...).
I Googling and read all pages in web but can not found any help for Delphi.
Please Help me.
thanks.

Delphi, Handles in TPanel objects

I was reading the source code for tmplayer and MPUI, both media players that use MPlayer as a backend to play media files in Delphi and I noticed here as well as in other older codes that I tried to experiment with that I can't use
Form1.Rectangle1.Handle
or as it is in this example for tmp layer that is trying to pipe the video output at a TPanel
CmdLine := HomeDir + 'mplayer.exe -slave -identify'
+' -wid ' + IntToStr(Form1.Panel1.Handle) + ' -colorkey 0x101010'
+' -nokeepaspect -framedrop -autosync 100' + #32 + Media;
As you may see RAD studio xe6/7 complains that the element does not contain a parameter named Handle. Is this something that used to be valid in older versions but can't be used anymore, and if yes how can I accomplish the same task in a simple Firemonkey form.
EDIT
Ok, so now it is clear to me that the Handle parameter is only applicable for VCL Forms. Trying to rephrase my question,
How can I port that particular line of code (getting the handle of a component) in a Firemonkey form?
Panels and/or Rectangle in Firemonkey doesn't have Handle as member. FireMonkey Handle is member of Form component instead .
You can convert a FireMonkey handle to the platform specific handle with the function : WindowHandleToPlatform, but there is no way to get the handle of a control inside a Form .
Maybe you can replace the Rectangle with another inner form and get the handle of it. Take a look at the FMXEmbeddedForm .

Why numbers getting reversed when formatted in RTL Arabic - Rails application?

I'm using Prawn gem in my Rails app to generate PDF reports.
I read the documentation for putting the text in Arabic with text_direction RTL in arabic.
But, issue is that numbers are getting reversed here.
I wanted semester 1234 as الفصل الدراسي 1234,
but in my app the output is الفصل الدراسي 4321.
My two lines of code is here:
pdftable = Prawn::Document.new
pdftable.text(t('org.semester') + " " + #semester)
#semester = '1234' (The reason would be that it is being treated as a text/string, thus changes to RTL (reversed))
Anyway, Please help me to retain numbers in proper order without changing the RTL format.
Without hacking too much you could use
#semester.to_s.reverse
So you reverse the string twice

html2pdf and local (latvian) language characters

I am using Html2PDf to convert html to pdf.
But I am not able to achieve that it shows local (latvian) language letters. It shows ? instead.
I do understand that I should somehow add appropriate fonts, but I do not know where to get those fonts (which one support latvinan language) and how to add them into html2pdf.
Html2Pdf is based on tcpdf and currently there is font folder.
I think that is seems trivial question, but I was searching via google, but have not found answer that works for me.
require_once('inc/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en');
//$html2pdf->pdf->setDefaultFont('times');
// HEADER
$pdf_output .='<page style="font-size: 11px; >';
$pdf_output .= '<img src="images/raka_pdf_logo.png" alt="logo"/><br><br><br><br>';
...
You may find the right font-family in html2pdf>tcpdf>fonts

How do I work with Word Documents without using COM Automation?

I have read multiple posts on the issue, and none seem to come to a decent conclusion to my question. (Perhaps I'm trying to see if anything has popped up lately.)
I have a small charity app that handles pledges. In doing so, it needs to work with and print documents.
Thing is, if Word is open in the background, the app thread will hang and won't respond to the closure of Word, and I have to roll back manually and close word. Sure, that all works fine, but I simply cannot guarantee that the end user will close Word, even if I put the instruction in a user manual.
I'm not too fussed about speed, but I guess that if it can be enhanced, it would be a nice little bonus.
Have any libraries been released for Delphi that will allow me to open, edit, print, and save documents? If not, is there a way to use Word Automation in such a way that it will not conflict with another open handle of Word when opened?
If you use GetActiveOleObject, you will get the running instance of Word.
By using CreateOleObject, you will get a new instance and shouldn't be troubled by other running instances.
In case you use the TWordApplication, wrapper you can set ConnectKind to ckNewInstance to accomplish this. By default, TWordApplication will try to connect with a running instance.
If you want to open edit and print Word documents and you don't mind using RTF format for what you're doing, investigate TRichView.
It will generate rich documents that are in RTF format, which is one of the formats MS word supports. I don't think it directly reads .DOC files but you can convert .DOC and .DOCX into RTF, for most simple files, but certain advanced formatting features would be lost in the conversion.
It has the advantage of working without any need for even any copy of MS Word to be installed on the machine that is going to do the document processing. For production of receipts and other simple documents, this would be the most reliable technique; Don't use Word directly, at all.
procedure PrintViaWord (const filename: string);
const
wdUserTemplatesPath = 2;
var
wrdApp, wrdDoc, wrdSel: variant;
begin
wrdApp:= CreateOleObject ('Word.Application'); // create new instance
sleep (5000); // this fixes a bug in Word 2010 to do with opening templates
wrdDoc:= wrdApp.documents.add (
wrdApp.Options.DefaultFilePath[wdUserTemplatesPath] + '\mytemplate.dot');
wrdDoc.Select;
wrdSel:= wrdApp.selection;
wrdApp.Options.CheckSpellingAsYouType:= 0;
wrdSel.paragraphformat.alignment:= 1;
wrdSel.typetext ('This is a program demonstrating how to open Word in the background'
+ ' and add some text, print it, save it and exit Word');
wrdDoc.SaveAs (filename + '.doc');
wrdApp.ActivePrinter:= 'Konica Minolta 211';
wrdApp.PrintOut;
WrdDoc.SaveAs (filename + '.doc');
wrdApp.quit;
wrdSel:= unassigned;
wrdDoc:= unassigned;
wrdApp:= unassigned
end;

Resources