Search code examples
wpfvb.netxps

Exporting canvas to xps vb


Hi today I tried to export my canvas to a file. First I tried to export it to a png and it worked fine, everything looks the same as on the canvas.

After that I modified my code to export to a xps file.

    Dim thePack As IO.Packaging.Package = IO.Packaging.Package.Open(path.LocalPath,IO.FileMode.Create)
    Dim doc As New Xps.Packaging.XpsDocument(thePack)
    Dim writer As Xps.XpsDocumentWriter = Xps.Packaging.XpsDocument.CreateXpsDocumentWriter(doc)
    writer.Write(mycanvas)
    doc.Close()
    thePack.Close()

The code runs fine but it doesn't generate the exact same view as on my canvas/png.

Are there any functions to change the output of the writer? It seems like the visual objects are moved lower then the text inside them.


Solution

  • I don't know why but dropshadow was giving me an issue.

           <Border Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Name="rand" Style="{DynamicResource BorderStyle}" >
               <Border.Effect>
                   <DropShadowEffect  Direction="45" Color="#DDDDDD"/>
               </Border.Effect>
           </Border>
    

    After I removed the border.effect from my usercontrol the xps file was generated flawlessly.

         <Border Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Name="rand" Style="{DynamicResource BorderStyle}" >
        </Border>