Hello,
I havelong sought a solution to this problem.
I have a series of images that are the result ofa conversion of a pdf into images precisely.
I need to createanXPSdocumentwith these imagesand in factthe code but it creates white but even ifoflarge dimensions.
There is someone to help me to resolve this problem ?
Thanks
this is code edited taken from her :http://social.msdn.microsoft.com/Forums/en-US/8c6eb3ee-f541-4e00-b0e9-a982db7c73f5/how-to-add-images-like-jpgtiff-into-xps-document
I reporthere mymodified codeasI do not haveimagesinxamlbut theloadfrom disk
private void ImageToXps()
{
String srcPage = "src.xaml";
String dstContainer = "text.xps";
File.Delete(dstContainer);
XpsDocument document = new XpsDocument(dstContainer, FileAccess.ReadWrite);
IXpsFixedDocumentSequenceWriter docSeqWriter=document.AddFixedDocumentSequence();
IXpsFixedDocumentWriter docWriter = docSeqWriter.AddFixedDocument();
IXpsFixedPageWriter pageWriter = docWriter.AddFixedPage();
String font1Path = Directory.GetCurrentDirectory() + "\\CURLZ___.TTF";
var files = Directory.GetFiles(@"C:\Users\Max\Desktop\Uni\", "*.tif").ToArray();
string[] imageuri = new string[files.Length];
for (int i = 0; i < files.Length; i++)
{
imageuri[i]=AddImage(pageWriter, files[i]);
}
String font1Uri = AddFont(pageWriter, font1Path);
//Load Markup file, and replace tokens with actual Xps URIs
StreamReader srcTextStream = new StreamReader(srcPage);
string pageContents = srcTextStream.ReadToEnd();
for (int i = 0; i < files.Length; i++)
{
pageContents = pageContents.Replace(files[i], imageuri[i]);
}
pageContents = pageContents.Replace("font1", font1Uri);
XmlWriter xmlWriter = pageWriter.XmlWriter;
xmlWriter.WriteRaw(pageContents);
pageWriter.Commit();
docWriter.Commit();
docSeqWriter.Commit();
document.Close();
}
private static string AddImage(IXpsFixedPageWriter pageWriter, String imageSource)
{
XpsImage image = pageWriter.AddImage(XpsImageType.JpegImageType);
string imageUri = image.Uri.ToString();
Stream dstImageStream = image.GetStream();
Stream srcImageStream = new FileStream(imageSource, FileMode.Open);
CopyStream(srcImageStream, dstImageStream);
image.Commit();
return imageUri;
}
private static string AddFont(IXpsFixedPageWriter pageWriter, String fontSource)
{
XpsFont font = pageWriter.AddFont(false);
string fontUri = font.Uri.ToString();
Stream srcFontStream = new FileStream(fontSource, FileMode.Open);
Stream dstFontStream = font.GetStream();
CopyStream(srcFontStream, dstFontStream);
font.Commit();
return fontUri;
}
public static void CopyStream(Stream srcStream, Stream dstSteam)
{
int arraySz = 1024 * 1024;
byte[] buffer = new byte[arraySz]; //1MB
long bytesRemaining = srcStream.Length;
while (bytesRemaining > 0)
{
long copyLng = (bytesRemaining > arraySz) ? arraySz : bytesRemaining;
srcStream.Read(buffer, 0, (int)copyLng);
dstSteam.Write(buffer, 0, (int)copyLng);
bytesRemaining -= copyLng;
}
}
www.Photoballot.net