How to view a GRF file - zpl

I have a txt file which is an impression of ZPL, but I can't pre-view that file. When opening the txt it has the following markup:
~DGR:DEMO.GRF,124236,102,:Z64:
What tool or code can I use to view this file?

The compression used for the GRF file is base64, so if you copy here all the stuff after the "Z64:" , you should be able to see the image.

Related

Extracting images from multiple PDF files using hexapdf - hexapdf no such file or directory # rb_sysopen

I'm in my master thesis and I have to extract images from about 500 pdf files, some people recommended hexapdf to me for this. I was able to install Ruby and hexapdf and now I'm kinda stuck getting the images out of the pdf's since I don't have a coding background. Any tips?
Thanks in advance.
I tried using the basic command for only one pdf to see what happened by using 'hexapdf images' followed by the pdf name but the result was 'no such file or directory # rb_sysopen'.
If you're getting no such file or directory # rb_sysopen, then that signals that the file you are trying to open does not exist. It sounds like this is probably the PDF that you are trying to extract images from.
I would check that you are following help provided by hexapdf documentation and that the path to your PDF is correct. If the file with your code and the PDF are in the same directory and you are running your code from that file, then you would do something like:
require 'hexapdf'
doc = HexaPDF::Document.open('my_pdf_document_filename.pdf')
If the file is somewhere else on the machine, it may be easiest to use a full file path instead of a relative file path which will depend on your system and such (e.g. /Users/username/thesis/image_processing/files/my_pdf_document_filename.pdf).

How to ensure that image files from Sphinx Documentation are copied "Automatically" in LaTeX pdf

In my Sphinx documentation project, I am using images like this:
.. image:: /_static/carousel_filling.png
:width: 300px
:height: 450px
:scale: 100 %
:alt: Image here
:align: right
In the Sphinx HTML docs generated, the images are perfectly displayed in the html pages. However, when I generate pdf documents using make latexpdf, I am coming up with the following error:
'LaTeX Warning: File `{carousel_filling}.png' not found on input line ...'
I tried to find documentation related to outputting images however I came up only with this:
Excertps from:
latex_additional_files A list of file names, relative to the
configuration directory, to copy to the build directory when building
LaTeX output. This is useful to copy files that Sphinx doesn’t copy
automatically, e.g. if they are referenced in custom LaTeX added in
latex_elements. Image files that are referenced in source files (e.g.
via .. image::) are copied automatically.
So as per this, the image files should get automatically added to the output pdf file. But this is not happening. In the pdf file where the image should be there only a blank rectangle can be seen.
Interestingly, I can see that the image file has been copied to the folder _build/latex, so it means that pdflatex is able to access the image file!!
Question
How do I correctly output the images included in my Sphinx documentation in generated pdf file?
Edit 1:
In the terminal I can see the following warning:
LaTeX Warning: File `{carousel_filling}.png' not found on input line 931.
! Package pdftex.def Error: File `"""{carousel_filling}".png' not found: using dra
ft setting.
See the pdftex.def package documentation for explanation.
Type H <return> for immediate help.
...
l.931 ...t=450\sphinxpxdimen]{{carousel_filling}.png}
?
[21]
Edit 2:
In place of the image (where the rectangle outline has been output in pdf file) I can see this:
"""{carousel_filling}".png
Don't place your images under _static. It is a special-purpose folder, not for images. E.g. create img/ at the level of your rst files, move image there, and .. image:: img/my-image.png.

Cannot write uploaded image to file

I'm trying to save an animated gif to a file location. Here is my current code:
# create folder location and file path name
my $dn="cmp".int(rand(10));
my $fn="ca".int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).".gif";
while (-f "$datapath/$dn/$fn") { $fn="ca".int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).int(rand(10)).".gif"; }
# open the uploaded image for saving to a file
open (IMAGE,$insfn{'attachment'});
binmode(IMAGE);
# open the file path for writing the image to
open (OUTPUT,"$datapath/$dn/$fn");
binmode(OUTPUT);
# write the image to the file
my $buf;
my $bufSize=4096;
while(read(IMAGE,$buf,$bufSize)) { print OUTPUT $buf; }
For some reason its not saving the image to the file.
Not sure what to do past this point Im fairly new to perl.
You haven't opened OUTPUT for writing.
replace
open (OUTPUT,"$datapath/$dn/$fn");
with
open (OUTPUT, ">", "$datapath/$dn/$fn");
and Perl will create the file, truncate it if it exists already, and allow writes to it.
Relevant documentation.

Convert a PDF to .txt gives me an empty .txt file

Hi I'm trying to read a pdf in Ruby, first of all I want to convert it into a txt. path is the path to the PDF, The point is that I get a .txt file empty, and as someone told me is a pdftotext problem, but I don't know how to fix it.
spec = path.sub(/\.pdf$/, '')
`pdftotext #{spec}.pdf`
file = File.new("#{spec}.txt", "w+")
text = []
file.readlines.each do |l|
if l.length > 0
text << l
Rails.logger.info l
end
end
file.close
What's wrong with my code? Thanks!
It's not possible to extract text from every PDF. Some PDF files use a font encoding that makes it impossible to extract text with simple tools such as pdftotext (and some PDF files are even completely immune to direct text extraction with any tool known to me -- in these cases you'll have to apply OCR first to have a chance to extract text...).
So if you test your code with the same "weird" PDF file all the time, it may well happen that you're getting frustrated over your code while in reality the fault lies with the PDF.
First make sure that the commandline usage of pdftotxt works well with a given PDF, then test (and develop further) your code with that PDF.
The problem is you are opening the file in write ("w") mode, whuch truncates the file. You can see a table of file modes and what they mean at http://ruby-doc.org/core-1.9.3/IO.html.
Try something like this, it uses a pdftotext option to send the text to stdout to avoid creating a temporary file and uses blocks for more idiomatic ruby.
text = `pdftotext #{path} -`
text.split.select { |line|
line.length > 0
}.each { |line|
Rails.logger.info(line)
}
You would need to open the txt file with write permission.
file = File.new("#{spec}.txt", "w")
You could consult How to create a file in Ruby
Update: your code is not complete and looks buggy.
Cant say what is path
Looks like you are trying to read the text file to which you intend to write file.readlines.each
spell check length you have it l.lenght
You may want to paste the actual code.
Check this gist https://gist.github.com/4160587
As mentioned, your code is not working because you are reading and writing to the same file.
Example
Ruby code file_write.rb to do the file write operation
pdf_file = File.open("in.txt")
output_file = File.open("out.txt", "w") # file to which you want to write
#iterate over input file and write the content to output file
pdf_file.readlines.each do |l|
output_file.puts(l)
end
output_file.close
pdf_file.close
Sample txt file in.txt
Some text in file
Another line of text
1. Line 1
2. Not really line 2
Once your run file_write.rb you should see new file called out.txt with same content as in.txt You could change the content of input file if you want. In your case you would use pdf reader to get the content and write it to the text file. Basically first line of the code will change.

Using PHPEXCEL with UTF-8 results in error messages

When I create an Excel Sheet with PHPEXCEL based on the "01simple-download-xlsx.php" example, I will get an error message in Excel as I am using UTF-8.
The error message says "Excel cannot open the file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file." I've used the 01simple-download-xlsx.php Testfile and tried to change the $objWriter to the one out of the 26utf8.php Testfile... both didnt work...
So how can I prevent this error and create a proper UTF-8 compatible Excel file with PHPEXCEL?
The reason was:
I have saved my php files with notepad in UTF-8 format. Therefor it was saved with the UTF-8 BOM. I have reopened the files in Notepad++ and saved the files as UTF-8 Without BOM. This way the Excel file gets generated correctly.

Resources