XML to tif conversion is not working

Hi, We have Aspose Total.net license and we are trying to convert XML to tif.
We used Aspose.pdf and Aspose.Tasks example mentioned on your portal but nothing is working.
with pdf below is the code and its giving a blank tif file.
Aspose.Pdf.Document document = new Aspose.Pdf.Document();
document.BindXml(fileDetail.FileInfo.FullName);
Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300);

        var settings = new Aspose.Pdf.Devices.TiffSettings()
        {
            Compression = Aspose.Pdf.Devices.CompressionType.LZW,
            Depth = Aspose.Pdf.Devices.ColorDepth.Format8bpp
        };
        
        Aspose.Pdf.Devices.TiffDevice tiffDevice = new Aspose.Pdf.Devices.TiffDevice(resolution, settings);
        tiffDevice.Process(document, fileDetail.OutputPath);

with Tasks
Its throwing an error of “The project format is undefined”
even in your portal you have used the same code.
Aspose.Tasks.Project project = new Aspose.Tasks.Project(fileDetail.FileInfo.FullName);
var options = new Aspose.Tasks.Saving.ImageSaveOptions(Aspose.Tasks.Saving.SaveFileFormat.TIFF);
options.HorizontalResolution = 300;
options.VerticalResolution = 300;
options.TiffCompression = Aspose.Tasks.Saving.TiffCompression.Lzw;
options.PixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
project.Save(fileDetail.OutputPath, options);

We need a quick solution how we can convert this.

@atyagi39,

Please ZIP and upload your source XML file that you are getting this problem with here for testing. We will then investigate the issue on our end and provide you more information.

Here is the attachment. 69610.zip (350 Bytes)

@atyagi39,

MS Word 2019 detects this XML file as Word 2003 XML Document; the following C# code of Aspose.Words for .NET API should be able to convert this XML to TIFF correctly.

Document doc = new Document("C:\\Temp\\69610\\69610.xml");
doc.Save(@"C:\Temp\\69610\\21.10.tiff");

But, currently it produces wrong output in TIFF image (see xml to tiff.zip (13.4 KB)). For the sake of any corrections in Aspose.Words API, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-22868. We will further look into the details of this problem and will keep you updated here on the status of correction. We apologize for any inconvenience.

How did you generate this XML file? What tool did you use to create such XML file. Because, when I opened this XML, MS Word 2019 displayed following warning message:

Moreover, this is not Aspose.Tasks issue. This API doesn’t accept any XML for loading. It accepts the XML files with valid MS Project structure file. Otherwise, an exception message will occur.

In You Example its mentioned that Aspose.tasks can do this task. Even They have example with Aspose.pdf.

I have not generated this file its a file from our database which we are trying to tiff.
So don’t know the source.

Also I need a solution where i need not to think what kind of xml file it is to decide shall i open it with Task,pdf or word. I need to know what is the best solution which can handle all type of xml files.

@atyagi39,

You can make use of FileFormatUtil.DetectFileFormat Method to detect if a particular XML file is suitable for Aspose.Words or not. Regarding Aspose.PDF, PdfFileInfo.IsPdfFile Property or Document.Check Method may be helpful but we are checking your queries further and will get back to you soon.

@atyagi39

In order to generate a PDF from XML template, the source XML template should follow the Aspose.PDF Schema. This way the API will be able to parse it and convert it into PDF. For more information, please check:

I think you guys are just writing some stories. Can you see what is my requirement and what you are writing. Show some professionalism please. I am asking converting a xml to tiff and I have provided the xml as well. I have seen your example xml and it looks same. So rather than telling me where is the problem in my xml you are giving me some special logics which is already mentioned in your website and i have read it.

@atyagi39

We apologize if any of our responses was irrelevant to the actual scenario. Please note that you cannot convert XML to TIFF directly using Aspose.PDF. You will be loading the XML file to create a PDF document and then converting it into TIFF (which you are already trying to achieve in your first post).

We have checked your XML file and it was not formed by following the Aspose.PDF XML Schema which was why the API was unable to process it and was generating blank output. Please note that you can generate a PDF (later TIFF) using both XML + XSLT OR single XML file. In the shared link of " Working with XML", examples to create PDF documents in both ways are given.

You can please check in the example of creating PDFs based on Aspose.PDF XML Schema that the source XML template is different than the one you provided us. You can change/modify it by following the guidelines given in the documentation and obtain valid output.

Please feel free to let us know in case you need more information.

Can you please point out which part is wrong in my xml. Also why everyother tool is able to open it in xml format. If any browser and tool is able to open it as a xml why not aspose fix this problem.

@atyagi39

Your XML does not follow the correct element sequence of supported schema. For example, please check the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
  <Page>
    <TextFragment>
      <TextSegment>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla odio lorem, luctus in lorem vitae, accumsan semper lectus. Cras a auctor leo, et tincidunt lacus.</TextSegment>
    </TextFragment>   
  </Page>
</Document>

Furthermore, can you please share an expected output TIFF for our reference that you want to obtain using the API? We will further proceed to assist you accordingly.

can you point out which sequence is wring by highlighting this xml. I can’t still see any problem in the xml.

@atyagi39

Your XML file contains tags like <Objekt><ObjektNoegleKode> which are not part of XML Schema supported by Aspose.PDF for .NET. Furthermore, as requested earlier, can you please share an expected output TIFF with us that you want to obtain from your XML? This would help us in having a clearer picture of your requirements.

So what is the problem in those tags. I am still not getting it how Aspose is fixed on tags. Tags could be any name in any language here tags are in danish. I am really surprised that you guys made this on specific tag names. very strange.
Can you stand on your own words earlier you have send me an example xml i could not found any issue in that. Now you are saying its not a part of schema. XML schema is totally different thing what you are explaining me here. If tags are aligned with each other than its a valid xml.
We all are developers here so don’t try to make false statements.
If you still say its not valid according to Aspose pdf schema please let me know what is your schema.

About my expectation of output if you go into this thread one of your guy made an attempt from Aspose.Word but its not correct and that’s why he has locked the ticket. I can’t not provide an output as I cant convert this to tiff and that’s why we bought your tool.

@atyagi39

It looks like there is some misunderstanding at our end about your actual requirements. Usually, we take XML to PDF (or any other format) Conversion in the sense that the user has an XML template where all formatting and content is defined e.g. Text, Margins, Tables, etc. For example, as a result of the above-shared XML template (which we have shared), a simple PDF with one page will be generated and it will contain the only text “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla odio lorem, luctus in lorem vitae, accumsan semper lectus. Cras a auctor leo, et tincidunt lacus.

This was why we have been suggesting you create a valid XML template that follows the Aspose.PDF XML Schema so that API would be able to generate PDF from it. Please note that BindXml() method is only used in such cases where provided XML file is based on supported XML Schema and contains valid XML tags and elements sequences.

In case you want to display XML as plain text in the PDF (please correct us if we are again mistaken), you do not need to use BindXml() method. Instead, you can read the XML file and create a TextFragment in the PDF. Later, the same document can be converted into TIFF like in the below code snippet:

var pdfDocument = new Aspose.Pdf.Document();
string xmlText = File.ReadAllText(dataDir + "69610.xml");
var page = pdfDocument.Pages.Add();
page.Paragraphs.Add(new TextFragment(xmlText));
pdfDocument.ProcessParagraphs();
Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300);
Aspose.Pdf.Devices.TiffSettings tiffSettings = new Aspose.Pdf.Devices.TiffSettings();
tiffSettings.Compression = Aspose.Pdf.Devices.CompressionType.LZW;
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format8bpp;
Aspose.Pdf.Devices.TiffDevice tiffDevice = new Aspose.Pdf.Devices.TiffDevice(resolution, tiffSettings);
tiffDevice.Process(pdfDocument, dataDir + "69610.xml.tif");

This misunderstanding happen because you are not reading users expectation and text about problem carefully.
BTW if I have 3 pages of text how it will fit in one page of pdf according to your code. As in your code you are adding only one page.

@atyagi39

If the content is longer to be fit on one page, the API will automatically add new pages to the document and content/text will be expanded over new pages. You only need to add one page in the start and add text into it.

Thanks a lot.