Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to dynamically hide columns in pdf export
Bibins
<p>Hi,</p>
<p> </p>
<p>The report has about 60+ columns and the export in pdf output is cluttered as its trying to fit in all the 60+ columns into A4 size. The layout selected in Master page is Auto.</p>
<p>Would like to restrict the pdf output such that only the columns that can be fitted in A4 is displayed correctly.</p>
<p>Have tried the hide element property in Visibility option but this does not work as the output columns dynamically changes based on user selection. Report is being developed using BIRT API and scripting so would like to know whether there is any way to control the columns being exported in pdf like if column count is greater than 10 or 12 dont export. Please help out.</p>
<p> </p>
<p>Regards,</p>
<p>Bibins</p>
Find more posts tagged with
Comments
Clement Wong
<p>You can do this easily via the DEAPI. I'm not sure how you are creating the report via API, but you should be able to implement the same code that I have in the beforeFactory in the attached example, either as part of your code, or as part of the report's beforeFactory.</p>
<pre class="_prettyXprint">
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);
th = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("mytable");
if (th.getColumns().getCount() > 2) {
for ( var i = 2; i < th.getColumns().getCount(); i++ ) {
ch = th.getColumns().get(i);
hr = StructureFactory.createHideRule();
hr.setFormat("pdf");
hr.setExpression("true");
ph = ch.getPropertyHandle("visibility");
ph.addItem(hr);
}
}
</pre>
Bibins
<p>Thank you Clement.</p>
<p> </p>
<p>It worked now I am able to control the number of columns exported to pdf.</p>
<p> </p>
<p>Wanted to check with you whether its possible to control for both pdf and docx format.</p>
<p> </p>
<p>When I tried only either one of them is working.</p>
<p> </p>
<p>Regards,</p>
<p>Bibins</p>
Clement Wong
<p>Bibins,</p>
<p> </p>
<p>This worked for me.</p>
<pre class="_prettyXprint">
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);
th = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("myTable");
if (th.getColumns().getCount() > 2) {
for ( var i = 2; i < th.getColumns().getCount(); i++ ) {
ch = th.getColumns().get(i);
hr = StructureFactory.createHideRule();
hr.setFormat("pdf");
hr.setExpression("true");
ph = ch.getPropertyHandle("visibility");
ph.addItem(hr);
hr2 = StructureFactory.createHideRule();
hr2.setFormat("docx");
hr2.setExpression("true");
ph.addItem(hr2);
}
}</pre>