Silently use Microsoft XPS Document Writer printer to create XPS - windows

For some days now I've been battling with printing XPS to file without the dialog.
I've read posts on the matter in CodeGuru and by Feng Yuan (MSDN), along with many discussion topics here and I am still lost.
Specifically my scenario is that I have a 3rd party API that I must use, and it prints to the default printer (say Microsoft XPS Document Writer). I want to be able to "apply" a filename prior to the printing procedure, and of course not to have dialog.
I've tried working with WinDDK - XPSDRV and LOCALMON samples but wasn't able to figure out exactly how to manipulate the code to achieve my goals. (or even fully understand if I need a new printer driver or a new port type)

I ran into the same need. Following is some of the logic that provides the desired functionality for me:
//
// PrintDocument_inst
//
this.PrintDocument_inst.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.k_line_PrintPage);
private void Print( string align_file_name )
{
if ( plot_metafile == null )
{
MessageBox.Show( "you need to load offset data before printing a plot" );
return;
}
try
{
PrintDocument_inst.DefaultPageSettings = PageSettings_inst;
PrintDialog_inst = new PrintDialog( );
PrintDialog_inst.Document = PrintDocument_inst;
PrintDialog_inst.UseEXDialog = true; // this must be set true or dialog won't show on 64 bit Vista
PrintDialog_inst.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
PrintDialog_inst.PrinterSettings.PrintToFile = true;
PrintDialog_inst.PrinterSettings.PrintFileName = align_file_name;
i_page_to_print_next = 1;
n_pages_still_to_print = 1;
PrintDocument_inst.Print( );
}
catch ( Exception e )
{
MessageBox.Show( e.ToString( ) );
}
finally
{
}
} // end of function Print( string align_file_name )
//PrintPage event handler
private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)
{
int leftMargin = ppea.MarginBounds.Left;
int topMargin = ppea.MarginBounds.Top ;
try
{
float _scale_f;
if ( PrintDialog_inst != null )
{
string str_printer_name = PrintDialog_inst.PrinterSettings.PrinterName.ToString ( );
if ( str_printer_name.CompareTo ( "Adobe PDF" ) == 0 )
{
_scale_f = 0.61F; // 0.85F;
}
else
{
_scale_f = 0.59F; // 0.82F;
}
}
else // case of print preview
{
_scale_f = 0.59F; // 0.82F;
}
if ( _scale_f != 1.0F ) ppea.Graphics.ScaleTransform ( _scale_f, _scale_f );
ppea.Graphics.DrawImage ( plot_metafile, leftMargin, topMargin );
ppea.HasMorePages = ( --n_pages_still_to_print > 0 ? true : false );
}
finally
{
}
} // end of private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)

You will delete filters in pipeline xml and also related dll's in inf file. But yet, as I did, i guess you will face problem of printing canvas (graphics). I wasn't able to convert / transform this canvas to glyphs to get the contents of it.
If you had further issues, let me know
Kind Regards

Related

Photoshop CC2019 auto-update all linked smart objects including nested ones

I have Photoshop CC2019 PSD document containing several smart objects that contains other smart objects that contains other smart objects. Some of these have linked layers. Normally, such images are not updated automatically (which is extremely annoying, Adobe!) but you have to manually update each of them once the linked image content has changed.
There is a .jsx script file named "Update All Modified Content.jsx" which auto-updates linked layers (PNG image in my case) but only if the smart object is in the top most document - that is no nested smart objects with linked layers are updated automatically.
My question is: does anyone know how to update the content of the above mentioned .jsx file so that it would auto-update all linked images across all the smart objects in PSD document including nested ones?
For those who care or would be willing to help updating the code here it is:
// Update all modified content
var idplacedLayerUpdateAllModified = stringIDToTypeID( "placedLayerUpdateAllModified" );
executeAction( idplacedLayerUpdateAllModified, undefined, DialogModes.NO );
So, after spending half a day with it I finally solved it myself. Here is the code:
#target photoshop
// SET INITIAL ACTIVE DOCUMENT
var mainDocument = app.activeDocument;
// SAVE THE DOCUMENT NAME FOR FUTURE USE
var mainDocName = mainDocument.name;
// RUN THE MAIN UPDATE FUNCTION
mainDocument.suspendHistory("processAllSmartObjects", "autoupdateAllSmartObjects(mainDocument, 0)");
// FINALLY SAVE THE MAIN DOCUMENT
mainDocument.save();
function autoupdateAllSmartObjects(theParent, prevVal) {
// FUNCTION TO TEST IF SMARTOBJECT IS LINKED
function isLinkedSO(obj) {
var localFilePath = "";
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), obj.id);
var desc = executeActionGet(ref);
var smObj = desc.getObjectValue(stringIDToTypeID('smartObject'));
var isLinked = false;
// TEST IF IT HAS LINKED FILE
try {
var localFilePath = smObj.getPath(stringIDToTypeID('link'));
isLinked = true;
} catch(e) {
//
}
return isLinked;
}
// FUNCTION TO UPDATE LINKED SMART OBJECT
function doTheUpdate(LYR, stackNr) {
// SET ACTIVE LAYER TO ACTUALY ITERATED ONE
app.activeDocument.activeLayer = LYR;
// RUN IN "SILENT" MODE
app.displayDialogs = DialogModes.NO;
var layer = app.activeDocument.activeLayer;
// IF ACTIVE LAYER IS SMARTOBJECT
if (layer.kind == "LayerKind.SMARTOBJECT") {
//alert(layer);
// OPEN THE SMARTOBJECT
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
// DO THE ACTUAL FILE UPDATE
var idplacedLayerUpdateAllModified = stringIDToTypeID( "placedLayerUpdateAllModified" );
executeAction( idplacedLayerUpdateAllModified, undefined, DialogModes.NO);
// IF IT IS NOT THE "CORE/MAIN" DOCUMENT
if(stackNr > 0) {
// SAVE CHANGES (UPDATE) AND CLOSE IT
app.activeDocument.close(SaveOptions.SAVECHANGES);
}
// CONTINUE INSIDE THIS ACTIVE SMARTOBJECT
autoupdateAllSmartObjects(app.activeDocument, stackNr);
}
return;
}
// FUNCTION TO PARSE GROUPS
function parseGroup(LYR) {
var groupLayers = LYR.layers;
// IF GROUP IS NOT EMPTY
if(groupLayers.length > 0) {
// PARSE ALL LAYERS IN THE GROUP
for (var i = groupLayers.length - 1; i >= 0; i--) {
var lyr = groupLayers[i];
// IF NOT LOCKED = NOT EDITABL:E
if(!lyr.allLocked) {
// YET ANOTHER GROUP?
if (lyr.typename == "LayerSet") {
// IF IT IS NOT EMPTY
if (lyr.layers.length > 0) {
// RE-RUN THE SCRIPT ANEW WITH THE SELECTED GROUP AS LAYERS SOURCE
autoupdateAllSmartObjects(lyr, 0);
}
// LAYERS
} else if (lyr.typename == "ArtLayer") {
// IF THE LAYER IS SMARTOBJECT
if (lyr.kind == LayerKind.SMARTOBJECT) {
// IF THE LAYER IS SET TO "visible" (THAT IS: NOT DISABLED)
if(lyr.visible){
// TEST IF THE SMARTOBJECT IS ACTUALLY LINKED
if(!isLinkedSO(lyr)) {
// RUN THE UPDATE SUB-FUNCTION
doTheUpdate(lyr, i);
}
}
}
}
}
}
}
}
// PARSE ALL THE LAYERS
for (var i = theParent.layers.length - 1 - prevVal; i >= 0; i--) {
var theLayer = theParent.layers[i];
// ONLY ArtLayers
if (theLayer.typename == "ArtLayer") {
// IF THE LAYER IS SMARTOBJECT
if (theLayer.kind == LayerKind.SMARTOBJECT) {
// IF THE LAYER IS SET TO "visible" (THAT IS: NOT DISABLED)
if(theLayer.visible){
// TEST IF THE SMARTOBJECT IS ACTUALLY LINKED
if(!isLinkedSO(theLayer)){
// RUN THE UPDATE SUB-FUNCTION
doTheUpdate(theLayer, i);
// IF WE ARE AT THE LAST LAYER IN THE STACK AND IT IS NOT OUR MAIN DOCUMENT
if(i == 0 && app.activeDocument.name !== mainDocName) {
// SAVE CHANGES (UPDATE) AND CLOSE IT
app.activeDocument.close(SaveOptions.SAVECHANGES);
}
}
}
}
// ONLY Groups
} else if (theLayer.typename == "LayerSet") {
// RUN SUB-FUNCTION FOR GROUP PARSING
parseGroup(theLayer);
// ANYTHING ELSE
} else {
autoupdateAllSmartObjects(theLayer, m);
}
}
return;
};
OP's script works!! It was going in loops for me too but after some trial and error, I realised that my smart objects (SO) that are linked across artboards ( - e.g. if you change one SO, it changes on various artboards) - were the issue. I hid all such SO and it works.
so basically, it only works for Smart Objects + copies made via 'New smart object via copy' NOT 'duplicate layer' / copypaste smart objects. If your work contains a 'duplicate layer' SO - it will break the script. You need to hide these objects ( or not work like that all together) before running the script

Xamarin Android Google Places Api AutoComplete broken

I'm trying to get the basic autocomplete functionality from Google's Places Api working with Xamarin Android.
I'm using version 25.0.0.0 of Xamarin's Google Play Services - Location lib.
I've managed to get to the point of returning results of a query while following this example code
This is the Fragment I'm using to test the code
public class PlaceAutocomplete: BaseFragment, IGoogleApiClientOnConnectionFailedListener {
IGoogleApiClient client;
public override void OnCreate( Bundle savedInstanceState ) {
base.OnCreate( savedInstanceState );
client = new GoogleApiClientBuilder( Activity )
.EnableAutoManage( Activity as BaseFragmentActivity, 0, this )
.AddOnConnectionFailedListener( OnConnectionFailed )
.AddApi( Places.GEO_DATA_API )
.Build();
}
public override View OnCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
Places.GeoDataApi.GetAutocompletePredictions( client, "cul",
new LatLngBounds( new LatLng( 33.515071, -118.796427 ), new LatLng( 34.435985, -117.127371 ) ), null )
.SetResultCallback<AutocompletePredictionBuffer>( AutocompleteResult );
return base.OnCreateView( inflater, container, savedInstanceState );
}
public void AutocompleteResult( AutocompletePredictionBuffer buffer ) {
if( !buffer.Status.IsSuccess ) {
Toast.MakeText( Activity, buffer.Status.StatusMessage, ToastLength.Long ).Show();
return;
}
var a = new List<IAutocompletePrediction>();
for( var i = 0; i < buffer.Count; i++ ) {
var item = buffer.Get( i );
if( item is IAutocompletePrediction ) {
a.Add( (IAutocompletePrediction) item );
} else {
//all the results go in here
}
}
Toast.MakeText( Activity, a.Count.ToString(), ToastLength.Long ).Show();
}
public void OnConnectionFailed( ConnectionResult result ) {
}
}
There are 5 returned results from GetAutocompletePredictions method but all of them of type named com.google.android.gms.location.places.internal.zzb, cannot be cast to IAutocompletePrediction and I did not find any way to use them.
Did I do something wrong or this part of Xamarin's Google Play library is not fully implemented?
Edit - New Information
This is not a bug. The IAutocompletePrediction is not currently implemented by Xamarin so you must cast it like this
item.JavaCast<IAutocompletePrediction>()
in order to use it.
Older informaton
I've talked to Xamarin Support and they've confirmed that this is a bug.
More info on the bug fix can be found here https://bugzilla.xamarin.com/show_bug.cgi?id=31878
As of
Xamarin 4.0.0.1717 /
Xamarin.Android 6.0.0.35 /
Xamarin Google Play Services Location component v 27.0.0.0
, it seems there's been a bit of work in this space.
The IEnumerable interface now provides a way to get a typed response, and the following snippet (replacing part of AutocompleteResult) works:
var a = new List<IAutocompletePrediction>();
String t = "";
foreach (IAutocompletePrediction x in buffer)
{
a.Add(x);
t += "\n" + x.GetFullTextFormatted(new StyleSpan(TypefaceStyle.Normal)).ToString();
}
Toast.MakeText(Activity, t /* a.Count.ToString() */, ToastLength.Long).Show();

In UnityScript, why does GUI not get called within hit on collider?

I'm trying to print out text when a user touches a sprite, however, even though I get no errors when building and running the code, the code refuses to printout the text and I cannot understand what I am doing wrong. Please help me understand why it does not print.
It prints the debug text when I touch the sprite, but not the GUI text with total.
This is the code:
#pragma strict
function Start () {
OnGUI();
}
function OnGUI(){
//var total = 0;
//GUI.Label( myRect, total.ToString() ); // Displays "10".
//GUI.Label( myRect, "" + bullets ); // Displays "10".
// GUI.Label(Rect(0,0,Screen.width,Screen.height),"Total:"+total);
}
//function Update () {
//}
var platform : RuntimePlatform = Application.platform;
function Update(){
if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer){
if(Input.touchCount > 0) {
if(Input.GetTouch(0).phase == TouchPhase.Began){
checkTouch(Input.GetTouch(0).position);
}
}
}else if(platform == RuntimePlatform.WindowsEditor){
if(Input.GetMouseButtonDown(0)) {
checkTouch(Input.mousePosition);
}
}
}
function checkTouch(pos){
var total = 0;
var wp : Vector3 = Camera.main.ScreenToWorldPoint(pos);
var touchPos : Vector2 = new Vector2(wp.x, wp.y);
var hit = Physics2D.OverlapPoint(touchPos);
if(hit){
GUI.Label(Rect(0,0,Screen.width,Screen.height),"Total:");
Debug.Log(hit.transform.gameObject.name);
hit.transform.gameObject.SendMessage('Clicked',0,SendMessageOptions.DontRequireReceiver);
//total = total +1;
}
}
You cannot put a gui item outside the OnGUI Method. You need to set a boolean to turn on the label.
Something along these lines.
OnGUI(){
if(labelbool)
GUI.Label ....
}
check(){
labelbool = true;
}

Android: How to end animation of a listitem using valueanimator?

I am using the ValueAnimator to make one row in my list pulse from dark blue to light blue finitely. However, I need to check for a boolean when the rows load and when it gets set to false I need the view to go back to its original non-pulsing state. What is the best way of doing this?
My code is as follows -
if(isHighlighted(post)) {
String titleText = title.getText().toString();
title.setText(titleText);
title.setTextColor(Color.WHITE);
timeStamp.setTextColor(Color.WHITE);
highLighterStartColor = resources.getColor( R.color.active_blue );
highLighterEndColor = resources.getColor( R.color.teal );
ValueAnimator va = ObjectAnimator.ofInt(view, "backgroundColor", highLighterStartColor, highLighterEndColor);
if(va != null) {
va.setDuration(750);
va.setEvaluator(new ArgbEvaluator());
va.setRepeatCount(ValueAnimator.INFINITE);
va.setRepeatMode(ValueAnimator.REVERSE);
va.start();
}
} else {
title.setTextAppearance(activity.getApplicationContext(), R.style.medium_text);
timeStamp.setTextAppearance(activity.getApplicationContext(), R.style.timestamp_text);
}

Windows service shut down

I use VS6 and ATL with CServiceModule to implement a custom windows service. In case of a fatal error service should shut itself down. Since CServiceModule is available via _Module variable in all files I thought of something like this to cause CServiceModule::Run to stop pumping messages and shut itself down
PostThreadMessage(_Module.dwThreadID, WM_QUIT, 0, 0);
Is this correct or you have better idea ?
For self shutdown you send command to Service Manager. Try this sample :
BOOL StopServiceCmd ( const char * szServiceName )
{
SC_HANDLE schService;
SC_HANDLE schSCManager;
SERVICE_STATUS ssStatus; // current status of the service
BOOL bRet;
int iCont=0;
schSCManager = OpenSCManager(
NULL, // machine (NULL == local)
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
);
if ( schSCManager )
{
schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);
if (schService)
{
// try to stop the service
if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) )
{
Sleep( 1000 );
while( QueryServiceStatus( schService, &ssStatus ) )
{
iCont++;
if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING )
{
Sleep( 1000 );
if ( iCont > 4 ) break;
}
else
break;
}
if ( ssStatus.dwCurrentState == SERVICE_STOPPED )
bRet = TRUE;
else
bRet = FALSE;
}
CloseServiceHandle(schService);
}
else
bRet = FALSE;
CloseServiceHandle(schSCManager);
}
else
bRet = FALSE;
return bRet;
}
I believe that if you do this, then the service manager will think that your service has crashed and if the user ever sets it up to auto-restart, it will.
In .NET, you use the ServiceController to signal your service to shut down. I expect it is similar in Win32 since most of this stuff in .NET is just wrappers. Sorry, I don't have C++ code handy to shut down the service, but here is the .NET code. This will hopefully help you Google the info you need, or find the docs in MSDN.
This is from some test suite code, thus the style of error checking ;) You will need to put this code in a thread so that the shutdown message gets handled.
private void stopPLService( bool close )
{
if ( m_serviceController == null )
{
m_serviceController = new ServiceController( "PLService" );
}
WriteLine( "StopPLService" );
if ( m_serviceController != null )
{
try
{
m_serviceController.Stop();
}
catch
{
// Probably just means that it wasn't running or installed, ignore
}
// Wait up to 30 seconds for the service to stop
try
{
m_serviceController.WaitForStatus( ServiceControllerStatus.Stopped, new TimeSpan( 0, 0, 30 ) );
}
catch ( System.ServiceProcess.TimeoutException )
{
Assert.Fail( "Timeout waiting for PLService to stop" );
}
catch
{
// Not installed, we only care in the start
}
if ( close )
{
m_serviceController.Close();
m_serviceController = null;
}
}
}
You probably want to use the ControlService or ControlServiceEx methods to shutdown your service. You should be able to get the required handle from the CServiceModule.

Resources