Jump to content
We've recently updated our Privacy Statement, available here ×

Text not wrapping in pdf


Recommended Posts

By: Enrico Goosen - enricogoosen

Text not wrapping in pdf

2003-05-13 02:55

Hi,

 

When I output my report in PDF, the text doesn't wrap...it just gets cut off.

Anything I can do about this?

It wraps in HTML output.

ALSO

I have strings with "n" characters to display it on a new line within a static text element. It works fine in HTML, but in PDF it only displays the first string...everything after the "n" character is getting left out.

Any ideas?

 

Enrico

 

 

 

 

By: Gregory A. Swarthout - gswarthout

RE: Text not wrapping in pdf

2003-05-13 08:12

This sounds like maybe the fonts are different between the PDF and the HTML with the PDF fonts being a bit bigger and so there isn't room to show the additional line(s) of text. Try increasing the band height or decreasing the PDF font size.

 

 

 

 

By: Enrico Goosen - enricogoosen

RE: Text not wrapping in pdf

2003-05-14 03:56

I don't think the size of fonts should make a difference, cos I could use a really small font, but if the text reaches past the end of the column it will just get chopped off.

Here's my code:

JasperDesign jasperDesign = new JasperDesign();

jasperDesign.setName("SubReportDesign"+cnt);

jasperDesign.setPageWidth(842);

jasperDesign.setPageHeight(595);

jasperDesign.setColumnWidth(802);

jasperDesign.setColumnSpacing(0);

jasperDesign.setLeftMargin(0);

jasperDesign.setRightMargin(0);

jasperDesign.setTopMargin(20);

jasperDesign.setBottomMargin(0);

jasperDesign.setWhenNoDataType(JasperDesign.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL);

 

//Fonts

JRDesignReportFont normalFont = new JRDesignReportFont();

normalFont.setName("Arial_Normal");

normalFont.setDefault(true);

normalFont.setFontName("Arial");

normalFont.setSize(12);

normalFont.setPdfFontName("Helvetica");

normalFont.setPdfEncoding("Cp1252");

normalFont.setPdfEmbedded(false);

jasperDesign.addFont(normalFont);

 

JRDesignReportFont boldFont = new JRDesignReportFont();

boldFont.setName("Arial_Bold");

boldFont.setDefault(false);

boldFont.setFontName("Arial");

boldFont.setSize(12);

boldFont.setBold(true);

boldFont.setPdfFontName("Helvetica-Bold");

boldFont.setPdfEncoding("Cp1252");

boldFont.setPdfEmbedded(false);

jasperDesign.addFont(boldFont);

 

JRDesignReportFont italicFont = new JRDesignReportFont();

italicFont.setName("Arial_Italic");

italicFont.setDefault(false);

italicFont.setFontName("Arial");

italicFont.setSize(12);

italicFont.setItalic(true);

italicFont.setPdfFontName("Helvetica-Oblique");

italicFont.setPdfEncoding("Cp1252");

italicFont.setPdfEmbedded(false);

jasperDesign.addFont(italicFont);

 

//Page Header

JRDesignBand band = new JRDesignBand();

band.setHeight(40);

 

int x = 0;

int y = 5;

int pageWidth = 802;

int questionColumnWidth = 250;

int answerColumnWidth = 552;

int columnHeight = 15;

 

JRDesignRectangle rectangle = new JRDesignRectangle();

rectangle.setX(x);

rectangle.setY(y);

rectangle.setWidth(pageWidth);

rectangle.setHeight(columnHeight);

rectangle.setForecolor(new Color(102, 102, 153));

rectangle.setBackcolor(new Color(102, 102, 153));

rectangle.setStretchType(JRDesignRectangle.STRETCH_TYPE_NO_STRETCH);

band.addElement(rectangle);

 

JRDesignStaticText staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y);

staticText.setWidth(questionColumnWidth);

staticText.setHeight(columnHeight);

staticText.setForecolor(new Color(255, 255, 255));

staticText.setBackcolor(new Color(102, 102, 153));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(boldFont);

staticText.setText(cnt+". "+"Question");

band.addElement(staticText);

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y+20);

staticText.setWidth(questionColumnWidth);

staticText.setHeight(columnHeight);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(normalFont);

staticText.setText(question.getQuestionText());

band.addElement(staticText);

 

Map detailDataMap = (Map)parameters.get(EvaluationReportRenderer.REPORT_DETAIL_DATA);

Map answers = (Map)detailDataMap.get(question);

int columns = answers.size();

int columnSize = answerColumnWidth / columns;

x = 250;

int totalReportUsers = ((Integer)parameters.get("reportUserTotal")).intValue();

if (question instanceof OPQuestion){

for (Iterator i2 = answers.keySet().iterator(); i2.hasNext(); ){

PossibleAnswer pa = (PossibleAnswer)i2.next();

int val = ((Integer)answers.get(pa)).intValue();

double percentage = ((double)val / (double)totalReportUsers);

String pcnt = NumberFormat.getPercentInstance().format(percentage);

String value = val+" = "+pcnt;

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y);

staticText.setWidth(columnSize);

staticText.setHeight(columnHeight);

staticText.setForecolor(new Color(255, 255, 255));

staticText.setBackcolor(new Color(102, 102, 153));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(boldFont);

staticText.setText(pa.getAnswerText());

band.addElement(staticText);

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y+20);

staticText.setWidth(columnSize);

staticText.setHeight(columnHeight);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(normalFont);

staticText.setText(value);

band.addElement(staticText);

 

x+=columnSize;

 

}

}else if (question instanceof TFQuestion){

for (Iterator i2 = answers.keySet().iterator(); i2.hasNext(); ){

String answer = (String)i2.next();

int val = ((Integer)answers.get(answer)).intValue();

double percentage = ((double)val / (double)totalReportUsers);

String pcnt = NumberFormat.getPercentInstance().format(percentage);

String value = val+" = "+pcnt;

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y);

staticText.setWidth(columnSize);

staticText.setHeight(columnHeight);

staticText.setForecolor(new Color(255, 255, 255));

staticText.setBackcolor(new Color(102, 102, 153));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(boldFont);

staticText.setText(answer);

band.addElement(staticText);

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y+20);

staticText.setWidth(columnSize);

staticText.setHeight(columnHeight);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(normalFont);

staticText.setText(value);

band.addElement(staticText);

 

x+=columnSize;

 

}

}else if (question instanceof FTQuestion){

for (Iterator i2 = answers.keySet().iterator(); i2.hasNext(); ){

String key = (String)i2.next();

String val = (String)answers.get(key);

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y);

staticText.setWidth(columnSize);

staticText.setHeight(columnHeight);

staticText.setForecolor(new Color(255, 255, 255));

staticText.setBackcolor(new Color(102, 102, 153));

staticText.setMode(JRElement.MODE_OPAQUE);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(boldFont);

staticText.setText(key);

band.addElement(staticText);

 

staticText = new JRDesignStaticText();

staticText.setX(x);

staticText.setY(y+20);

staticText.setWidth(columnSize);

staticText.setHeight(columnHeight);

staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);

staticText.setFont(normalFont);

staticText.setText(val);

band.addElement(staticText);

 

x+=columnSize;

 

}

}

jasperDesign.setPageHeader(band);

 

//Column header

band = new JRDesignBand();

jasperDesign.setColumnHeader(band);

 

//Detail

band = new JRDesignBand();

jasperDesign.setDetail(band);

 

//Column footer

band = new JRDesignBand();

jasperDesign.setColumnFooter(band);

 

//Page footer

band = new JRDesignBand();

jasperDesign.setPageFooter(band);

 

//Summary

band = new JRDesignBand();

jasperDesign.setSummary(band);

 

Am I missing anything?

 

 

 

 

By: Teodor Danciu - teodord

RE: Text not wrapping in pdf

2003-05-14 04:11

 

Hi,

 

You are using static text elements to display

content that in fact is not static. Every time

the text changes inside those "static text"

elements that you have.

 

And the problem is that a static text element

never adapts its size so that the content fits inside.

This is because they should always display

the same thing and the designer should provide

the correct element size at design time.

 

But I think in your case you need to use

<textField> elements, and use isStretchWithOverflow="true" for them, so that

if the content is larger, they adapt their size to it.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...