- Posts: 13
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
How to add PageContent text gravity ?
IP: 192.168.0.71
8 years 7 months ago - 8 years 7 months ago #12776
by Tele
How to add PageContent text gravity ? was created by Tele
Last edit: 8 years 7 months ago by Tele. Reason: Added desired screenshot
IP: 192.168.0.71
8 years 7 months ago #12778
by Davide
Replied by Davide on topic How to add PageContent text gravity ?
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?
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?
IP: 192.168.0.71
8 years 7 months ago - 8 years 6 months ago #12779
by Tele
Replied by Tele on topic How to add PageContent text gravity ?
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 ?
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: 8 years 6 months ago by Tele.
IP: 192.168.0.71
8 years 6 months ago - 8 years 6 months ago #12781
by Tele
Replied by Tele on topic How to add PageContent text gravity ?
Here is my code to add header
@Davide : Any suggestions ?
Code:
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();
Last edit: 8 years 6 months ago by Tele.
IP: 192.168.0.71
8 years 6 months ago - 8 years 6 months ago #12787
by Tele
Did you get a chance to check my issue once ?
Replied by Tele on topic How to add PageContent text gravity ?
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: 8 years 6 months ago by Tele.
IP: 192.168.0.71
8 years 6 months ago #12788
by Davide
Replied by Davide on topic How to add PageContent text gravity ?
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.
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.
Code:
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();
Time to create page: 0.443 seconds