Pages PrintOut Word VBS [duplicate] - printing

This question already has answers here:
Print certain pages only
(2 answers)
Closed 2 years ago.
I can't seem to get Words PrintOut to accept/honor the parameter for PAGES when run in VBScript. Weirdly, it honors COPIES just fine. Any ideas?
Code:
Dim ObjWord
Set ObjWord = CreateObject("Word.Application")
ObjWord.Visible = True
'Open Document
Dim ObjDoc
'https://learn.microsoft.com/en-us/office/vba/api/word.documents.open
'.Open (FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument, OpenAndRepair, DocumentDirection, NoEncodingDialog)
Set ObjDoc = ObjWord.Documents.Open("C:\tmp\test.docx", ,TRUE, , , , , , , , ,TRUE)
'PageRange
'https://learn.microsoft.com/en-us/office/vba/api/word.application.printout
'.PrintOut (Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight)
Dim ObjPrint
ObjPrint = ObjDoc.PrintOut(FALSE, , , , , , , ,"1", , ,TRUE) ' No Error, but Pages not honored
'ObjPrint = ObjDoc.PrintOut(FALSE, , , , , , ,"2", , , ,TRUE) ' Corretly Printes Two Copies
objDoc.Saved = TRUE
objWord.Quit
Set ObjDoc = Nothing
Set objWord = Nothing

So I had to pass an additional param for it to honour the Pages value which was Range.
https://learn.microsoft.com/en-us/office/vba/api/word.document.printout
https://documentation.help/MS-Office-Word-VB/womthPrintOut1.htm
It required a CONSTANT declaration. Eg:
https://learn.microsoft.com/en-us/office/vba/api/word.wdprintoutrange
Specifies a range to print.
WDPRINTOUTRANGE ENUMERATION (WORD)
Name Value Description
wdPrintAllDocument 0 The entire document.
wdPrintCurrentPage 2 The current page.
wdPrintFromTo 3 A specified range.
wdPrintRangeOfPages 4 A specified range of pages.
wdPrintSelection 1 The current selection.
In my case, I believe it will always be 4.
Therefore this worked as expected. (Print Only Page 2)
ObjPrint = ObjDoc.PrintOut(FALSE, ,"4", , , , , ,"2", , ,TRUE)
Further Reading on Printing Word via VBScript. Disclaimer: This is my personal blog --> https://www.freesoftwareservers.com/display/FREES/Print+Microsoft+Word+via+Batch+-+WINWORD.EXE+Switches+-+VBScript+Print+Specific+Pages

Related

How to generate HTML to PDF, 2 pages per sheet?

I am using ABCPDF version 10 in an .aspx file, language is VB.
This script receives a URL as an argument, retrieves the URL and converts the contents it receives to PDF. We use this as an internal service for generating reports, invoices, etc.
The requirement has come up to put 2 pages on a sheet, so 2 A5 pages on one landscape A4 page, like a booklet but without the pagination requirements, just 2:1 sequentially.
Here is our current script for standard A4 (excerpt):
Dim footer as String = request("footer")
Dim url as String = request("url")
Dim theDoc As New WebSupergoo.ABCpdf10.Doc()
theDoc.MediaBox.String = "A4"
theDoc.Rect.String = theDoc.MediaBox.String
'theDoc.Rect.Inset(30, 30)
' left, bottom, width, height
theDoc.Rect.SetRect(10,40,575,780)
theDoc.HtmlOptions.Engine = 1
theDoc.HTMLOptions.Timeout = 455000
theDoc.HTMLOptions.AddLinks = False
theDoc.Page = theDoc.AddPage()
Dim theID As Integer
theID = theDoc.AddImageUrl(url, True, 0, True)
While True
'theDoc.FrameRect() 'enable this to see the rectangle on the PDF, for debugging
If Not theDoc.Chainable(theID) Then
Exit While
End If
theDoc.Page = theDoc.AddPage()
theID = theDoc.AddImageToChain(theID)
End While
Dim i as Integer
For i = 1 To theDoc.PageCount
theDoc.PageNumber = i
theDoc.Flatten()
Next
Can anyone tell me what I need to do to get 2 pages on one page of PDF output?
NB - The "pages" are described by using css page-break-after:always in the content, which ABCPDF handles as expected.

Custom wireshark disector shows value but fieldname is not visible using lua

I am testing some network packets of my Organisation's product. We already have custom plugins. I am trying to add some some more fields into those existing plugins (like conversion of 2 byte code to a string and assign it to a field)
Thankyou in advance for reading my query.
--edit
Wireshark version : 2.4.5 (organization's plugins dont work on latest wireshark application)
--edit
Problem statement:
I am able to add field and show value, but fieldname is not displayed as defined.
I cannot share the entire .lua file but i will try to explain What i did:
Below is the image where I have a field aprint.type. this is a two byte field. In .lua file, for display purpose it is appended with corresponding description using a custom function int_to_enum.
I want to add one more proto field aprint.typetext which will show the text.
What I did:
Added a protofield f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text") (Tried f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text",FT_STRING) also)
Below the code where subtree aprint.type is shown, added my required field as subtree:add(f_apr_msg_type_txt, msg_type_string) (Below is image of code extract)
I am able to see the text but field Name is shown as Wireshark Lua text (_ws.lua.text)
Normally displaying strings based on numeric values is accomplished by a value string lookup, so you'd have something like so:
local aprint_type_vals = {
[1] = "Foo",
[2] = "Bar",
[9] = "State alarm"
}
f_apr_msg_type = ProtoField.uint16("aprint.type", "Type", base.DEC, aprint_type_vals)
f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text", base.ASCII)
... then
local msg_type = tvb(offset, 2):le_uint()
subtree:add_le(f_apr_msg_type, tvb(offset, 2))
subtree:add(f_apr_msg_type_txt, tvb(offset, 2), (aprint_type_vals[msg_type] or "Unknown"))
--[[
Alternatively:
subtree:add(f_apr_msg_type_txt, tvb(offset, 2)):set_text("aprint_type_text: " .. (aprint_type_vals[msg_type] or "Unknown"))
--]]
I'm also not sure why you need the extra field with only the text when the text is already displayed with the existing field, but that's basically how you'd do it.

How to select the type of file when using SaveImage()

I have realize that the SaveImage() command uses the last the last type of format that has been selected during normal DM operation. I assume that this option is selected somewhere in the GobalInfo tags. Please, could someone tell me which tag I have to modify to select dm4 format when I use SaveImage()?
'SaveImage()' is just a convenience wrapper. It is generally not the
Image which is saved to file, but an ImageDocument which can contain one ore more images. The latest DigitalMicograph help
documentation is more detailed about loading/saving than previous
ones, so I'm just copy-pasting the according passages below:
For example to store the front-most displayed image(document) as DM images, you may use:
string name = "C:\\TempImg"
string handler = "Gatan 3 Format"
ImageDocument doc = GetFrontImageDocument()
doc.ImageDocumentSaveToFile( handler, name )
And you can always get the ImageDocument from any image, using:
string handler = "Gatan 3 Format"
image img := RealImage("Test - not yet shown", 4, 100, 100 )
string name = "C:\\" + img.GetName()
ImageDocument doc = img.ImageGetOrCreateImageDocument()
doc.ImageDocumentSaveToFile( handler, name )

Nhibernate setFirstResult

I'm having an issue with Nhibernate version 3.3.3 when trying to use setFirstResult.
IQuery q = session.CreateQuery("Select a from SelectionAssignment a ")
.SetFirstResult(1)
.SetMaxResults(10);
var assignments = q.List<SelectionAssignment>();
The above spits out SQL like this:
SELECT TOP (10) asId30_
, asHostId30_
, asDescript3_30_
, asIsChase30_
, asPosition30_
, asGoalTime30_
, asRoute30_
, asActiveta8_30_
, asPassAssi9_30_
, asSummary10_30_
, asOverrid11_30_
, asDeliver12_30_
, asDirectLoad30_
, asAllowDe14_30_
, asVehicle15_30_
, asCustomerId30_
, asTotalWe17_30_
, asTotalItems30_
, asSingleSKU30_
, asSingleB20_30_
, asCreated21_30_
, asStartDate30_
, asEndDate30_
, asPriority30_
, asIsDeleted30_
, asDeleted26_30_
, asDeleted27_30_ FROM
(
select selectiona0_.Id as Id30_
, selectiona0_.HostId as HostId30_
, selectiona0_.Description as Descript3_30_
, selectiona0_.IsChase as IsChase30_
, selectiona0_.Position as Position30_
, selectiona0_.GoalTime as GoalTime30_
, selectiona0_.Route as Route30_
, selectiona0_.ActivetargetContainer as Activeta8_30_
, selectiona0_.PassAssignment as PassAssi9_30_
, selectiona0_.SummaryPromptType as Summary10_30_
, selectiona0_.OverridePrompt as Overrid11_30_
, selectiona0_.DeliveryLocationId as Deliver12_30_
, selectiona0_.DirectLoad as DirectLoad30_
, selectiona0_.AllowDeliverLocationOverride as AllowDe14_30_
, selectiona0_.VehicleLicense as Vehicle15_30_
, selectiona0_.CustomerId as CustomerId30_
, selectiona0_.TotalWeight as TotalWe17_30_
, selectiona0_.TotalItems as TotalItems30_
, selectiona0_.SingleSKU as SingleSKU30_
, selectiona0_.SingleBatch as SingleB20_30_
, selectiona0_.CreatedDate as Created21_30_
, selectiona0_.StartDate as StartDate30_
, selectiona0_.EndDate as EndDate30_
, selectiona0_.Priority as Priority30_
, selectiona0_.IsDeleted as IsDeleted30_
, selectiona0_.DeletedDate as Deleted26_30_
, selectiona0_.DeletedUser as Deleted27_30_
, ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row
from SelectionAssignment selectiona0_ where ( selectiona0_.IsDeleted=0)
) as query
WHERE query.__hibernate_sort_row > 0
ORDER BY query.__hibernate_sort_row
Whereas if I set the parameter to be .SetFirstResult(0) it works fine.
Can anyone tell me why? Or how I could go about fixing this?
Edit: Apologies, I'm getting an error message of Invalid column name 'asId30' 'asHostId30' etc. The column name is Id, HostId etc.
I discovered the problem. It seemed to be the column name "SelectionAssignment" was causing an issue because NHibernate uses it's own alias on the produced SQL which takes 10 characters and adds a digit. However the 10th and 11th character in my column name are "AS". This seemed to cause a conflict with the query when it tried to put its own AS in there.
Once I changed the column name to be something different "PickingAssignment" the issue was fixed.
I hope I've explained clearly enough and that it can help others with the same issue. Thanks to jbl for trying to help.

Int32.ParseInt throws FormatException after web post

Update
I've found the problem, the exception came from a 2nd field on the same form which indeed should have prompted it (because it was empty)... I was looking at an error which I thought came from trying to parse one string, when in fact it was from trying to parse another string... Sorry for wasting your time.
Original Question
I'm completely dumbfounded by this problem. I am basically running int.Parse("32") and it throws a FormatException. Here's the code in question:
private double BindGeo(string value)
{
Regex r = new Regex(#"\D*(?<deg>\d+)\D*(?<min>\d+)\D*(?<sec>\d+(\.\d*))");
Regex d = new Regex(#"(?<dir>[NSEW])");
var numbers = r.Match(value);
string degStr = numbers.Groups["deg"].ToString();
string minStr = numbers.Groups["min"].ToString();
string secStr = numbers.Groups["sec"].ToString();
Debug.Assert(degStr == "32");
var deg = int.Parse(degStr);
var min = int.Parse(minStr);
var sec = double.Parse(secStr);
var direction = d.Match(value).Groups["dir"].ToString();
var result = deg + (min / 60.0) + (sec / 3600.0);
if (direction == "S" || direction == "W") result = -result;
return result;
}
My input string is "32 19 17.25 N"
The above code runs on a .NET 4 web hosting service (aspspider) on an ASP.NET MVC 3 web application (with Razor as its view engine).
Note the assersion of degStr == "32" is valid! Also when I take the above code and run it in a console application it works just fine. I've scoured the web for an answer, nothing...
Any ideas?
UPDATE (stack trace)
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9586043
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
System.Int32.Parse(String s) +23
ParkIt.GeoModelBinder.BindGeo(String value) in C:\MyProjects\ParkIt\ParkIt\GeoBinder.cs:42
Line 42 is var deg = int.Parse(degStr); and note that the exception is in System.Int32.Parse (not in System.Double as was suggested).
You are wrongly thinking that it is the following line that is throwing the exception:
int.Parse("32")
This line is unlikely to ever throw an exception.
In fact it is the following line:
var sec = double.Parse(secStr);
In this case secStr = "17.25";.
The reason for that is that your hosting provider uses a different culture in which the . is not a decimal separator.
You have the possibility to specify the culture in your web.config file:
<globalization culture="en-US" uiCulture="en-US" />
If you don't do that, then auto is used. This means that the culture could be set based on the client browser preferences (which are sent with each request using the Accept-Language HTTP header).
Another possibility is to specify the culture when parsing:
var sec = double.Parse(secStr, CultureInfo.InvariantCulture);
This way you know for sure that . is the decimal separator for the invariant culture.
Testing this (via PowerShell):
PS [64] E:\dev #43> '32 19 17.25 N' -match "\D*(?\d+)\D*(?\d+)\D*(?\d+(\.\d*))"
True
PS [64] E:\dev #44> $Matches
Name Value
---- -----
sec 17.25
deg 32
min 19
1 .25
0 32 19 17.25
So the regex is working with all three named captures getting a value, all of which will parse OK (ie. it isn't something like \d matching something like U+0660: ARABIC-INDIC DIGIT ZERO that Int32.Parse doesn't handle).
But you do not check that the regex actually makes a match.
Therefore I suspect that the value passed to the function is not the input you expect. Put a breakpoint (or logging) at the start of the function and get the actual value of value.
I think what is happening is:
Value isn't what you think it is.
The regex fails to match.
The captures are empty
Int32.Parse("") is throwing (just confirmed: it throws a FormatException "Input string was not in a correct format.")
Adendum: Just noted you comment on the assertion.
If things seem contradictory go back to basics: at least one of your assumptions is wrong eg. there could be an off by one in the exception's line number (an edit to the file before going to that line number: very easy to do).
Stepping through with a debugger in this case is by far the easiest approach. On every expression check everything.
If you cannot use a debugger then try and remove that restriction, if not how about IntelliTrace? Othewrwise use some kind of logging (if you app doesn't have it, add it as you'll need it in the future for things like this).
try remove non unicode ( if any - non-visible) chars from string :
string s = "søme string";
s = Regex.Replace(s, #"[^\u0000-\u007F]", string.Empty);
edit
also - try to see its hex values to see where it is doing exceptio n :
BitConverter.ToString(buffer);
this will show you the hex values so you can verify...
also paste its value so we can see it.
It turns out that this is a non-question. The problem was that the exception came from a 2nd field on the same form which indeed should have prompted it (because it was empty)... I was looking at an error which I thought came from trying to parse one string, when in fact it was from trying to parse another string...
Sorry for wasting your time.

Resources