Easy way to make a test PDF of a certain file size - file

want to test the upload file size limit in an application, and it's a pain finding / making various pdf's of certain sizes to test / debug this. Anybody have a better way?

You can write a simple shell script that converts set of images to pdf: How can I convert a series of images to a PDF from the command line on linux? and do it for 1,2,3, ..., all image files in certain directory.
Creating directory full of copies of single image, should be simple too, start with one image file with desired size e.g. 64KB.
# pseudocode - don't test it
END=5
for i in {1..$END}; do cp ./image ./image_$i; done
for i in {1..$END}; do convert ./image_{1..$i} mydoc_$i.pdf; done

I've found an online tool, however, it seems to not be working correctly since it can only generate 10MB files even though you tell it to make a 50MB file.
https://www.fakefilegenerator.com/generate-file.php

Related

Compressing PDF with ghostscript in .bat file - missing text

I am trying to compress PDF file and turn it grayscale with .bat script and i have big problem.
When i do the compression, the text in PDF turns red, when i added grayscale lines, after script finished its job, text is white/Gone.
Can someone help me fix it so the text can be still black? My script part:
gs -sDEVICE=pdfwrite -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray -sOutputICCProfile=sgray.icc -dPDFSETTINGS=/ebook -dCompatibilityLevel=1.7 -dCompressFonts=true -dEmbedAllFonts=true -dNOPAUSE -dQUIET -dBATCH -dAutoRotatePages=/None -sOutputFile="%TEMP%\%%~nxf" "%%~f"
Here is the image before and after compression :
You haven't said which version of Ghostscript you are using. You have not supplied the PDF file so that it can be investigated (pictures may show the problem, they are not helpful for diagnosing or fixing it).
You should not set -dProcessColorModel, especially not when you have set -sColorConversionStrategy.
You absolutely should not be setting -sOutputICCProfile.
There's really no point in setting PDFCompatibilityLevel higher than the pdfwrite device already sets it, unless you are adding content via pdfmark operators which requires a higher level (and you aren't doing that).
There's also no point in setting CompressFonts=true or EmbedAllFonts=true, as these are the default values.
When you are trying to diagnose a problem, don't set -dQUIET, you want Ghostscript to tell you about anything it thinks might be a problem.
On Windows (which I assume this is because you are talking about a .bat file) the Ghostscript executable is called gswin32, gswin32c, gswin64 or gswin64c, not gs. So I'm somewhat puzzled as to how you;re getting this to work at all.
You have set -dPDFSETTINGS=/ebook after setting -sColorConversionStrategy, if you look at the table of settings in the documentation you will see that the /ebook setting sets the colour conversion strtaegy to RGB, since that comes later on the command line than your ColorConversionStrategy, that's the one that takes precedence. The confusion between ProcessColorModel (DeviceGray, from your command line) and ColorConversionStrategy (RGB from the PDFSETTINGS value) is very possibly what is causing your problem.
When faced with this kind of problem I'd suggest you simplify the command line until you figure out what exactly is causing it. I would also suggest that you don't use PDFSETTINGS at all, as that changes many configuration controls all at once. Figure out which ones you want to use and turn them on individually.
As a final point, Ghostscript's pdfwrite device doesn't 'compress' PDF files, it produces PDF files from its input. If you choose to take action such as downsampling images or altering the colour space then it's possible that a new PDF file will be smaller than an input PDF file. It's not compressed though, it's smaller because you have discarded information.

How would I store different types of data in one file

I need to store data in a file in this format
word, audio, jpeg
How would I store that all in one file? Is it even possible do would I need to store links to other data files in place of the audio and jpeg. Would I need a custom file format?
1. Your own filetype
As mentioned by #Ken White you would need to be creating your own custom file format for this sort of thing, which would then mean creating your own parser type. This could be achieved in almost any language you wanted but since you are planning on using word format, then maybe C# would be best for you. However, this technique could be quite complicated and take a relatively large amount of time to thoroughly test your file compresser / decompressor, but may be best depending on your needs.
2. Command line utilities
Another way to go about this would be to use a bash script to combine all of the files into one file, and then decompress it at the other end. For example the steps could involve:
Combine files using windows copy / linux cat command on command line
Create a metdata file of your own that says how many files are in this custom file, and how much memory each one takes up (could be a short XML or JSON file for example...)
Use the linux split command or install a Windows command line file splitter program (here's just one example) to split the file back into whatever components have made it up.
This way you only have to create a really small file type, and let the OS utilities handle the combining of them for you.
Example on Windows:
Copy all of the files in your current directory into one output file called 'file.custom'
copy /b * file.custom
Generate custom file format describing metadata (i.e. get the file size on disk in C# example here). This is just maybe what I would do in JSON. SO formatting was being annoying so here's a link (Copy paste it into an editor or online JSON viewer).
Use a decompress windows / linux command line tool to decompress each files to the exact length (and export it back to the exact name) specified in the JSON (metadata) file. (More info on splitting files on this post).
3. ZIP files
You could always store all of the files in a compressed zip file, and then just use a zip compressor, expander as and when you like to retreive any number of file formats stored within.
I found a couple of examples of :
Combining multiple files into one ZIP file in only C# .net,
Unzipping ZIP files in C#
Zipping & Unzipping with only windows built-in utilities
Zipping & Unzipping in Linux command line
Good Zipping/Unzipping library in Java
Zipping/Unzipping in Python

Batch Scripts - Alternative Output to Notepad?

Good Afternoon,
Basically, I have a batch script that does the following:
Pings multiple network machines
Writes the result to a txt file
Searches the created txt file for certain keywords, then outputs that to a separate txt file
Displays the 2nd txt file
It's all very nice and lovely, basically if the machine pings fine then all it shows is the "Pinging xxxxx [10.xxx.xxx.xxx] with 32 bytes of data:" & "Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)" lines.
If it detects anything other than a good ping, it will report the error message in addition to the 2 lines above.
Which leads me to the question...
Is there an alternative output to notepad for the log file? The information that is displays is exactly what I need, but because it's pinging 20+ assets it looks extremely cluttered and ugly. Are there any decent alternatives to display the log file?
Apologies if this is a stupidly basic question, it's after lunch so my brain is only functioning at 0.01% of it's usual power...
I made good experience with writing a .tex file and compiling it with latex (or its derivatives) into a .pdf file. Also, I use a bash script to write a .html document. An .xml file is a nice way to provide the data and an associated .xsl style sheet will add the appropriate visual representation.

Copying multiple files to a Winscp directory via Script

I have a problem when trying to upload multiple files to one WinSCP directory, i can manage to copy just one single file, but the problem is that i need to upload many files that are generated by a software, the names are not fixed ones, so i need to make use of wildcards in roder to copy all of them, i have tried many variants on the code, but it all was unsuccessful, the code i am using is:
open "sftp://myserver:MyPass#sfts.us.myserver.com" -hostkey="hostkey"
put "C:\from*.*" "/Myserverfolder/Subfolder/"
exit
This code does actually copy the first alphabetically named file, but it ignores the rest of the files.
Any help with it would be much appreciated
Try this in script
Lcd C:\from
Cd Myserverfolder/Subfolder
Put *
Try and do all manually first so you can see what's going on.

Complexity of getting a file C#

Im thinking of storing a large number of files in a folder and load them into my C# program. The problem I thought about was the performance when loading a file to read from, from a folder that contains very many files. Will the time to load and read from a file be about the same when there is one file in the chosen folder or one million? Does anyone know the complexity? ( O(1), O(n), O(n^2)? )
If you are only selected one file, it does not if there is one or a million files, as long as you pick the path correctly.
If you are trying to read all the files,and then search from that, then that is different :P
but if you have the exact file path to it, then no difference

Resources