Hi,
Hi René,
Thanks for contacting support.
WorkZone:
We’re migrating from the obsolete Aspose.Pdf.Generator namespace to Aspose.Pdf. The main problem is that I could not find any dedicated documentation reference for this, so the the migration is being implemented intuitively.
We are working over documentation so that it can demonstrate complete functionality and required understanding of full feature of Aspose.Pdf for .NET DOM approach. We hope that you will find dedicated documentation on our website soon. Please spare us little time.
WorkZone:
Document.BindXml method is supposed to be used with xsl not with xslt.
Please note that the method Document.BindXml() can be used with XSLT as well. Please check following code snippet, in order to use it for XSLT.
Aspose.Pdf.Document doc = new Document();
doc.BindXml("inputXML.xml", "inputXSLT.xslt");
doc.Save(dataDir + "XMLtoPDF_out.pdf");
WorkZone:
But as for now, my only problem is how to get away from Aspose.Pdf.Generator.Pdf.BindFO method
In order to generate PDF from FO file, please check following code snippet which serves the purpose.
Aspose.Pdf.XslFoLoadOptions foToPdfLoadOptions = new Aspose.Pdf.XslFoLoadOptions();
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + “sampleFOFile.fo”, foToPdfLoadOptions);
// save result
string pdfOutputPath = dataDir + "FOTOPDF.pdf";
pdfDocument.Save(pdfOutputPath);
In case of any further assistance, please feel free to contact us. We are sorry for this inconvenience.
Best Regards,
Hi,
I’d like to share another problem I have, this time with image conversion (will get back with xsl fo later - still have problems with it as well).
So, when I convert a wmf image, the result on pdf gets its originally white background inverted to black. I’ve used Aspose.Pdf namespace for Document creation, and for adding the image I’ve tried two approaches, an old one we’ve used before - adding image directly to a page’s paragraph and the new approach like here:
//open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
pdfDocument.Pages.Add();
//set coordinates
int lowerLeftX = 100;
int lowerLeftY = 100;
int upperRightX = 200;
int upperRightY = 200;
//get the page where image needs to be added
Page page = pdfDocument.Pages[1];
//load image into stream
FileStream imageStream = new FileStream(“D:\pdftest\Penguin.PNG”, FileMode.Open);
//add image to Images collection of Page Resources
page.Resources.Images.Add(imageStream);
//using GSave operator: this operator saves current graphics state
page.Contents.Add(new Operator.GSave());
//create Rectangle and Matrix objects
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
//using ConcatenateMatrix operator: defines how image must be placed
page.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = page.Resources.Images[page.Resources.Images.Count];
//using Do operator: this operator draws image
page.Contents.Add(new Operator.Do(ximage.Name));
//using GRestore operator: this operator restores graphics state
page.Contents.Add(new Operator.GRestore());
//save updated document
pdfDocument.Save(“D:\pdftest\Image-In-PDF.pdf”);
Both of the approaches resulted in the wmf’s background color inversion.
As for the ImageFileType, I’ve also tried out both Unknown and SVG.
By the way, could you please clarify for me the usage of the ImageFileType? Under Aspose.Pdf.Generator this type used to have distinct values corresponding to all the supported image file types and now there’re just Unknown and Svg. Should I explicitly set Unknown for all the raster types and SVG for all the vector (including emf, wmf)?
The sample wmf is attached inside a zip file.
Thanks
As for the XSL FO,
our legacy approach was as simple as this:
var pdf = new Aspose.Pdf.Generator.Pdf();
pdf.BindFO(stream, new MemoryStream(TransformToClone));
// Save where stream is the file attached (Aspose.zip/Original.fo) and TransformToClone is
byte[] TransformToClone = Encoding.UTF8.GetBytes(
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<xsl:stylesheet xmlns:xsl="“http://www.w3.org/1999/XSL/Transform”" version="“1.0"”>
<xsl:output method="“xml”" encoding="“utf-8"” />
<xsl:template match=""@*|*"">
xsl:copy
<xsl:apply-templates select=""@*|node()"" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>");
The result looks like the attached Aspose.zip/LegacyResult.pdf.
Using the new approach I’ve tried the following
var foToPdfLoadOptions = new XslFoLoadOptions();
var pdfDocument = new Document(stream, foToPdfLoadOptions);
pdfDocument.BindXml(new MemoryStream(TransformToClone));
// Save The .fo file gets converted to pdf, but I fail to apply the TransformToClone for some reason (see the attached Aspose.zip/NewResult.pdf).
Hi René,
Thanks for sharing details with us.
WorkZone:
As for the ImageFileType, I’ve also tried out both Unknown and SVG.
By the way, could you please clarify for me the usage of the ImageFileType? Under Aspose.Pdf.Generator this type used to have distinct values corresponding to all the supported image file types and now there’re just Unknown and Svg. Should I explicitly set Unknown for all the raster types and SVG for all the vector (including emf, wmf)?
In order to convert an Image to PDF, you do not need to define image type in DOM. You can read image into a MemoryStream Object and then convert it into PDF like following code snippet. For more information please check “Convert an Image to PDF” article in API documentation.
Document doc = new Document();
Page page = doc.Pages.Add();
FileStream fs = new FileStream(dataDir + "wmftest.wmf", FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, int.Parse(fs.Length.ToString()));
MemoryStream mystream = new MemoryStream(tmpBytes);
Bitmap b = new Bitmap(mystream);
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);
// Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
page.Paragraphs.Add(image1);
image1.ImageStream = mystream;
dataDir = dataDir + "ImageToPDF_out.pdf";
doc.Save(dataDir);
mystream.Close();
I have tried to convert your shared image into PDF by using above code snippet and noticed that API threw an ArgumentException at save() method. For the sake of investigation, I have logged an issue as PDFNET-42805 in our issue tracking system. We will further look into the details of the issue and keep you posted on the status of its correction. Please be patient and spare us little time.
WorkZone:
So, when I convert a wmf image, the result on pdf gets its originally white background inverted to black
I could not replicate this issue at our side, as API threw an exception with the image file which you have shared. By looking into the code snippet that you have shared, it seems that you are using a PNG file for conversion. If so, then please share that file with us, so that we can try to reproduce the transparency issue in our environment and address it accordingly.
We are sorry for the inconvenience.
Best Regards,
hi, Asad,
Hi René,
WorkZone:
our legacy approach was as simple as this:var pdf = new Aspose.Pdf.Generator.Pdf();pdf.BindFO(stream, new MemoryStream(TransformToClone));// Savewhere stream is the file attached (Aspose.zip/Original.fo) and TransformToClone isbyte[] TransformToClone = Encoding.UTF8.GetBytes(@“<?xml version=""1.0"" encoding=""UTF-8""?><xsl:stylesheet xmlns:xsl=”“XSLT Namespace”" version=““1.0"”><xsl:output method=”“xml”" encoding=““utf-8"” /><xsl:template match=”“@|”“><xsl:apply-templates select=”“@*|node()”" /></xsl:copy></xsl:template></xsl:stylesheet>");The result looks like the attached Aspose.zip/LegacyResult.pdf.Using the new approach I’ve tried the followingvar foToPdfLoadOptions = new XslFoLoadOptions();var pdfDocument = new Document(stream, foToPdfLoadOptions);pdfDocument.BindXml(new MemoryStream(TransformToClone));// SaveThe .fo file gets converted to pdf, but I fail to apply the TransformToClone for some reason (see the attached Aspose.zip/NewResult.pdf)
Hi René,
WorkZone:
thanks for your reply, I’ll try the snippet. As for the png file from my example, it is just a copy-paste from one of the Aspose support threads. I’ve tried to use this approach in general for all the image types, as the thread mentioned that it was the recommended way to go instead of using Generator namespace.
Hi, Asad,
Hi René,
Hi, Asad,
as for the Imaging, the code snippet you’ve provided also throws an exception (“The parameter is invalid”) from within the Aspose internals. So, I’m still having color inversion problem with that particular wmf image I’ve attached. I’ve tried some other wmf-s with white/transparent background and there was no inversion with my new code. I’ll probably pass these changes to our testing team and see if it can deal with our typical tasks/images. But anyway, even if we assume that this particular wmf has some flaws in it, Aspose.Pdf.Generator approach still did convert it with no problems, so, I still suggest that Aspose needs to investigate it.
Another issue I’ve experienced with Aspose.Pdf.Image (as opposed to Aspose.Pdf.Generator.Image) is ImageScale property behavior. Setting this property on Aspose.Pdf.Image seems to be of no effect, the converted image (if bigger) just gets fitted onto the page with distortion. Now I have to explicitly set FixHeight and FixWidth properties to save the aspect ratio and get the same result as with Aspose.Pdf.Generator.Image, e.g.
(some pseudocode here)
var scaleRatio = CalculateScaleRatio();
image.FixHeight = [get real image height] * scaleRatio;
image.FixWidth = [get real image width] * scaleRatio;
WorkZone:
as for the Imaging, the code snippet you’ve provided also throws an exception (“The parameter is invalid”) from within the Aspose internals. So, I’m still having color inversion problem with that particular wmf image I’ve attached. I’ve tried some other wmf-s with white/transparent background and there was no inversion with my new code. I’ll probably pass these changes to our testing team and see if it can deal with our typical tasks/images. But anyway, even if we assume that this particular wmf has some flaws in it, Aspose.Pdf.Generator approach still did convert it with no problems, so, I still suggest that Aspose needs to investigate it.Hi René,Thanks for sharing the details.Can you please share the image file causing this problem so that we can test the scenario using new DOM approach. Also please share the code snippet which you are using (in case it is different form code shared earlier in this thread).In order to set the image dimensions, you need to specify the Width and Height information. You may consider getting page dimensions and set same dimensions for image being placed inside the document.WorkZone:
Another issue I’ve experienced with Aspose.Pdf.Image (as opposed to Aspose.Pdf.Generator.Image) is ImageScale property behavior. Setting this property on Aspose.Pdf.Image seems to be of no effect, the converted image (if bigger) just gets fitted onto the page with distortion. Now I have to explicitly set FixHeight and FixWidth properties to save the aspect ratio and get the same result as with Aspose.Pdf.Generator.Image, e.g.(some pseudocode here)var scaleRatio = CalculateScaleRatio();image.FixHeight = [get real image height] * scaleRatio;image.FixWidth = [get real image width] * scaleRatio;
Hi,
Hi René,
Hi Asad,
Any new regarding the XSL FO issue?
The ticket was initially logged May 28, so…
Best regards,
Thanks for your inquiry.
I am afraid that earlier logged issue(s) have not been yet resolved, due to large number of pending issues in the queue, logged previously. However we have shared your concerns with respective team and as soon as we get some feedback from their side, we will let you know. Please be patient and spare us little time.
We are sorry for the inconvenience.