We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Does aspose pdf support xsl-fo to PDF conversion in the stream level? (.net)

My bussiness requirement is I need to convert the incoming xsl-fo stream that is created by XslCompiledTransform to PDF stream. Is this possible with ASPOSE? I did a quick search here and the examples I have found are only converting an physical xml to a PDF.

@frostless

You can use XSL-FO streams as well in order to create PDF document from it. e.g.:

Document pdfDocument = new Document(XMLstream, new XslFoLoadOptions());
pdfDocument.Save(dataDir + @"output.pdf");

In case you face any issue, please feel free to let us know.

I get this error “Root element is missing”
When I init the DocumentDocument pdfDocument = new Document(XMLstream, new XslFoLoadOptions());
Here XMLstream is the stream generated by XslCompiledTransform using the incoming XmlDocument and predefined XSL file


I think I managed to fix the above issue by setting the position of Stream to 0: fo.Seek(0, SeekOrigin.Begin) where fo is the xsl-fo stream

But now I got new issues when init the pdfDocument

  Message=Exception occured during import of source Xslfo. 
Exception's message is : 'Unable to cast object of type '#=zd3oYr34zuFbx0fhzYSOxRgoRR9o9LXooN0fai7Y=' to type '#=zHaaQ1pb6WcLCy5ipKhYdVSRLvG42RCN4JQ=='.' .\r\n  Since in conversion's options selected mode of ignoring validation errors,  and such errors was detected, this exception can be result of that bad formatting. Here is list of found formatting errors : ============================================
Invalid property value encountered in page-width=""[: #=z21oQMZ$DnIgFP_VlT_UUZMc=: No conversion defined 
   at #=zOdaj7bVSY0DjW3t5l44bsNgKAKpO.#=zKkpxotI=(#=zo1Yn4FFOUPCuAvh7Bg== #=zMuOVl9o=, String #=zgRwocA0=, #=zCnNZMVKacFlRz0mJDc8VfRc= #=z2LppkwA=)
   at #=zo1Yn4FFOUPCuAvh7Bg==.#=zqQ6_NM8fGQOU(#=zozZcbjX8htrMEcfb1ovc9bM= #=zRW5ruOs=, String #=zxPi8mM0=, String #=zU75guvM=)] Line(1)\Col(284)---------------------------------
Invalid property value encountered in page-height=""[: #=z21oQMZ$DnIgFP_VlT_UUZMc=: No conversion defined 
   at #=zOdaj7bVSY0DjW3t5l44bsNgKAKpO.#=zKkpxotI=(#=zo1Yn4FFOUPCuAvh7Bg== #=zMuOVl9o=, String #=zgRwocA0=, #=zCnNZMVKacFlRz0mJDc8VfRc= #=z2LppkwA=)
   at #=zo1Yn4FFOUPCuAvh7Bg==.#=zqQ6_NM8fGQOU(#=zozZcbjX8htrMEcfb1ovc9bM= #=zRW5ruOs=, String #=zxPi8mM0=, String #=zU75guvM=)] Line(1)\Col(284)---------------------------------
"fo:page-sequence" is not a valid child of "fo:simple-page-master"![ ] Line(1)\Col(730)============================================'

Does it mean my xsl is not compliant with ASPOSE? It is possible becasue the xsl was written catering for another PDF engine.

I bypassed the error by hardcoding a minimum amount of xsl-fo that is compliant with ASPOSE.

@frostless

Yes, your understandings are correct. The XSL should be Aspose.PDF Compliant in order to generate correct output.

It is good to know that you were able to generate PDF using XSL-FO. Please keep using our API and in case you face any issue, please feel free to let us know.

I am still getting lots of errors when I try to expand my working minimum xsl-fo. And none of the errors are readable to me. How do I analyse errors like this and where can I get the instructions on writing ASPOSE compliant xsl??

Attached is the problematic xsl-fo (extention name changed to pdf since xml is not acceptabletest1.pdf (80.8 KB)
)

Error Message: Object reference not set to an instance of an object.
Stack Trace:   at #=zmK6qJXZGoanSev$6YbR4WC8=..ctor(#=zd3oYr34zuFbx0fhzYSOxRgoRR9o9LXooN0fai7Y= #=z1zHEVkg=, Int32 #=zZtqMTYxuiuof, String #=zsbwBHwPGlSuz, Boolean #=zoKywWkfxhGWw, Boolean #=zYo_yLO4RZe_B)
   at #=z2tpCc4hf09kNUBH3uIJEGjCXN7Za..ctor(#=zd3oYr34zuFbx0fhzYSOxRgoRR9o9LXooN0fai7Y= #=z1zHEVkg=, Int32 #=zZtqMTYxuiuof, String #=zHnLlcL0T0H5X, Boolean #=zoKywWkfxhGWw, Boolean #=zYo_yLO4RZe_B)
   at #=z_u5W$X$K6Zs72Nehse0ujDMznapO.#=zkzt4getfoog7(Int32 #=znhoR45Y=, Boolean #=zIEir4f4=, Boolean #=zFrZDjbZngYL_, Boolean #=zYo_yLO4RZe_B)
   at #=z_u5W$X$K6Zs72Nehse0ujDMznapO.#=zSR3TY9s=(Boolean #=zIEir4f4=, Int32 #=znhoR45Y=)
   at #=zvf0vCoZeb_PK_8ojsdODXddoW1RvulH2mw==.#=zlifs8y8=(Int32 #=zZtqMTYxuiuof, Boolean #=zIEir4f4=)
   at #=zmaYKpqDf_C13XtEz$TrIjwiz3lxy_dEaR$4mz3U=.#=zk4QNiHCaIV9b(Boolean #=zIEir4f4=)
   at #=zvf0vCoZeb_PK_8ojsdODXddoW1RvulH2mw==.#=zk4QNiHCaIV9b(Boolean #=zIEir4f4=)
   at #=zvf0vCoZeb_PK_8ojsdODXddoW1RvulH2mw==.#=zVolKj5$ODxnq()
   at #=zowqgTFQlmDlmwGSQC_w8LRE=.#=zxyesTO9cNjQG(#=z4NpCaJftjha00seW6hZKFUXbFFH1avtsGA== #=ztApTthsuWSj1)
   at #=z3z$4tS_w3tSL6OkgwEN66uE=.#=zgJMr_B$5u8u2.#=ze7vhjA0=(String #=zZyv4g$I=, String #=zdwxK8HU=, String #=z5j58Rh4=)
   at #=z3z$4tS_w3tSL6OkgwEN66uE=.#=ze7vhjA0=(String #=zZyv4g$I=, String #=zdwxK8HU=, String #=z5j58Rh4=)
   at #=zvR29fcci1pPV44uZRQZ5mmg=.#=z5W7l9qM=(XmlTextReader #=zHDlsFz0=)
   at #=zvR29fcci1pPV44uZRQZ5mmg=.#=z5W7l9qM=(Stream #=zrNsy2mc=)
   at #=z_Tdjxkl_8Wj5F_4U9dmmfOc=.#=zO4hYpsY=(Stream #=zPTRy0vU=, #=zDDxWaNvzX216mzFBFNjVff4= #=z$0FxaJo=)
   at #=zp_froJGP93HPIlmXtfJTn0rOWIF2T4SX1Q==.#=zO4hYpsY=(Document #=za9q6HOo=, Stream #=zB7KCooFm3FcA, XslFoLoadOptions #=zZsA365UodbSI)

@frostless

Please visit Working with XML for your kind reference and feel free to contact us if you still face any issue.

Thanks for the information. Is there a way to better understand the error message though? I find the link you gave is a bit too general and it does not really help me to modify my xsl quickly. It would be really good if I can extract information from the errors on which specific part of my xml is not compliant, so I can quickly change the xsl and test bit by bit.

@frostless

Would you kindly share the file extension that you have shared with us in your earlier response. Is it .fo or .xsl? We are trying to test the scenario by changing the extension from .pdf to .fo but it is not working and we are not getting the exception that you have shared.

I think I figure out the reason, when I manually modified the xsl-fo to be Aspose compliant I omit <fo:simple-page-master master-name="body-pages-portrait" > after add it back it is loaded good.


Actually the file attached previously was wrong, please use this newly attached one.
xspose for all new.pdf (2.1 MB)

If the full version is too bog, here is the mini version:(I guess they share the same problem not 100% sure though)min version.pdf (69.2 KB)


It is xml file, but in my case the extention does not really matter.
What I did was I copied the content in the file into my app as a C# string, and then I converted it to MemeoryStream

string inputXML = [this is the content from the uploaded file]
byte[] byteArray = Encoding.UTF8.GetBytes(inputXML);
fo = new MemoryStream(byteArray);

Finally I used APOSE API to do the XSL-FO to PDF conversion

fo.Seek(0, SeekOrigin.Begin);
Document pdfDocument = new Document(fo, new XslFoLoadOptions());
pdfDocument.Save(pdf, SaveFormat.Pdf);

I still got two questions:
1: How to add attachments in the xsl-fo level?
2: How to add bookmark in the xsl-fo level?
I looked at this https://docs.aspose.com/display/pdfnet/Working+with+XML but it is about adding attachments and bookmarks in the Aspose object. We want to be able to achive this by modifying the xml file.

@frostless

Thanks for elaborating further.

We have logged an issue as PDFNET-47310 in our issue tracking system after replicating it in our environment. We will definitely look into details of your XML and keep you posted with the status of issue investigation and resolution.

An investigation ticket as PDFNET-47311 has been logged in our issue management system against your above requirements. We will also investigate feasibilty of these requirements and let you know as soon as the ticket is resolved. Please be patient and spare us little time.

We are sorry for the inconvenience.

For bookmark, I was looking for something like

<fo:bookmark-tree> <fo:bookmark internal-destination="ID0ECAAAA"> <fo:bookmark-title>account cost</fo:bookmark-title> </fo:bookmark> </fo:bookmark-tree>

For attachment,

<fo:declarations
    xmlns:altsoft="http://alt-soft.com/xml2pdf/extensions">
    <altsoft:attachment src="c:\temp\2.text" name="123.pdf" description="Document Attachment" />
    <altsoft:attachment src="c:\temp\1.text" name="test.pdf" description="Document Attachment" />
</fo:declarations>

That I can easily define in the xsl-fo code.

Actually I have already managed to resolved this issue PDFNET-47310 . It was because <fo:simple-page-master master-name="body-pages-portrait" > is missing. So maybe we can focus on PDFNET-47311

@frostless

Thanks for your feedback.

Sure, we have updated the tickets information and will surely let you know as soon as some updates are available.