Hello,
I’m attempting to convert an XPS => PDF (zoom in) => JPEG.
The pdf looks fine after saving, but once converted to a jpeg, it is missing some images. I’m not totally sure which conversion is at fault here, but something is definitely wrong. Here’s some example code and the source xps i’m using:
public static void ZoomBad()
{
var inputFile = @"d:\aspose\input\single_bad.xps";
var outputPdf = @"d:\aspose\output\single_output.pdf";
var outputFiles = @"D:\aspose\output\pdf_out_{0}.jpeg";
//XPS => PDF CONVERSION
using (System.IO.Stream pdfStream =
System.IO.File.Open(outputPdf, System.IO.FileMode.Create, System.IO.FileAccess.Write))
using (System.IO.Stream xpsStream = System.IO.File.Open(
inputFile, System.IO.FileMode.Open,
System.IO.FileAccess.Read))
{
var document = new XpsDocument(xpsStream, new XpsLoadOptions());
var options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions();
var device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream);
document.Save(device, options);
}
Document pdfDocument = new Document(outputPdf);
var pageEditor = new PdfPageEditor();
pageEditor.BindPdf(pdfDocument);
//EDITING PDF (ZOOM)
for (var i = 1; i < pdfDocument.Pages.Count; i++)
{
var page = pdfDocument.Pages[i];
pageEditor.ProcessPages = new[] { i };
pageEditor.Zoom = (float)0.9407069;
pageEditor.ApplyChanges();
}
pageEditor.Save(outputPdf);
//PDF => JPEG CONVERSION
pdfDocument = new Document(outputPdf);
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream =
new FileStream(string.Format(outputFiles, pageCount), FileMode.Create))
{
JpegDevice jpegDevice = new JpegDevice(new Resolution(300), 100);
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
imageStream.Close();
}
}
}
Source xps: source_xps.zip (1.2 MB)
PS: I know you can convert from XPS => JPEG directly, unfortunately this isn’t possible for our process.
Here’s what the missing image looks like side by side:
image.png (82.9 KB)