RadaeePDF.com :: Topic: How to add PageContent text gravity ? (1/1)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF

TOPIC: How to add PageContent text gravity ?

How to add PageContent text gravity ? 1 month 1 week ago #12776

  • Tele
  • Tele's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
  • Karma: 0
rsz_1rsz_screenshot_from_2017-08-19_18-42-22.png



I have added a long text in pdf using PageContent class but it's displaying single line and also not displaying complete text. Can you please suggest to set gravity for PageContent ?
Last Edit: 1 month 1 week ago by Tele. Reason: Added desired screenshot
The administrator has disabled public write access.

How to add PageContent text gravity ? 1 month 1 week ago #12778

  • Davide
  • Davide's Avatar
  • OFFLINE
  • Moderator
  • Posts: 680
  • Thank you received: 47
  • Karma: 14
Hi,
to change line you can add "\r" into your text as you can see in the demo activity PDFTestAct.
Please check this class to see some useful methods regarding PageContent.

If this is not what you wanted, can you please send us your code so we can check it?
The administrator has disabled public write access.
The following user(s) said Thank You: Tele

How to add PageContent text gravity ? 1 month 1 week ago #12779

  • Tele
  • Tele's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
  • Karma: 0
Thanks for reply!
Could you please check the updated post once, I have added a desired screenshot as per requirement in that
1. Using "PageContent" class I want to add header like in added screenshot(pink color text) which is horizontally centered text to pdf page , Is there any suggestions for this ?
2. Using "PageContent" class I want to add underline for header like in added screenshot(pink color text), Any suggestions ?
3. Is we have any alternate classes/methods for adding content like this ?
Last Edit: 1 month 5 days ago by Tele.
The administrator has disabled public write access.

How to add PageContent text gravity ? 1 month 5 days ago #12781

  • Tele
  • Tele's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
  • Karma: 0
Here is my code to add header
                                        PageContent content = new PageContent();
					content.Create();
					content.GSSave();
					Matrix mat = new Matrix(1, 1,10, 730);
					content.GSSetMatrix(mat);
					mat.Destroy();
					DocFont dfont = m_doc.NewFontCID("Helvetica Bold", 1);
					ResFont rfont = page.AddResFont(dfont);
					content.TextBegin();
					content.TextSetFont(rfont, 25);// set font and
					content.TextSetCharSpace(1f);
					content.TextSetWordSpace(0.2f);
					content.TextSetLeading(16);
					content.TextSetRenderMode(0);
					//SpannableString content11 = new SpannableString(Txt_roomate);
					//content11.setSpan(new UnderlineSpan(), 0, content11.length(), 0);				
					content.DrawText("Centered and Underlined Text");
					content.SetFillColor(Color.parseColor(Global.pdf_general_text_color));
					content.SetStrokeColor(Color.parseColor(Global.pdf_general_text_color));
					content.TextEnd();
					content.GSRestore();
					page.AddContent(content, true);
					content.Destroy();
@Davide : Any suggestions ?
Last Edit: 1 month 5 days ago by Tele.
The administrator has disabled public write access.

How to add PageContent text gravity ? 1 month 5 days ago #12787

  • Tele
  • Tele's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
  • Karma: 0
Tele wrote:
Thanks for reply!
Could you please check the updated post once, I have added a desired screenshot as per requirement in that
1. Using "PageContent" class I want to add header like in added screenshot(pink color text) which is horizontally centered text to pdf page , Is there any suggestions for this ?
2. Using "PageContent" class I want to add underline for header like in added screenshot(pink color text), Any suggestions ?
3. Is we have any alternate classes/methods for adding content like this ?

Did you get a chance to check my issue once ?
Last Edit: 1 month 4 days ago by Tele.
The administrator has disabled public write access.

How to add PageContent text gravity ? 1 month 4 days ago #12788

  • Davide
  • Davide's Avatar
  • OFFLINE
  • Moderator
  • Posts: 680
  • Thank you received: 47
  • Karma: 14
Hi,
with the following code you will add a pink underlined and horizontally centered text to your pdf.
There is no way to direclty underline the text, so we created the text and then we underlined it with a line.
The only way to add text, line, image, form, grid.. etc to the pdf is through PageContent.
Page page = m_doc.NewPage(pageno, w, h);//create A4 paper

        PageContent content = new PageContent();
		content.Create();//create content, do not forget.

		//set alpha for both fill and stroke
		DocGState dgs = m_doc.NewGState();
		dgs.SetFillAlpha(255);//set alpha value to 0.5
		dgs.SetStrokeAlpha(255);//set alpha value to 0.5
		ResGState rgs = page.AddResGState(dgs);
		content.GSSet(rgs);

		//prepare to write texts
		content.GSSave();

		int style = 1;
		DocFont dfont = m_doc.NewFontCID("DroidSansFallback", style);//bold-italic and embed in horizontal writing
        if(dfont == null)
        {
            dfont = m_doc.NewFontCID("Roboto-Regular", style);
            if(dfont == null)
                dfont = m_doc.NewFontCID("DroidSans", style);
        }
		ResFont rfont = page.AddResFont(dfont);

        //center text
        String text = "Pink text!";
        float[] size = content.TextGetSize(rfont, text, 22, 22,0, 0.2f);
        content.GSSave();
        Matrix mat = new Matrix( 1, 1, (w-size[0])/2, 777 );
        content.GSSetMatrix(mat);
        mat.Destroy();

		content.TextBegin();
		content.TextSetFont(rfont, 22);//set font and size
		content.SetFillColor(0xff69b4);//set fill color to black-green.
		content.TextSetCharSpace(0);
		content.TextSetWordSpace(0.2f);
		/*content.TextSetLeading(16);
		content.TextSetRenderMode(0);//fill and stroke
		content.TextSetHScale(120);//set horizontal scale*/
		content.DrawText(text);
		content.TextEnd();
		content.GSRestore();

		//underline
		dgs = m_doc.NewGState();
		dgs.SetFillAlpha(255);//set alpha value to 0.5
		dgs.SetStrokeAlpha(255);//set alpha value to 0.5
		rgs = page.AddResGState(dgs);
		content.GSSet(rgs);

		content.GSSave();
		Matrix matUnder = new Matrix( 1, 1, (w-size[0])/2, 770 );
		content.GSSetMatrix(matUnder);
		matUnder.Destroy();

		//build a path object
		Path pathUnder = new Path();
		pathUnder.MoveTo(1, 1);
		pathUnder.LineTo(size[0] - 1, 1);
		pathUnder.ClosePath();

		//fill it
		content.SetStrokeColor(0xff69b4);//set pink color;
		content.SetStrokeWidth(2);//set stroke width
		content.StrokePath(pathUnder);
		content.GSRestore();

		//add content to page
		page.AddContent(content, true);

		content.Destroy();
		page.Close();
The administrator has disabled public write access.
The following user(s) said Thank You: Tele
Powered by Kunena Forum