GhostScript Unique Filenaming - ghostscript

I'm creating a virtual printer by using Redirection Port Monitor (Redmon) to pass a PostScript file to GhostScript and have it saved as a PDF. Is there a parameter that I can use in the -sOutputFile= for it to save the pdf with a unique filename? System Date and Time or even passing the original filename is fine.

No there is no such parameter, you are expected to generate the output filename yourself.
If you set RedMon to 'prompt for filename' then that's the filename that GS will use. You might be able to set the environment variable REDMON_FILENAME and have it use that, not entirely sure.
You could alter RedMon to set the OutputFile= to a unique name, such as date and time, Ghostscript has no options to do so (and it can't use the input filename, because it doesn't know it).
Of course, you could also alter Ghostscript if you're going to change source code and rebuild applications.

Related

For the use of the LocalizedResourceName property

I wish to customize my own folder style, I tried to make the folder get remarks by modifying the LocalizedResourceName property in desktop.ini.
I try to set LocalizedResourceName to a Chinese string. But it is displayed as garbled characters when it is actually displayed.
I noticed the following code in the desktop.ini of the system folder:
LocalizedResourceName=#%SystemRoot%\system32\shell32.dll,-21798
So I try to write a .dll file by myself, encapsulate the icon and string, and use it.
I already know how to make a resource-only dll file, but I don't know how to get a certain resource in the file. (ie, get the number -21798 in the above example code)
How should I do ?
By convention, a positive resource number is an index (0 is the first resource etc.) and negative numbers are resource ids. In this specific case, it is the string resource with the id of abs(-21798) that Windows would pass to LoadString.
If you want to create your own .dll, add a string with an id of 2 for example (any number between 2 and 0xffff) and in your .ini you would use #c:\path\mydll.dll,-2.
Before you go to all this trouble, just try saving the .ini as UTF-16 LE (Unicode in Notepad) and use Chinese strings directly without the #.

Windows 10: Simple way to print a PDF-file without the save-dialog

I'm trying to print the PDf-file(s) in a certain folder (or alternatively just print the files one-by-one) using for example Micorosft Print to PDF in order to create flattened versions. However when using Microsoft Print to PDF i need to specify the ouput-file's name and path. Is there any way to circumvent this or an alternative virtual printer specialized on such a job?
What I've already tried:
Windows 10 Print to PDF from command-line and Printing PDFs from Windows Command Line
These approches try to use the command prompt (personally favoured by me aswell, as it allows to create a batch-file and automate the process completely), but unfortunately the programs/printers listed in those posts are either not free or show a save-file-dialog aswell. Furthermore they are quite slow (even though this is not my main focus). So far, PDFtoPrinter has been the best solution, though it shows the save-file-dialog aswell...
Another idea I got from this post is to create a (VBA-/PowerShell-)script, but I'm not very experienced at that.
Any way to print just one PDF via the console and then making a loop or maybe even hard-coding the names would suffice aswell. I can easily rename the files for example to 1.pdf, 2.pdf, 3.pdf, ...
At this point I've tried so much but there has to be a way to get this running. Any help would be greatly appreciated!
Microsoft Print to PDF on Windows is not "Free", simply "Leased", however that said you can change the owners designed behavior to a different "port" than "prompt" or use the drivers to print to your desired named file.
To use ONE fixed output filename like %TEMP%OUT.PDF you are best served by cloning/duplicate the "Microsoft Print to PDF" to a printer name of your choice so I call mine "My Print to PDF" as its shorter to type and the Auto printed file goes to MyData folder. For a visual guide see https://stackoverflow.com/a/69169728/10802527 and up vote there if that helps.
The alternative is to use a structure like
CliPdfApp /PrintTo file.pdf "Microsoft Print to PDF" "Microsoft Print to PDF" "C:\MyFavourite Places\FileName.pdf
However few apps follow the required convention, so WordPad will convert Docx or RTF via command line but can not handle a PDF and Edge AFAIK was not designed to make the PDF format CLI print friendly :-). But those links you have in the question will suggest acrord32 /p or /t filename printer printdriver filename and that is probably the best method for flattening acroforms
Disclaimer I support SumatraPDF so can suggest to "Print As Image ONLY" its perfect as one single 32 or 64 bit portable.exe https://www.sumatrapdfreader.org/prerelease so all you need is:-
SumatraPDF -print-to "My Print to PDF" filename.pdf (or other types supported)
There are other print methods/options but BE-AWARE that is NOT flattening forms since "Flattening" means convert the form to plain readable text and SumatraPDF ONLY prints PDF as Imagery.
So combining SumatraPDF with a promptless port will provide a single command to build a known output then you need to monitor that output and rename to one of your choice, that can be tricky if you are submerged and "running silent and deep" without GDI feedback (that the print is spooling/erroring) and time is as variable as the input PDFs complexity.
You use the word "Slow" but that is the innate feature of PDF "Slow and Steady" output are its designed aims.
As an alternative to SumatraPDF two other viewers are more geared towards PDF Command Line printing. One is Acrobat Reader as per above "/Terminate and Stay Resident" and it does that exceptionally well so should be preferred. A good alternative lightweight but powerful PDF handler is Tracker PDF X-change which has both command line printing and its own programmable printer drivers.
Win2PDF has a command line to create image only (flattened) PDF files.

ghostscript annotation conversion

I'm trying to convert from pdf to pdf/a using version 9.19 on win server 2012r2.
commandline:
"D:\Program Files\gs\gs9.19\bin\gswin64c" -dPDFA -dNOOUTERSAVE -dColorConversionStrategy=/sRGB -dProcessColorModel=/DeviceRGB -sDEVICE=pdfwrite -o target.pdf -dPDFACompatibilityPolicy=2 "PDFA_def.ps" source.pdf
For a lot of files I get
"Annotation set to non-printing, not permitted in PDF/A, aborting conversion"
Using Acrobat Pro conversion, it converts non printing annotations without problems.
What may I need to look for in PDFA_def.ps?
There is nothing to look for in pdfa_def.ps, since that is just a template for the additional information required to produce a PDF/A file.
Your problem is that your annotation is not valid for inclusion in a PDF/A file, non-printing annotations are not permitted in PDF/A. To create a PDF/A file from such an input, either the annotation must be removed, or it must be set to print. Ghostscript's pdfwrite device cannot know which one you want.
However, you can change the PDFACompatibilityPolicy; the default value is 0 which will include the offending feature, and produce a non-PDF/A file. You can try changing it to 1 instead which will ignore the feature. I'm not in a position to test this right now (I'm heading for an airport) but it ought to work.
Obviously I don't know what Acrobat does in this case, but it must do something similar, or produce an invalid file. At least Ghostscript gives you the choice.

How to get the name of the exe in the Innosetup script from the full path of the exe is given?

For example if the full file path of the exe is provided as C:\Projects\Executable\Serial Data Streaming Recorder.exe, I need to extract the name of the exe. That is Serial Data Streaming Recorder and I want to dynamically assign this value to a variable from the full file path of exe.
Manually done like in below example:
#define ExePath "C:\Projects\Executable\Serial Data Streaming Recorder.exe"
#define AppName "Serial Data Streaming Recorder"
I want to dynamically assign the value Serial Data Streaming Recorder to the variable AppName from the full file path of exe.
I'm using this name in many places in the inno script for many files, So i don't want to do it manually by assigning this value to a variable.
To do this at runtime in [Code] You can get the file name and extension using the ExtractFileName(). I think you can then remove the extension by passing blank to the ChangeFileExt() function but if not, you can find and remove it using standard string operations like Pos() and Delete().
If you need to do this at compile time, you need to use ISPP, most of the functions have the same name and signature so use ExtractFileName() to get the file name itself, RPos() to get the period and Delete() to remove it.
Hmm... I usually solve this simply by never using any absolute paths in my install scripts. You can also just define ExePath like this:
#define BasicName "Serial Data Streaming Recorder"
#define ExePath "C:\Projects\Executable\" + BasicName + ".exe"
and then use {#BasicName} whenever you need just the name.
There are also several preprocessor script functions (not pascalscript) that can do string manipulations to do more advanced stuff.

Disable BAD/Discard file log on SQL Loader

Is there a way to prevent sqlloader from creating either the BAD file or the DISCARD file or both?
I read in a forum that setting the BAD parameter to NUL or NULL does that, but it doesn't seem to work. Something like:
sqlldr control=CONTROL.ctl data=DATA.txt bad=NUL
This ends up creating a file called NUL.bad (or NULL.bad depending on how you spell it)
Discard file should be optional, based on a discard predicate / discard parameter, but the Bad file is not an optional file - if you get rows rejected when loading, it will generate the file.
You could try send bad to the null depending (/dev/null in unix, NUL windows), did you set the right one for your OS?

Resources