We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

XPS to PDF conversion loosing image size

Hi,
I am using the XPS to PDF conversion, the header image looks fine in WPF as well as looking at the xps document seperately. Once the PDF conversion is done it loses it's scaling. and is cropped at the image (scale size) edges.

Any ideas how to fix this?

4 Replies

SL Sowmiya Loganathan Syncfusion Team January 28, 2020 11:55 AM UTC

Hi Damien, 

Thank you for contacting Syncfusion.  

We have tried to reproduce the reported issue “Scaling and cropping issue while converting XPS to PDF”, but we regret to let you know that we were unable to reproduce it. Could you please share us the below details to replicate the issue, it will helpful for us to provide the precise solution on this.  

  • Input XPS file
  • Complete code snippet or sample
  • Product version
  • Environment details like OS, Display scaling and resolution
  • Issue details with screenshot

Regards, 
Sowmiya Loganathan 



DH Damien Holley February 9, 2020 10:55 PM UTC

Hi Sowmiya,
OS: Win10
Display: 2k monitors + 125%
SF Version : 17.2460.0.46

The file views, please note that the image in the pdf file appears like it's being cropped to the total space of the logo in the xaml file:
XPS FILE
PDF File



The main part of the code, tempFile is the path to the temporary XPS file:
                              //GET XAML file as XPS
var p = printFrame as FixedPage;
pageFrame.Child = null;

if (p == null) {
throw new Exception("Page is null."); }
var xpsFile = GetXPSDocumentAsStream(p, ref tempFile);

if (xpsFile != null) {
xpsFile.Position = 0;
//writeXPSToFile(ref xpsFile, filePath);

Syncfusion.XPS.XPSToPdfConverter converter = new Syncfusion.XPS.XPSToPdfConverter();
PdfDocument doc = converter.Convert(tempFile);
//doc.PageSettings.Size = PdfPageSize.A4;
//doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
doc.Save(filePath);

//open PDF file
System.Diagnostics.Process.Start(filePath);

doc.Close(); }

The part that saves the pdf:
                         try {
MemoryStream output = new MemoryStream();
var doc = new FixedDocument();
var pContent = new PageContent();
content.Width = 2000;
content.Height = 2900;

((System.Windows.Markup.IAddChild)pContent).AddChild(content);

doc.Pages.Add(pContent);

if (overdue) {
pContent = new PageContent();
var temp = new FixedPage();
temp.Width = 2000;
temp.Height = 2900;

temp.Children.Add(new OverdueDetails());
((System.Windows.Markup.IAddChild)pContent).AddChild(temp);
doc.Pages.Add(pContent); }

//var xDoc = new XpsDocument(System.IO.Packaging.Package.Open(output, FileMode.Create, FileAccess.ReadWrite));
var xDoc = new XpsDocument(tempFile, FileAccess.ReadWrite, System.IO.Packaging.CompressionOption.NotCompressed);
var xpsWriter = XpsDocument.CreateXpsDocumentWriter(xDoc);

//write out doc
xpsWriter.Write(doc);
xDoc.Close();

return output; }

catch(Exception ex) {
gfuncs.ERROR(ref ex, "GetXPSDocumentAsStream", "PrintSavePDF");
return null; }

Attachment: sample_files_d0775bdc.rar


SL Sowmiya Loganathan Syncfusion Team February 10, 2020 11:28 AM UTC

Hi Damien,  

Thank you for the details.  

We were able to reproduce the reported issue “Images are cropped while convert XPS to PDF” with scaling 125% in the product version 17.2.0.46. However, this issue has been resolved in our main release (17.4.0.39) and latest product version 17.4.0.47 (NuGet version). So kindly use the latest version to overcome this issue.  

Please let us know if you have any concerns on this.  

Regards, 
Sowmiya Loganathan 



DH Damien Holley February 12, 2020 11:29 PM UTC

Worked immediately, thank you very much!

Loader.
Live Chat Icon For mobile
Up arrow icon