I have a lot of programming niche interests -- video, VNC, static analysis, PDF, filesystems, Flash, SOAP, etc. Most of all, I love it when these interests intersect. For example, I wrote still-closed-source (sigh) library that converts a VNC stream to QuickTime. A prototype of that software was the basis for the YAPC::NA 2006 videos I produced.
Another convergence happened last week. Google released MacFUSE 1.x, a Mac port of the Linux user-mode filesystem code. I had tried an earlier version, but I never got the Perl bindings (Fuse.pm) to work right. What can this do? It lets you write your own mountable virtual filesystem in a couple hundred lines of code.
Back in 2002-2005, I did a ton of PDF work. A result of that was a base library, CAM::PDF. I got authority to release it to CPAN about the same time the business motivation for the library dried up. But in the process, I learned the PDF specification inside and out. PDF is basically a serialization of an arbitrary tree structure: strings, numbers, hashes, arrays, references and blobs, all in an almost-human-readable syntax.
You can store anything in PDF. Most of that tree is focused on storing pages, text and graphics, but the fascinating part is that's just convention. The underlying data structure is generic.
So why not put filesystem data and metadata inside a PDF? I mentioned the idea at the last Madison Perl Mongers meeting and they laughed at me! (LAUGHED! at ME!) Well, that was enough motivation! A weekend later, I released Fuse:PDF v0.01 to CPAN. It's still very worthy of the v0.01 label (no symlinks, no hardlinks, no large files) but it's usable.
What do you think? Inspired or daft? Should I have put it in the Acme:: namespace? :-)
[Along the way, I'm also writing Test::Virtual::Filesystem which is a collection of typical file I/O actions that should work on any mounted filesystem.]
Re:Inspired? Lunatic!! :-)))
ChrisDolan on 2007-11-17T01:29:07
So you mount a PDF doc as a filesystem. I was wondering: what happens when you try to open such a PDF in Acrobat and try to print it out?:-)
Nothing unusual. The filesystem does not affect the rendering of the PDF in any way. It's as if the filesystem were in the comments of an HTML file -- it just makes the PDF bigger from the point of view of rendering.
Oh, and yes, I would have put that under ACME... well, at least that first implementation. But if you come up with a clever mapping, so that when mounting a real PDF the text inside is available as.txt files and the graphic is available as .png or .jpg, this would really be a nifty way of editing PDFs...
Hmm, that's a clever idea. But it would only work well for read-only. The PDF layout format is way too specialized to be able to round-trip as a text file. Unless you meant present the PDF rendering commands in a text file?
Re:Inspired? Lunatic!! :-)))
RGiersig on 2007-11-19T14:50:08
Well, I was thinking more into the lines of quick-n-dirty PDF template munging. Create a PDF template with some dummy text and then simply mount it and replace the dummy text with something more appropriate. If this allows to replace a whole textbox full of text, perfect! Even if you could only replace lines of text it could be useful. Exchanging a picture with one of the same dimensions should work regardless, no?
Oh, and yes, I would have put that under ACME... well, at least that first implementation. But if you come up with a clever mapping, so that when mounting a real PDF the text inside is available as.txt files and the graphic is available as .png or .jpg, this would really be a nifty way of editing PDFs...
Hmm, that's a clever idea. But it would only work well for read-only. The PDF layout format is way too specialized to be able to round-trip as a text file. Unless you meant present the PDF rendering commands in a text file?
OK, mounting the PDF is probably mostly useful for steganography. But part of that could be a simple interface to traverse the PDF. Or does this already exist?Re:Inspired? Lunatic!! :-)))
ChrisDolan on 2007-11-20T00:01:10
Since you came up with this idea, I've been thinking about it a lot. PDF has a VERY write-only syntax (Perl's ill-gotten reputation has nothing on PDF), but I think there are a few opportunities here. Keep an eye on this journal over the next couple of weeks.;-)
Re:Inspired? Lunatic!! :-)))
RGiersig on 2007-11-20T11:21:22
Hmm, would it be possible to add a PDF to the end of a mounted PDF? I mean, if you store a PDF into a mounted PDF that it would be incorporated in a way that it would also be printed out if I print the mounted PDF?
I'll keep an eye on you...;o) Re:Inspired? Lunatic!! :-)))
ChrisDolan on 2007-11-21T02:12:42
Hmm, like putting the extra PDF in a magic folder and make it auto-append to the existing PDF? That has a pretty awkward feel to me. Instead, you're probably better off using the appendpdf.pl helper in the CAM::PDF distibution.Re:Inspired? Lunatic!! :-)))
RGiersig on 2007-11-21T09:31:46
I'm aware that all those things can be better accomplished using PDF manipulation libs. I'm just brainstorming about somewhat useful (or lunatic) uses of a writeable mounted PDF from a PDF view and not from a filesystem view...;o)
Have a webserver serve a PDF and have that PDF mounted. Then in the crontab do
fortune >/mounted-PDF/chunk0042.txt
Insane? I hope so...;-)
Re:Inspired? Lunatic!! :-)))
ChrisDolan on 2007-11-22T06:57:26
Fuse::PDF v0.05 is on its way to CPAN. Here's what it can do:% mount_pdf -A test.pdf $PWD/mnt &
% find mnt
mnt
mnt/pages
mnt/pages/1
mnt/pages/1/fonts
mnt/pages/1/fonts/TT0
mnt/pages/1/fonts/TT0/Subtype
mnt/pages/1/fonts/TT0/BaseFont
mnt/pages/1/fonts/TT0/FirstChar
mnt/pages/1/fonts/TT0/LastChar
mnt/pages/1/fonts/TT0/Type
mnt/pages/1/layout.txt
mnt/pages/1/text.txt
mnt/metadata
mnt/metadata/Creator
mnt/metadata/Producer
mnt/metadata/CreationDate
mnt/metadata/ModDate
mnt/metadata/ID
mnt/filesystems
mnt/filesystems/FusePDF_FS
mnt/filesystems/FusePDF_FS/foo
mnt/filesystems/FusePDF_FS/bar
mnt/revisions
mnt/revisions/1
% more mnt/pages/1/fonts/TT0/BaseFont
HISDQN+Helvetica
% more mnt/pages/1/text.txt
F u s e : : P D F - E m b e d a f i l e s y s t e m i n a P D F d o c u
m e n t
C h r i s D o l a n < c d o l a n @ c p a n . o r g >
T o g e t s o f t w a r e t h a t c a n i n t e r a c t w i t h t h i s
f i l e s y s t e m, s e e
h t t p : / / s e a r c h . c p a n . o r g / d i s t / F u s e - P D F/
% umount $PWD/mnt