DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Android Cloud Apps with Azure
  • Overview of Android Networking Tools: Receiving, Sending, Inspecting, and Mock Servers
  • Using Db4o in an Android Application
  • How To Use Constraint Layout in Xamarin.Android

Trending

  • No Spark Streaming, No Problem
  • Understanding Git
  • How To Start a Successful Career in DevOps
  • The Agile Architect: Mastering Architectural Observability To Slay Technical Debt
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Add Text in Header/Footer Area of PDF File in Android Applications

How to Add Text in Header/Footer Area of PDF File in Android Applications

David Zondray user avatar by
David Zondray
·
Aug. 06, 14 · Code Snippet
Like (0)
Save
Tweet
Share
2.44K Views

Join the DZone community and get the full member experience.

Join For Free

This technical tip shows how developers can add text in header or footer of a PDF file  inside their Android applications. The TextStamp class is used to add text in PDF document. We can also use the same class to add text in Header/Footer area of PDF file. The TextStamp class provides necessary methods to specify font size, font style, and font color etc for stamp object. In order to add text in the Header area, first you need to create a Document object and a TextStamp object using required methods. After that, you can call addStamp(..) method of Page class to add text in the PDF file.   Please note that when placing text in Header section, you need to call setTopMargin(..) in such a way that it adjusts the text in the header area of your PDF. Similarly when placing text in Footer section, you need to call setBottomMargin(..) in such a way that it adjusts to the text in Footer area.

  • When adding stamp object in Header section, you also need to set VerticalAlignment to Top.
  • When adding stamp object in Footer section, you also need to set VerticalAlignment to Bottom.
//open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("/mnt/sdcard/input.pdf");
//create text stamp
com.aspose.pdf.TextStamp textStamp = new com.aspose.pdf.TextStamp("Sample Stamp");
//set properties of the stamp
textStamp.setTopMargin(10);
textStamp.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);
textStamp.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Top);

//set text properties
textStamp.getTextState().setFont(new com.aspose.pdf.FontRepository().findFont("Arial"));
textStamp.getTextState().setFontSize(14.0F);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);
textStamp.getTextState().setForegroundColor(java.awt.Color.GREEN);

// iterate through all pages of PDF file
for (int Page_counter =1; Page_counter<=pdfDocument.getPages().size();Page_counter++)
{
    //add stamp to all pages of PDF file
    pdfDocument.getPages().get_Item(Page_counter).addStamp(textStamp);
}
//save output document
pdfDocument.save("/mnt/sdcard/TextStamp_output.pdf");

PDF application Android (robot)

Opinions expressed by DZone contributors are their own.

Related

  • Android Cloud Apps with Azure
  • Overview of Android Networking Tools: Receiving, Sending, Inspecting, and Mock Servers
  • Using Db4o in an Android Application
  • How To Use Constraint Layout in Xamarin.Android

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: