Knowledge Base and examples

Knowledge Base - How to add text to a PDF.

This article shows how to add text to a pdf.

To use these methods you need a Premium license.

int pageNumber = 0;

//prepare to write texts
PageContent content = new PageContent();
content.Create();//create content, do not forget.
content.GSSave();
Matrix mat = new Matrix( 1, 1, 100, 500 );
content.GSSetMatrix(mat);
mat.Destroy();

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

content.TextBegin();
content.TextSetFont(rfont, 20);//set font and size
content.SetFillColor(0xff0000);
content.SetStrokeColor(0x10);
content.TextSetCharSpace(0);
content.TextSetWordSpace(0.3f);
content.TextSetLeading(20);
content.TextSetRenderMode(2);//fill and stroke
content.TextSetHScale(120);//set horizontal scale
content.DrawText("RadaeePDF\rTest!");
content.TextEnd();
content.GSRestore();

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

page.Close();

//refresh view
PDFVPage pageToRefresh = m_view.vGetPage(pageNumber);
m_view.vRenderSync(pageToRefresh);

//refresh view RDPDFReader
// m_view.refreshView(pageNumber);
//if you want to save text to pdf
//m_doc.Save();


If you are using RDPDFReader to refresh the view you have to add this method to PDFLayoutView

 public void refreshView(int pageToRefresh){
if(m_layout != null) {
m_layout.vRenderSync(m_layout.vGetPage(pageToRefresh));
invalidate();
}
}
Applies To

RadaeePDF SDK for Android

Details

Created : 2015-08-25 10:27:52, Last Modified : 2016-02-29 16:38:06