Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1

TOPIC:

How to add PageContent text gravity ? 6 years 8 months ago #12776

  • Tele
  • Tele's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0



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 ?
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: by Tele. Reason: Added desired screenshot

How to add PageContent text gravity ? 6 years 8 months ago #12778

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
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 following user(s) said Thank You: Tele

Please Log in or Create an account to join the conversation.

How to add PageContent text gravity ? 6 years 8 months ago #12779

  • Tele
  • Tele's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 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 ?

Please Log in or Create an account to join the conversation.

Last edit: by Tele.

How to add PageContent text gravity ? 6 years 8 months ago #12781

  • Tele
  • Tele's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 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 ?

Please Log in or Create an account to join the conversation.

Last edit: by Tele.

How to add PageContent text gravity ? 6 years 8 months ago #12787

  • Tele
  • Tele's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 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 ?


Did you get a chance to check my issue once ?

Please Log in or Create an account to join the conversation.

Last edit: by Tele.

How to add PageContent text gravity ? 6 years 8 months ago #12788

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
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 following user(s) said Thank You: Tele

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum