How to convert PDF to Image without generating a file - ghostscript

Based on the Code How-To-Convert-PDF-to-Image-Using-Ghostscript-API
I trying to figure out how to get a image foreach page without creating the files
To get an image foreach Page i setted OutputToMultipleFile = true.
Then i went step for step through his code but i wasn't able to find the part where the files get created.
So i want to know what i need to change in this code?
or anything else which helps to achieve this
EDIT
here my current parameters:
args[0] =
args[1] =-dNOPAUSE
args[2] =-dBATCH
args[3] =-dSAFER
args[4] =-sDEVICE=pnggray
args[5] =-r130
args[6] =-sOutputFile="C:\Scannen1.PDF%d.png"
args[7] ="C:\Scannen1.PDF"

You need to use a device which doesn't write to file, all the image format devices write their output to file. You could use the display device which will return you a bitmap in memory as a template and write your own device, or you can modify one of the existing devices.
Modifying an existing device is a task for a developer and while not excessively difficult is not trivial either.
In any event, you aren't going to get what you want by fiddling with command line switches. Like Sinatr I'm puzzled by what you can usefully do with Ghostscript which doesn't involve writing to file.
Oh, one other possibility is to load the nulldevice, which is done in PostScript and is simply a bit bucket.

Related

Read a tiff image in lua löve (love2d)

I wrote a little program using lua LÖVE. Now I would like to make it read some TIFF files, since LÖVE does not support this image format. And I failed.
Basically, LÖVE can read the file from some userdata. I thought that I might read the data with another library and convert it internally to a format that LÖVE supports, but can't find anything suitable. I looked at graphicsmagick lua bindings, but unfortunately it does not appear to be up to date. I tried to get it too run, but gave up after a while; I would probably have to rewrite the whole package and I can't even find some of the modules it uses (for example the "sys" module).
EDIT: Some more background. I need a fast image viewer to quickly browse through files on the disk. I do not like to use the file manager for that purpose, and I would like it to behave exactly as I want it to behave. I was using xzgv for this purpose for years.
When I discovered lua and LÖVE, I decided to write one both as an exercise and because I want to have a little tool like that (you can see how it looks like here).
Here is a solution which does not requires any libraries. Basically, the idea is that you convert an image using the convert program from the ImageMagick suite and pipe its output to a filehandle with io.popen. That way the file is read only once from the storage.
local cmd = "/usr/bin/convert %s -format JPG:-"
local file = "test.tiff"
local fh = io.popen(cmd:format(file), "r")
local fdata = fh:read("*a") -- read all
fh:close()
fdata = love.filesystem.newFileData(fdata, file)
local img = love.graphics.newImage(fdata)

Is there a way I can use a different extension than .txt such as .log or .csv when using ApprovalTests?

I want the content to remain a text file, so code such as:
Approvals.Verify("some actual result as text");
Should continue to work. But I would like the approval tests to write to a ..approval.csv file or a ..approval.log file instead of ..approval.txt file.
I looked through the code and I think I may need to create a custom IApprovalWriter, but I also notice that the ExtensionWithDot property is read/write, so I'm wondering how this can be set.
Does anyone know how to do that?
ApprovalTests.Approvals.Verify(WriterFactory.CreateTextWriter(text, fileExtensionWithoutDot));
or for your example:
Approvals.Verify(WriterFactory.CreateTextWriter("some actual result as text", "log"));
Happy Testing!

Include pictures while converting ps1 to exe with PowerGUI

I use the PowerGUI editor to convert a ps1 file to an exe file. Reason is that I dont want people to see my source code. The script includes a own little GUI with a picture on it. My problem is that after converting the script to an exe file the picture will only be shown when it exists on a specific path. If I delete or move the picture from that path it wont be shown when starting the exe.
How can I include the picture to the exe? I want to have only one file in the end ...
One way you could do this is by converting your image into a Base 64 String, using the following:
[convert]::ToBase64String((get-content C:\YourPicture.jpg -encoding byte)) > C:\YourString.txt
With the string that is produced in the text file "C:\YourString.txt" you can copy and paste it into your code and load it into a picture object on the form like so:
$logo.Image = [System.Convert]::FromBase64String('
iVBORw0KGgoAAAANSUhEUgAAAfQAAACMCAYAAACK0FuSAAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAAXEQAAFxEByibzPwAAAAd0SU1FB98DFA8VLc5RQx4AANRpSURBVHhe7J0FmBTX0oZ7F1jc3d3d
nU+dOtXw4MGDZfft25fmyJEjPu+//76Xqzke8pCHPOQhD3lIQGxxcGSapvHdd9+FF3hHEdjGFHgn
....... Many more lines of string .......
OqelFQzDMAzD/CZoztADbUwhUm0JERoXCNfEQYhyPAQryiBIUQSBiiTwl1sb3skwDMMwzG+KWLVe
jTEBH6U7JvJ0CJQXoaGPQMWBm5W+Va27k14MwzDMfwCA/wfUstOLO+nBIAAAAABJRU5Jggg==')
Do this will mean that your image is stored within the code already and doesn't need to be loaded from somewhere.
Note: Make sure that the pictures size on disk is the smallest you can get it as producing the string can take sometime and could turn out thousands of lines long. So I would recommend that you only use a pic that is less that 75 Kilobytes in size. You could do it with larger one but this will take a long time to process.

Loading files during run time in XNA 4.0

I made a content pipeline extension (using this tutorial) in XNA 4.0 game.
I altered some aspects, so it serves my need better, but the basic idea still applies. Now I want to go a step further and enable my game to be changed during run time. The file I am loading trough my content pipeline extension is very simple, it only contains decimal numbers, so I want to enable the user to change that file at will and reload it while the game is running (without recompiling as I had to do so far). This file is a very simplified version of level editor, meaning that it contains rows like:
1 1,5 1,78 -3,6
Here, the first number determines the object that will be drawn to the scene, and the other 3 numbers are coordinates where that object will be placed.
So, how can I change the file that contains these numbers so that the game loads it and redraws the scene accordingly?
Thanks
Considering you've created a custom content pipeline extension I presume you know how to load in data using streamreader? Where you could just empty your level data and load new data in by reading through the text file line by line?
The reason I mention this is because as far as I am aware it's not possible to load in data through the content pipeline during runtime especially because the xna redistribute does not contain the content pipeline.
Another option could be to change to using xml for the level file and use XElement which I quite recently found and this is my current method.
Here is a commented example of using StreamReader to load in simple level data from a .txt file. http://pastebin.com/fFXnziKv
In XNA 4, if you are using StorageContainer, you can do something like:
(...)
StorageContainer storageContainer = //get your container
Stream stream = storageContainer.OpenFile("Level.txt", FileMode.OpenOrCreate);
StreamReader sr = new StreamReader(stream);
while (!sr.EndOfStream)
{
String line = sr.ReadLine();
//use line to do something meaningful
}
stream.Close();
storageContainer.Dispose();
(...)
From personal experience, if you go for raw TextReader, the only problem is to get the path of your Content folder, which can be relatively easy to retrieve (in Windows only!)

how do you load files in windows phone 7? using XNA

I am porting an iphone game to windows phone 7. iphone works fairly similarly to Winmo7 in that you add all the files you want to be able to read to the project. we didn't want this extra step in our asset creation pipeline, so we just made it so all files were put into our own basic file archive, then just added that one archive file to the project. we then have an asset build process that exports all our assets, then creates this archive from them.
in winmo7 it caught me by surprise that you couldn't just do the same thing. as far as I know, the only way you can load data is though the content pipeline. we solved this fairly easily though by simply making a contentImporter that would just convert all the files to byte[] and export them as byte arrays, then you can simply load them an just directly access all the bytes that are in the file. unfortunately, unlike c++ where you would just cast memory to structures (because the file would already be stored in the structure's format) c# seems to require a more manual approach, where you use things such as BitConverter to load all the data into structures and classes from the byte array.
the thing is, we want to use our already existing asset export processes for things like textures and meshes, were we already have stuff setup for figuring out the exact pixel format that should be used for each texture ect. so in those cases we don't want to use the default Texture and Mesh content Importers. we tried making our on Texture ContentImporter, by simply making it return a Texture2D, but in order to create a Texture2D, you need a graphics device.
the second problem was the process of having to add every asset to the project. we decided that we didn't want to just load our dataArchive like we do for the iphone, because we DO want to use the default ContentImporters for Some of the data (like sound). but we solved this problem by making it so you just add one text file, with the root data dir in it, to the project, then made a ContentImporter that iterates through that directory structure and calls 'context.BuildAsset' on all the files there.
so summing up, we have one asset and ContentImporter that automatically handles the importing of all the assets in the data directory, thus solving the problem of having to add them manually to the project. some of these assets will be directed through the default ContentImporters (like sound and music, and xmls) while others will just be imported as byte[] and loaded manually, because we already have the asset in the format we want. in the case of those assets, it would be good if we could do the 'byte[] -> loaded manually' inside custom ContentImporters - offline- but for the first one we tried - Textures - it required a Graphics device to create the native Textue2D structure, and we couldn't find one in the ContentImporter framework.
so any thoughts? pointers? or is this the bestest way to do everything? I suppose another option would be to just convert all assets to a format the default Texture and Mesh processors can take in, and parameters to go with each of them (so we have a hand crafted 565 texture, convert it back to an 888 tga, then send it through the default texture pipeline with a parameter saying "convert this to 565")
TitleContainer
its this new class they added in 4.0, and is a little less explicit than the File stuff
just go TitleContainer.OpenStream(path)
It's straight forward to open a text file and read the contents in a WP7 project. Here is one way.
Uri linesUri = new Uri("lines.txt", UriKind.Relative);
StreamResourceInfo stream = App.GetResourceStream(linesUri);
StreamReader streamReader = new StreamReader(stream.Stream);
var contents = streamReader.ReadToEnd();
streamReader.Close();
I initially dragged the lines.txt file into my project from explorer - no other handling was necessary for this code to work.
Include the references you need...
using System.IO;
using System.Windows.Resources;
Rephrase the question and I would be more than happy to help you. Specifically, give examples of the issues you are trying to solve. I have done a lot work with the content pipeline in XNA and could share with you some tips.
I will update my answer once you give more details.

Resources