Overwrite the date format in the header of a printed HTML document using Delphi - datetime

I have a Delphi application that uses a TWebBrowser to allow the user to print an HTML document. I'd like to control the Date/Time format shown in the header when a user prints the document. By default, it's set to mm/dd/yyyy. How can I overwrite this Date/Time format so it show something different in a print-out?
Code used to print:
var WebHTML : TWebBrowser;
//Code to populate the TWebBroser with the HTML document...
//Prompt the user to print the HTML file, show print dialog
WebHTML.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
I want to control the Date/Time format from my application, preventing users from changing this by using the print dialog. If I can set the date format in my code, I won't even have to prompt the user - I can just call ExecWB with OLECMDEXECOPT_DONTPROMPTUSER.
I also tried using HTML/CSS to control the Date/Time values - but I don't think the headers/footers of the printout can be modified by using HTML or CSS.

Related

IE10 / Edge PDF not showing correct values

So I have a PDF that has been created on the fly by opening a template, modifying the values for certain fields, and then saved.
Works:
If I open the file in Chrome, I have the correct values.
If I save the file to disk and open it with Adobe Reader DC (or whatever that's called), I get the correct values.
Doesn't Work:
When I open the document in IE 10, it opens in Edge, and shows "default" values for the fields.
When I save the file to disk and open it with IE, it shows "default" values.
When I open the file using "PDF reader - Document Viewer and Manager" it shows "default" values.
I'm using Windows 10, the application I'm working on is done in ASP.Net. It works the same way whether I return a FileStreamResult, FilePathResult, or File.
And I'm now pretty much certain the problem is Microsoft's products and not my code.
Any idea why Microsoft products are incapable of opening my PDFs correctly? Do they have to be flattened in some specific way or something?
Edit (more information as requested in comments):
The documents are created using PdfSharp.
They have fields that are dynamically replaced with values (i.e. [MyFieldA] is replaced with "ActualValueA").
Once the merge fields are replaced with actual values, the file is written using File.WriteAllText(fileName,fileText); where fileText is obtained through File.ReadAllText(fileTemplateName);
Image of comparison of fields that are wonky:
So I found the solution to the problem, and it appears that it might be a two-fold thing.
One piece of the puzzle I believe was the memorystream being used to create the PDF. It was declared in an inner scope, used in a PdfReader.Open call in an assignment to a var that was declared in an outer scope, and then the scope ended, while the var was still being used. I moved the memorystream declaration to the outer scope where the var declaration was so that they would be in the same scope. Also, the memorystream wasn't being closed with a memoryStream.Close() call or in a using (var memoryStream = new MemoryStream()) { } block. So I added a call to memoryStream.Close().
The other piece is that the PDF template form fields had some default display values. It appears that Microsoft stuff (Edge, PDF Viewer) may not be able to get the inserted values, and is instead reading the default display values of the fields and displaying those. Once all of the default display values were removed, Edge began opening the PDF and displaying values correctly.
Since these two pieces were done in tandem, I can't say for certain that they both play an equal role in this, but these are the only two changes that were done to get values to start displaying correctly. My gut feeling is that the problem lies with the default display values and Edge.

ReportExecutionService.Render() - missing hyperlink from report column

I am working on peace of code where, rendering a report using ReportExecutionService.Render() method. I have passed following parameters to this method;
string format = "EXCELOPENXML";
string devInfo = #"False";
Report contains one column with hyperlink, but after rendering the report with Render method, output file is missing that hyperlink. If I export same report from report viewer to excel, resulting excel has the hyperlink on that column.
What can be the possible issue for missing hyperlink? Do i need to specify any particular format (i tried same thing with HTML, PDF formats as well but no luck)? Is there any workarround to get the hyperlink into the rendered report using ReportExecutionService.Render()?

ASP.NET ReportViewer Parameter Prompt doesn't show

I've been looking for this answer for a couple days now and I've been getting little bits of information that make it seem that you can have ReportViewer Control automatically prompt for the report's parameters. Just everything that I've tried and found doesn't seem to work. I've gotten the Parameter Prompts to work on a Windows Form but I just cannot get it to work in ASP.NET
I guess I'm simply asking can you get Report-viewer's Parameter Prompts to work in ASP.NET? if so, How?
I know you can do it manually, it's just, I feel if you can make ReportViewer Prompt automatically why program it yourself?
Edit: this is for local processing btw.
Prompting for parameters is not supported in local processing mode.
In article Report Parameters Dialog Box (Visual Studio Report Designer), which is invoked by clicking the Help button on that dialog, it says in the introductory text that:
The parameters properties that you specify in the Report Parameters
dialog box become part of the report definition. Some properties are
intended for programmatic use only. In contrast with reports that are
processed on a remote report server, a locally processed report does
not have a parameter input area used for selecting or typing parameter
values.
A little testing shows me that the default values specified for the parameters will be used, unless you modify them programmatically. I could not find an explanation on this design decision. If you want to use local processing, and prompt for user input, I would recommend to follow this solution:
I you embed the reports in a ReportViewer Control, you can put it on a page or form and add custom input controls to that page or form to gather report parameters. In the code-behind files, you will then pass the parameter values using code like this:
List<ReportParameter> parameterList = new List<ReportParameter>();
List<string> selectedProductTypes = listboxProductTypes.GetSelectedValues();
ReportParameter productTypes = new ReportParameter("ProductTypes", selectedProductTypes.ToArray(), false);
ReportParameter username = new ReportParameter("Username", "<current user>", false);
parameterList.Add(productTypes);
parameterList.Add(username);
reportViewer.LocalReport.SetParameters(parameterList);
In this example, you can see how to pass a multi-valued parameter, the values of which are taken from a multi-select ListBox.
You can also create a page that has the controls to gather the parameter input, put them in a set session variables and then transfer to the page that has the report viewer.
use object data source and set the parameter source as Session.
The only code you need to write is filling the session variables.

How to capture the output from wmd editor in C# asp.net 3.5

I'm using WMD -editor in a message board Application that I am developing in ASP .net 3.5 using C# .
How can I capture the output(markdown?) to the server side so that I can save the user input.
All I could come up is this :
var txt =document.getElementById("wmd-output").innerHTML;
If you're capturing the input as the user is writing the post, e.g. to save a draft, then what you have above is fine and should work.
If you mean capturing the Markdown after the form has been submitted then you need to remove the call to convertToHtml(). The WMD editor converts the Markdown on the fly and submits this in the form for some reason (doesn't seem all that useful if you want to be able to edit the Markdown later).
The call is around line 1200 in the file wmd.js. Either delete or comment the convertToHtml() line.
edit: looks like there is a better way to do this: Using wmd-new to submit markdown

Embed word document into ASP.net page and access using VBscript

I have some code that opens a word document using VBScript on an ASP.net page:
set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "c:\inetpub\wwwroot\JSWordTest\test.doc", False, False, False
This works great but opens the word doc in another window. Ideally I would like to make this look as if it is contained in the current page perhaps in an IFrame. I have some other buttons which paste text into the word document when clicked.
I cannot just set the src of the iframe to the word document as need a reference to the word document (objWord) to allow me to paste text into it in real time again using Vbscript to do this.
Not sure if this is possible but any ideas/alternatives welcome?
Requirements:
The word doc needs to be displayed from web browser
At the side of the word document will be some buttons which when clicked paste text into it
You can use this technique to get the contents of the Word document without displaying any windows at all.
' Declare an object for the word application '
Set objWord = CreateObject("Word.Application")
objWord.Visible = False ' Don''t show word '
objWord.Documents.open("C:\test.doc") ' Open document '
objWord.Selection.WholeStory ' Select everything in the doc '
strText = objWord.Selection.Text ' Assign document contents to var'
objWord.Quit False ' Close Word, don't save '
Once you've got the contents of the document in the variable you can do what you want with it as far as writing it out with a document.write or whatever method you want to use.
You can find more detail on the MS Word application object and its methods here: http://msdn.microsoft.com/en-us/library/aa221371(office.11).aspx
If it is an option to install an ActiveX component at the client machines, you can try EDraw Office Viewer component or the cheapter Ultra Office Control. Both are based on the DSOFramer example by Microsoft and provider similar methods to interface with the documents.
Sample code is given and shows how to trigger dialogs, insert text, etc.
You can get inspirations from Excel Viewer component. It is like EDraw Office Viewer but free and open source. Currently, it opens office documents only but you can easily change it to work with Word.
You could try saving to HTML format
Const wdFormatHTML = 8
dim doc
set doc = objWord.Documents.open("C:\test.doc")
doc.SaveAs "doc.htm", wdFormatHTML
' etc ...
and then use that as the source of your iframe document. Bear in mind that when saving to HTML format, Word creates a corresponding resources folder (for images etc), so you might need to take that into account.

Resources