Is there a way to display negative numbers in PDF template using aspose

Is there a way to display negative numbers in PDF template on aspose pdf version 16.1.10.

I have attached a sample code of generating template pdf using .xml file as input:

public void generatePDF(String xmlFile, String rtfFile, String pdfName) {
        new RTFGeneratorHelper().setAsposeLicense();
        InputStream rtfStream = null;
        InputStream xmlStream = null;
        DataSet ds = null;
        try {
            File file = new File(rtfFile);
            if (file.exists()) {
                rtfStream = new FileInputStream(file);
                com.aspose.words.Document doc = new com.aspose.words.Document(rtfStream);           
                String fontFolder = System.getProperty("FONT_FOLDER");
                if(fontFolder != null){                	
                    FontSettings fs = FontSettings.getDefaultInstance();
                    fs.setFontsFolder(fontFolder, false);                    
                    doc.setFontSettings(fs);                    
                }
                String localeCode= (String) RequestContext.getObject(RequestContext.LOCALE_ID);
        		if(null != localeCode && localeCode.equals("zh_CN"))
        		{        			
        			FontSettings fs = FontSettings.getDefaultInstance();
        			 URL url = getClass().getClassLoader().getResource("fonts");
                    fs.setFontsFolder(url.toURI().getPath(), false);
                    fs.setDefaultFontName(arialUnicodeFont);
                    doc.setFontSettings(fs);
        		}               
                ds = new DataSet();              
                ds.readXml(xmlFile);
                doc.getMailMerge().setUseNonMergeFields(true);
                doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
                doc.getMailMerge().executeWithRegions(ds);
                doc.updateFields();                
			   doc.save(pdfName, com.aspose.words.SaveFormat.PDF);
               }
            }
		catch (Exception e) {
        	logger.error("Error in generatePDF()");
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        } 
}

@prudhviyadav Could you please attach your input document, sample XML data, the current and expected output documents? This will help us to better understand your requirements. We will check your documents and provide you more information.

Hi Alexey,

Please find the attached xml file, current output and expected output example.

template pdf.zip (28.5 KB)

@prudhviyadav You shoudl specify the following number format in the template to get the expected output \# "#;(#)". For example see the following simple code, template and output documents:

DataTable data = new DataTable("Data");
data.Columns.Add("test");
data.Rows.Add(10);
data.Rows.Add(-10);
data.Rows.Add(20);
data.Rows.Add(-20);

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.ExecuteWithRegions(data);
doc.Save(@"C:\Temp\out.docx");
doc.Save(@"C:\Temp\out.pdf");

in.docx (12.7 KB)
out.docx (9.9 KB)
out.pdf (14.1 KB)

Alexey,

Thank you for the inputs.

Could you please provide sample logic for generate rtf file with applying negative number format.

We are trying to generate rtf template which can display negative numbers format (the negative numbers in colors and brackets as per the images provided in previous comment pointing the expectation) using com.aspose.words.Document, even for generation we are using aspose.
test template rtf.docx (26.0 KB)

@prudhviyadav You should specify number format like this

{{MSG1 \# "#;(#)"}}

Alexey,

Thank you, but we are also looking to have the negative numbers in selected colour/color along with the brackets

@prudhviyadav In this case I can only suggest to use IF field and use different formatting in the true and false values. For example see the attached template, code and output documents:

DataTable data = new DataTable("Data");
data.Columns.Add("test");
data.Rows.Add(10);
data.Rows.Add(-10);
data.Rows.Add(20);
data.Rows.Add(-20);

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields;
doc.MailMerge.ExecuteWithRegions(data);
doc.Save(@"C:\Temp\out.docx");
doc.Save(@"C:\Temp\out.pdf");

in.docx (12.9 KB)
out.docx (10.0 KB)
out.pdf (24.2 KB)

Press Alt+F9 to see field codes in the template.