Hi there
I'm hoping someone could help with a problem I am experiencing when converting an XPS file to a PDF file using PDFsharp.
I have a very simple XPS document which contains only an image inside a canvas. When I view the XPS file I can see the image. When I used PDFsharp to convert the XPS file to a PDF file, the image is no longer displayed.
I have looked inside the PDF file which PDFsharp produces and the image data is there. It is a bit hard to follow the PDF command chain at a glance (I am in the process of having a closer look) but I’m fairly sure it is part of the document.
Interestingly, if I print the XPS file to a PDF file using PDFCreator I get a PDF file with the image in it.
Any ideas why a single image in an XPS file would convert to PDF but not display correctly?
My questions at the moment are:
-Could it be something like a render or layout transform (which I remove)?
-Could it be tiling (I notice the PDFsharp PDF file uses a pattern)?
-Is the PDF command to display the image being used?
Here is a more information into what I am doing roughly speaking:
1. First, I render a complex custom control to a PNG file as follows:
Code:
// Create a render bitmap and push the surface to it
RenderTargetBitmap renderBitmap =
new RenderTargetBitmap(
(int)size.Width,
(int)size.Height,
96d,
96d,
PixelFormats.Pbgra32);
renderBitmap.Render(surface);
I’ve already tried saving the control directly to XPS and this doesn’t work either, hence I’m trying the rendering to an image.
3. Create a very simple WPF Canvas control:
Code:
<Canvas>
<Image Source=”renderBitmap.png”
... no scaling, no stretching/>
</Canvas>
4. Save Canvas to XPS:
Code:
canvas.LayoutTransform = null;
Package package = Package.Open(filename, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
writer.Write(canvas);
doc.Close();
package.Close();
5. Convert XPS file to PDF using PDFsharp:
Code:
PdfSharp.Xps.XpsConverter.Convert(filename)
Any help would be much appreciated!!
Mark