0

I'm using the XNA framework and wish to incorporate multi-paged PDF files into my XNA application.

I understand that I can achieve this by creating a custom importer and processor but I can only find one example which refers to custom importers/processors. Unfortunately, since this example applies to shaders its not particularly helpful though - http://msdn.microsoft.com/en-us/library/bb447754.aspx

So just to summarise, any ideas how I can implement multi paged PDFs into my XNA application?

All replies are highly appreciated.

cbros2008
  • 353
  • 1
  • 7
  • 23

1 Answers1

1

The content pipeline does not handle your situation well. It does not support importing a single file and generating multiple outputs (in your case a PDF to a texture for each page). (reference)

In addition, I imagine you will want to use a third-party, external command-line tool to convert your PDF pages to textures (off the top of my head, ImageMagick is probably a good place to start). The following approach with also save you the hassle of integrating it into the content pipeline.

So here's what I would do: First of all, run your PDF conversion tool before the content pipeline build. The simple (but slow) place would be the pre-build event of your content project. I'd suggest converting PDF to multiple PNG files.

And then use a wildcard to include all those PNG files into your content project. Here's a question that explains it.

When you go to load your textures, simply use something like Directory.EnumerateFiles to find the names of the resulting XNB files in the appropriate content path.

(If you'd like to add drag-and-drop to Visual Studio you could mess about with MSBuild to remove PDF items and replace them with wildcard PNG items or something. This also has the advantage of allowing you to only rebuild your PNGs when the PDF changes, making your build much faster. I'll leave this as an exercise.)

Of course, if you're just doing a few, fixed PDF files - simply convert them to images directly with your tool and add those to your content project.

Community
  • 1
  • 1
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104
  • Thank you, since posting this, I did decide to convert the PDFs to PNGs then play with those. Thanks for the detailed answer! – cbros2008 Nov 04 '10 at 07:21