I'm working on a Backbone project coupled with a koa/node backend that reads on a psql database. I setted a get route that is supposed to point to PDF files, and I was expecting to obtain base64 encrypted strings for each of them. I got this object instead:
{"0":37,"1":80,"2":68,"3":70,"4":45,"5":49,"6":46,"7":51,"8":10,"9":37,"10":196,"11":229,"12":242,"13":229,"14":235,"15":167,"16":243,"17":160,"18":208,"19":196,"20":198,"21":10,"22":52,"23":32,"24":48,"25":32,"26":111,"27":98,"28":106,"29":10,"30":60,"31":60,"32":32,"33":47,"34":76,"35":101,"36":110,"37":103,"38":116,"39":104,"40":32,"41":53,"42":32,"43":48,"44":32,"45":82,"46":32,"47":47,"48":70,"49":105,"50":108,"51":116,"52":101,"53":114,"54":32,"55":47,"56":70,"57":108,"58":97,"59":116,"60":101,"61":68,"62":101,"63":99,"64":111,"65":100,"66":101,"67":32,"68":62,"69":62,"70":10,"71":115,"72":116,"73":114,"74":101,"75":97,"76":109,"77":10,"78":120,"79":1,"80":149,"81":86,"82":203,"83":114,"84":26,"85":89,"86":12,"87":221,"88":247,"89":87,"90":104,"91":118,"92":120,"93":145,"94":235... }
Has anyone ever seen this kind of representation for a PDF file? How can I get this data back as a regular PDF file?
Thanks for helping!
This looks like a pretty broken way to get things out of a database. Your object is a pair of {position: byte}, as Python hints the first items are part of a PDF header:
>>> [chr(i) for i in [37, 80, 68, 70, 45, 49, 46, 51]]
['%', 'P', 'D', 'F', '-', '1', '.', '3']
Since you did not specify any libraries/code, I can’t provide any direct advice, but you should check what your database really contains (this should be a BLOB of binary data, not base64 or crazy JSON) and how to get the raw binary data out of your database using the libraries of your choice.
Related
I have a job which processes files and then lands them as single CSVs on a blob storage container. The problem I face is that I also need to land empty files, which only contain the header. How can this be achieved when I use .saveSingleFile?
Example Code snipped:
df.coalesce(1)
.write
.options(configuration.readAndWriteOptions)
.partitionBy(INGESTION_TIME)
.format("csv")
.mode("append")
.saveSingleFile(path.toString)
Example readAndWriteOptions:
{"sep": ";", "header": "true"}
In other words:
In above case, if df.show() is only displaying a header, no CSV file is written. However, I want to output a csv file without data but column names. Is there an option which would allow this ? Both cases need to be possible, if data is available and if data is not available, therefore something like .take(1) will not be a sufficient solution.
Update:
Looks like this is related to a Spark API Bug and should have been resolved with Version 3.
I need to store the data presented in the graphs on the Google Ngram website. For example, I want to store the occurences of "it's" as a percentage from 1800-2008, as presented in the following link: https://books.google.com/ngrams/graph?content=it%27s&year_start=1800&year_end=2008&corpus=0&smoothing=3&share=&direct_url=t1%3B%2Cit%27s%3B%2Cc0.
The data I want is the data you're able to scroll over on the graph. How can I extract this for about 140 different terms (e.g. "it's", "they're", "she's", etc.)?
econpy wrote a nice little module in Python that you can use through a command-line interface.
For your "it's" example, you would need to type this command in a terminal / windows console:
python getngrams.py it's -startYear=1800 -endYear=2008 -corpus=eng_2009 -smoothing=3
This will automatically save the query result in a CSV file named after your query parameters.
econpy's package, in #HugoMailhot's answer, no longer works (2021) and seems not maintained.
Here's a updated version, with some improvements for easier integration into Python code:
https://gitlab.com/cpbl/google-ngrams
You can call this from the command line (as in econpy's) to create a CSV file, e.g.
getngrams.py it's -startYear=1800 -endYear=2008 -corpus=eng_2009 -smoothing=3
or call it from python to get (and plot) data directly in python, e.g.:
from getngrams import ngrams
df = ngrams('bells and whistles -startYear=1900 -endYear=2018 -smoothing=2')
df.plot()
The xkcd functionality is still there too.
(Issues / bug fix pull requests /etc welcome there)
So I need to transfer information from a file. An example of the heading is label=1234 I was hoping I could use a perl code to change "label" to "id", is this possible?
Cy.js supports JSON data. Convert or write your data to JSON, and you can load it in as described in the docs: http://cytoscape.github.io/cytoscape.js/
I have to generate a tiff file with many images and meta data.
I found that it's possible to convert a png or a jpg to tiff here :
But how to add meta data ? it is possible with ImageMagic for iOS ?
thanks
Edit: finaly i installed ImageMagick on iphone, but i don't found how to create multipage tiff with magickwand .... it's possible also to use libtiff directly :
i found how to create a empty simple page in c code
char buffer[25 * 144] = { /* boring hex omitted */ };
TIFF *image;
char szFileName[512];
strcpy(szFileName, getenv("HOME"));
strcat(szFileName, "/Documents/");
strcat(szFileName, "output.tif");
// Open the TIFF file
if((image = TIFFOpen(szFileName, "w")) == NULL)
{
printf("Could not open output.tif for writing\n");
}
// We need to set some values for basic tags before we can add any data
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, 25 * 8);
TIFFSetField(image, TIFFTAG_IMAGELENGTH, 144);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 144);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
// Write the information to the file
TIFFWriteEncodedStrip(image, 0, buffer, 25 * 144);
// Close the file
TIFFClose(image);
So are there any c tutorial about how insert images Data in the created tiff file ?
and how create multipage tiff ?
thx
I have used LibTIFF - but not on iOS directly. But then, it is a plain old C library, so should be fine. I do note that the Apple Image I/O framework supposedly supports image meta-data (but again, I have not used this myself). See link here - but seemingly nothing for multi-page TIFF or bespoke tags, only standardised camera info tags...
However, in plain C, adding your own bespoke tags is usually performed most simply by modifying the core library and adding them to the main header file: tiff.h along with a few wrapper functions.
See section on "Adding New Tags"
And then you can refer/use them as you would other TIFF tags, e.g. what I have done to load in some embedded xml data:
TIFFGetField(lp_tif,MYTAG, &lp_xml)
Of course, you then have to ship/maintain your modified version of libTIFF (new "public" tags have to go through the process with Adobe).
The example you posted is fine for writing a single TIFF file (i.e set all the tags then write the contents of buffer to the file). For multi-page TIFF - it's one step further. You need to understand the concept if a Image File Directory (IFD). I would suggest looking at this link further to understand the use of the functions:
TIFFWriteDirectory()
TIFFReadDirectory()
NB: Properly, every TIFF file should have one directory to associate all the tags and image data together.
Finally, you can of course go one level even further! If you know the fixed structure of the TIFF file you want to create - simply write the bytes without even using LibTIFF.
In case it is an option for you to use a script for adding the meta data:
Use Phil Harvey's exiftool!
exiftool is a quite powerful, well-documented (and multi-platform) commandline utility to read and write meta data from/to lots of different file formats, including TIFF.
I got this question from my cousin:
"What will be the best way to create a similar working website just like: http://www.plakletters.nl".
I have looked into the website and think that to start of with i'm gonna help my cousin write a script that loads all fonts installed on the system into a dropdownlist. This dropdownlist will post a font value back to the page and will create images with the input of a user that comes from a textbox. This images will have to be created server side, and I also want to give the users the ability (in the future) to lay their own text over an uploaded image, to see what the result will look like on their own image. I found some information about how to create images using php, I don't know if php can output a list of installed fonts from the system it's running on. What scripting language would you use to get this job done? Keep in mind i would just like to start with outputting some images based on user input using a scripting language.
ImageMagick. This can be called from the shell or with the Perl bindings or with bindings for a lot of other languages. See http://www.imagemagick.org/Usage/text/
If you use perl, another alternative is the Imager module. This tends to be a simpler install than ImageMagick/PerlMagick.
Adding text looks like:
use Imager;
my $img = Imager->new(file => "foo.jpg") || die Imager->errstr();
my $font = Imager::Font->new(file=>"Arial.ttf");
$img->string(
x => 50, y => 70,
string => "Hello, World!",
font => $font, size => 30,
aa => 1, color => 'white'
);
$img->write(file => "foo2.jpg");
More details here.
Well, my favorite language is Python, so that's what I'd use! :) The PIL module gives you image manipulation capabilities.
Although I have never used PIL before, I put together the following with a few minutes of research and experimentation:
import Image
import ImageDraw
im = Image.open("my_image.png")
draw = ImageDraw.Draw(im)
draw.text((0,0), "my text")
im.save("my_out.png")
As you might have guessed, this just opens a PNG file, writes "my text" into it in the upper left corner and saves the modified image with a new name. I do not know how to get the font information you're looking for, but expect there's a module that can help with that also.