Flow Document Paper Size - printing

I an trying to make a flow document and print with, I was able to adjust the data to required size, and I am getting the required output.
Below is the code for my Flow Document:
<Window x:Class="test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="test" Height="600" Width="500">
<Grid>
<FlowDocumentReader Width="330" Height="110" Name="DocumentRdr">
<FlowDocument FontSize="8" Name="Document" >
<Paragraph Margin="0">
<TextBlock Text="Brand:"/>
<Run Text="{Binding Brand}" />
</Paragraph>
<Paragraph Margin="0">
<TextBlock Text="Item:"/>
<Run Text="{Binding Cat1}" />
<TextBlock Text="Size:"/>
<Run Text="{Binding Size}" />
</Paragraph>
<Paragraph Margin="0">
Welcome
<Run Text="{Binding Brand}" />
</Paragraph>
<BlockUIContainer Margin="0">
<Image Source="{Binding BarCode}" Width="Auto" Height="Auto" Stretch="None" HorizontalAlignment="Left" />
</BlockUIContainer>
</FlowDocument>
</FlowDocumentReader>
</Grid>
</Window>
and the code I use for printing is as follows:
Dim data As New SampleData With {.Brand = "Some Brand", .Cat1 = "A Cat 1", .Size = "100-120"}
Dim k As Zen.Barcode.BarcodeDraw = Zen.Barcode.BarcodeDrawFactory.Code25InterleavedWithoutChecksum
Dim ms As New MemoryStream
k.Draw("1234", 25).Save(ms, System.Drawing.Imaging.ImageFormat.Png)
ms.Position = 0
Dim bi As New BitmapImage
bi.BeginInit()
bi.StreamSource = ms
bi.EndInit()
data.BarCode = bi
Dim temp As New test
temp.DataContext = data
Dim doc = temp.Document
doc.PageHeight = 110
Dim pd = New PrintDialog()
Dim dps As IDocumentPaginatorSource = doc
dps.DocumentPaginator.PageSize = New Windows.Size(100, 100)
If pd.ShowDialog() = True Then
dps.DocumentPaginator.PageSize = New Windows.Size(330, 110)
pd.PrintDocument(dps.DocumentPaginator, "Document")
End If
The Problem is, the text and image every thing comes in the size I want, but I am not able to change the size of the paper. I am trying to print labels, due to long page I am getting a print for every 10-12 labels, I want to change the paper size.
This print dialog is part of system.windows.control and not system.drawings.printing. I tied to change the code by keeping required size in every place in code where there is size, but not able to do. Could you please correct me, where I went wrong.
Tried the below code too:
pd.PrintQueue.DefaultPrintTicket.PageMediaSize = New System.Printing.PageMediaSize(10, 10)

Related

In Elmish.WPF (F#), how is the Binding written to support a tabcontrol within another tabcontrol with different models?

As a complete newbie (but learning fast), I've been studying through Elmish.wpf but it is unclear to me how to manage a TabControl placed on a TabItem of another TabControl. For example, in Xaml, the top level window is:
<Window x:Class="FrontOffice.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FrontOffice"
xmlns:doctor="clr-namespace:Doctor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Window.Resources>
<DataTemplate x:Key="DoctorViewTemplate">
<doctor:DoctorView />
</DataTemplate>
<DataTemplate x:Key="NurseViewTemplate">
<local:NurseView/>
</DataTemplate>
<DataTemplate x:Key="MedicalRecordsViewTemplate">
<local:MedicalRecordsView/>
</DataTemplate>
<DataTemplate x:Key="PatientViewTemplate">
<local:PatientView/>
</DataTemplate>
<DataTemplate x:Key="ProvidersViewTemplate">
<local:ProvidersView/>
</DataTemplate>
<local:PropertyDataTemplateSelector x:Key="templateSelector"
DoctorViewTemplate="{StaticResource DoctorViewTemplate}"
NurseViewTemplate="{StaticResource NurseViewTemplate}"
MedicalRecordsViewTemplate="{StaticResource MedicalRecordsViewTemplate}"
PatientViewTemplate="{StaticResource PatientViewTemplate}"
ProvidersViewTemplate="{StaticResource ProvidersViewTemplate}"/>
</Window.Resources>
<Grid>
<TabControl ItemsSource="{Binding Tabs}" ContentTemplateSelector="{StaticResource templateSelector}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Header" Value="{Binding Header}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
</Window>
Each of the views: DoctorView, NurseView, MedicalRecordsView, etc.., have thier own tab control similar to this (but with different views and properties):
<UserControl x:Class="Doctor.DoctorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Doctor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<DataTemplate x:Key="AppointmentsViewTemplate">
<local:AppointmentsView />
</DataTemplate>
<DataTemplate x:Key="ChartStatusViewTemplate">
<local:ChartStatusView/>
</DataTemplate>
<DataTemplate x:Key="CheckInViewTemplate">
<local:CheckInView/>
</DataTemplate>
<local:PropertyDataTemplateSelector x:Key="templateSelector"
AppointmentsViewTemplate="{StaticResource AppointmentsViewTemplate}"
ChartStatusViewTemplate="{StaticResource ChartStatusViewTemplate}"
CheckInViewTemplate="{StaticResource CheckInViewTemplate}"/>
</UserControl.Resources>
<Grid>
<TabControl ItemsSource="{Binding Tabs}" ContentTemplateSelector="{StaticResource templateSelector}">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Header" Value="{Binding Header}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
</UserControl>
The Top Most Window in F# is currently defined as:
namespace FrontOfficeModels
open Elmish.WPF
open Elmish
module FrontOffice =
type DetailType =
| DoctorView
| NurseView
| MedicalRecordsView
| PatientView
| ProviderView
type Tab = { Id: int; Header: string; Type: DetailType }
type Model =
{ Tabs: Tab list
Selected: int option }
type Msg =
| Select of int option
let init () =
{ Tabs = [{Id=0; Header="Doctor View"; Type=DoctorView}
{Id=1; Header="Nurse View"; Type=NurseView}
{Id=2; Header="Medical Records View"; Type=MedicalRecordsView}
{Id=3; Header="Patient View"; Type=PatientView}
{Id=4; Header="Provider View"; Type=ProviderView }
]
Selected = Some 3 }
let update msg m =
match msg with
| Select entityId -> { m with Selected = entityId }
let bindings () : Binding<Model, Msg> list = [
"Tabs" |> Binding.oneWay (fun m -> m.Tabs)
]
let designVm = ViewModel.designInstance (init ()) (bindings ())
let main window =
Program.mkSimpleWpf init update bindings
|> Program.withConsoleTrace
|> Program.runWindowWithConfig
{ ElmConfig.Default with LogConsole = true; Measure = true }
window
Now, I'm thinking I need to change DoctorView, NurseView, etc... in the DetailType to be separate models -- since each will now have its own tab control and completely different properties for data entry,
type DetailType =
| DoctorView
| NurseView
| MedicalRecordsView
| PatientView
| ProviderView
and I'm thinking that I need to use Elmish.WPF Bindings.SubModel. But if I do so, how then is the Binding for the top window rewritten? How is this best done?
Thanks for any help with this.
TIA
OP cross posted in this GitHub issue and I answered their question in this comment.

Tag search in HTML using js in ant

I am using the below mentioned code to get the content of a specific tag, but when I am trying to execute it I am getting some extra data along with it, I don't understand why is it happening. Lets say if I search for title tag then I am getting " [echo] Title : <title>Unit Test Results</title>,Unit Test Results" this as result, but the problem is title only contains "<title>Unit Test Results</title>" why this extra ",Unit Test Results" thing is coming.
<project name="extractElement" default="test">
<!--Extract element from html file-->
<scriptdef name="findelement" language="javascript">
<attribute name="tag" />
<attribute name="file" />
<attribute name="property" />
<![CDATA[
var tag = attributes.get("tag");
var file = attributes.get("file");
var regex = "<" + tag + "[^>]*>(.*?)</" + tag + ">";
var patt = new RegExp(regex,"g");
project.setProperty(attributes.get("property"), patt.exec(file));
]]>
</scriptdef>
<!--Only available target...-->
<target name="test">
<loadfile srcFile="E:\backup\latest report\Report-20160523_2036.html" property="html.file"/>
<findelement tag="title" file="${html.file}" property="element"/>
<echo message="Title : ${element}"/>
</target>
The return value of RegExp.exec() is an array. From the Mozilla documentation on RegExp.prototype.exec():
The returned array has the matched text as the first item, and then
one item for each capturing parenthesis that matched containing the
text that was captured.
If you add the following code to your JavaScript...
var patt = new RegExp(regex,"g");
var execResult = patt.exec(file);
print("execResult: " + execResult);
print("execResult.length: " + execResult.length);
print("execResult[0]: " + execResult[0]);
print("execResult[1]: " + execResult[1]);
...you'll get the following output...
[findelement] execResult: <title>Unit Test Results</title>,Unit Test Results
[findelement] execResult.length: 2
[findelement] execResult[0]: <title>Unit Test Results</title>
[findelement] execResult[1]: Unit Test Results

Write Ant properties to a YAML file

I want to have my Ant project output a few properties as YAML file.
For example:
<property name="foo" value="aaa"/>
<property name="bar" value="bbb"/>
<property name="baz" value="ccc"/>
Is written to output.yml as
foo: aaa
bar: bbb
baz: ccc
Can anyone suggest a method that doesn't require external tools/libraries?
Ant has built in JavaScript, which you might try. See below for an illustration.
This uses <scriptdef> to create a task "props2yaml" that writes a set of properties to a file. I've not tried to generalise for characters needing escape sequences, etc.
<scriptdef name="props2yaml" language="javascript">
<attribute name="destfile"/>
<element name="propertyset" type="propertyset"/>
<![CDATA[
var destfile = attributes.get( "destfile" );
//var properties = project.getProperties( );
//var prop_names = properties.keySet( ).toArray( ).sort( );
var properties = elements.get( "propertyset" ).get( 0 ).getProperties( );
var prop_names = properties.stringPropertyNames( ).toArray( ).sort( );
var fw = new java.io.FileWriter( destfile );
for ( var i in prop_names ) {
fw.write( prop_names[i] + ': "' + properties.get( prop_names[i] ) + '"\n' );
}
fw.flush( );
fw.close( );
]]></scriptdef>
<property name="foo" value="aaa"/>
<property name="bar" value="bbb"/>
<property name="baz" value="ccc"/>
<props2yaml destfile="output.yml">
<propertyset>
<propertyref name="foo" />
<propertyref name="bar" />
<propertyref name="baz" />
</propertyset>
</props2yaml>
For me the output in this case is:
bar: "bbb"
baz: "ccc"
foo: "aaa"
You could preserve order by changing the scriptdef as you see fit.
The commented out lines show how to get a full list of all Ant properties in the project.

Can't authenticate using Quickbooks web connector / CFML

I am attempting to implement a Quickbooks Web connector (QBWC) in Railo 4.x
<cfcomponent output="false">
<cffunction name = "authenticate" access="remote" returntype="string">
<cfargument name = "username" type="string" required="true">
<cfargument name = "password" type = "string" required="true">
<cfset var loc = {}>
<cfset loc.retVal= []>
<cfset loc.retVal[1] = "MYSESSIONTOKEN">
<cfset loc.retVal[2] = "NONE">
<cfset loc.retVal[3] = "">
<cfset loc.retVal[4] = "">
<cfreturn loc.retVal >
</cffunction>
<cffunction name = "clientVersion" access="remote" returnType ="string">
<cfargument name = "productVersion" type="string" required="true">
<cfset var loc = {}>
<cfset loc.retVal = "">
<cfreturn loc.retVal>
</cffunction>
</cfcomponent>
This is my QWC file:
<?xml version="1.0"?>
<QBWCXML>
<AppName>QuickCellarSVC</AppName>
<AppID></AppID>
<AppURL>http://localhost:8080/QuickCellar.cfc</AppURL>
<AppDescription>Quick Cellar railo component</AppDescription>
<AppSupport>http://localhost:8080/support.cfm</AppSupport>
<UserName>Joe</UserName>
<OwnerID>{57F3B9B1-86F1-4fcc-B1EE-566DE1813D20}</OwnerID>
<FileID>{90A44FB5-33D9-4815-AC85-BC87A7E7D1EB}</FileID>
<QBType>QBFS</QBType>
<Scheduler>
<RunEveryNMinutes>2</RunEveryNMinutes>
</Scheduler>
</QBWCXML>
The QBWC trace shows the problem :
Object reference not set to an instance of an object.
More info:
StackTrace = at QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)
Source = QBWebConnector
I was able to drill down a little more and discover that there is a casting problem in Railo maybe?
<?xml version="1.0" encoding="UTF-8"?>
-<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">-<soap:Body>-
Can't cast Complex Object Type Struct to StringUse Built-In-Function "serialize(Struct):String" to create a String from Struct
Now I know some of you are thinking "just serialize" the struct. Well, there is no such function in Railo (that I know of).
Any ideas are greatly appreciated.
The first issue I see is your "authenticate" method has return type of string, but you are returning an array. If you are trying to return a string you could use return serializeJSON(loc.retVal) instead of just retVal, which would return it as a JSON formatted string.

xml.parse return null google app script

I am trying parse the xml but result return null.
Here is the xml:
<feed>
<title type="text">neymar</title>
<subtitle type="text">Bing Image Search</subtitle>
<id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$top=2</id>
<rights type="text"/>
<updated>2013-05-13T08:45:02Z</updated>
<link rel="next" href="https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$skip=2&$top=2"/>
<entry>
<id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$skip=0&$top=1</id>
<title type="text">ImageResult</title>
<updated>2013-05-13T08:45:02Z</updated>
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Guid">99cb00e9-c9bb-45ca-9776-1f51e30be398</d:ID>
<d:Title m:type="Edm.String">neymaer wallpaper neymar brazil wonder kid neymar wallpaper hd</d:Title>
<d:MediaUrl m:type="Edm.String">http://3.bp.blogspot.com/-uzJS8HW4j24/Tz3g6bNII_I/AAAAAAAAB1o/ExYxctnybUo/s1600/neymar-wallpaper-5.jpg</d:MediaUrl>
<d:SourceUrl m:type="Edm.String">http://insidefootballworld.blogspot.com/2012/02/neymar-wallpapers.html</d:SourceUrl>
<d:DisplayUrl m:type="Edm.String">insidefootballworld.blogspot.com/2012/02/neymar-wallpapers.html</d:DisplayUrl>
<d:Width m:type="Edm.Int32">1280</d:Width>
<d:Height m:type="Edm.Int32">800</d:Height>
<d:FileSize m:type="Edm.Int64">354173</d:FileSize>
<d:ContentType m:type="Edm.String">image/jpeg</d:ContentType>
<d:Thumbnail m:type="Bing.Thumbnail">
<d:MediaUrl m:type="Edm.String">http://ts3.mm.bing.net/th?id=H.5042206689331494&pid=15.1</d:MediaUrl>
<d:ContentType m:type="Edm.String">image/jpg</d:ContentType>
<d:Width m:type="Edm.Int32">300</d:Width>
<d:Height m:type="Edm.Int32">187</d:Height>
<d:FileSize m:type="Edm.Int64">12990</d:FileSize>
</d:Thumbnail>
</m:properties>
</content>
</entry>
<entry>
<id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$skip=1&$top=1</id>
<title type="text">ImageResult</title>
<updated>2013-05-13T08:45:02Z</updated>
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Guid">9a6b7476-643e-4844-a8da-a4b640a78339</d:ID>
<d:Title m:type="Edm.String">neymar jr 485x272 Neymar Show 2012 Hd</d:Title>
<d:MediaUrl m:type="Edm.String">http://www.sontransferler.com/wp-content/uploads/2012/07/neymar_jr.jpg</d:MediaUrl>
<d:SourceUrl m:type="Edm.String">http://www.sontransferler.com/neymar-show-2012-hd</d:SourceUrl>
<d:DisplayUrl m:type="Edm.String">www.sontransferler.com/neymar-show-2012-hd</d:DisplayUrl>
<d:Width m:type="Edm.Int32">1366</d:Width>
<d:Height m:type="Edm.Int32">768</d:Height>
<d:FileSize m:type="Edm.Int64">59707</d:FileSize>
<d:ContentType m:type="Edm.String">image/jpeg</d:ContentType>
<d:Thumbnail m:type="Bing.Thumbnail">
<d:MediaUrl m:type="Edm.String">http://ts1.mm.bing.net/th?id=H.4796985557255960&pid=15.1</d:MediaUrl>
<d:ContentType m:type="Edm.String">image/jpg</d:ContentType>
<d:Width m:type="Edm.Int32">300</d:Width>
<d:Height m:type="Edm.Int32">168</d:Height>
<d:FileSize m:type="Edm.Int64">4718</d:FileSize>
</d:Thumbnail>
</m:properties>
</content>
</entry>
</feed>
and here is the code:
var response = UrlFetchApp.fetch('https://api.datamarket.azure.com/Bing/Search/Image?Query=%27neymar%27&$top=2',options)
var resp = response.getContentText();
var ggg = Xml.parse(resp,false).getElement().getElement('entry').getElement('content').getElement('m:properties');
Logger.log(ggg);
How do I get element <d:MediaUrl m:type="Edm.String">?
update: but still not work
var response = UrlFetchApp.fetch('https://api.datamarket.azure.com/Bing/Search/Image?Query=%27neymar%27&$top=2',options)
var text = response.getContentText();
var eleCont = Xml.parse(text,true).getElement().getElement('entry').getElement('content');
var eleProp = eleCont.getElement('hxxp://schemas.microsoft.com/ado/2007/08/dataservices/metadata','properties')
var medUrl= eleProp.getElement('hxxp://schemas.microsoft.com/ado/2007/08/dataservices','MediaUrl').getText()
Logger.log(medUrl)
While the provider is using multiple namespaces (signified by m: and d: in front of element names), you can ignore them for retrieving the data you're interested in.
Once you've called getElement() to get the root of the XML doc, you can navigate through the rest using attribute names. (Stop after var feed = ... in the debugger, and explore feed, you'll find you have the entire XML document there
Try this:
var text = Xml.parse(resp,true);
var feed = text.getElement();
var urls = [];
for (var i in feed.entry) {
urls.push(feed.entry[0].content.properties.MediaUrl.Text);
}
Logger.log(urls);
This also works. Note that you have multiple entries in your response, and this example is going after the second of them:
var ggg = Xml.parse(resp,true)
.getElement()
.getElements('entry')[1]
.getElement('content')
.getElement('properties')
.getElement('MediaUrl')
.getText();
References
Namespaces in XML 1.0
XmlElement methods referencing namespace, such as getElement(namespaceName, localName)
Other relevant StackOverflow questions. xml element name with colon, lots about XML namespaces

Resources