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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Covert Microsoft Excel Files to PDF or PDF/A in Android Applications

David Zondray user avatar by
David Zondray
·
May. 28, 14 · · Code Snippet
Like (1)
Save
Tweet
2.46K Views

Join the DZone community and get the full member experience.

Join For Free
This technical tip show how developers can Covert Microsoft Excel Files to PDF or PDF/A inside their Android applications using Aspose.Cell for Android .  PDF documents are widely used as a standard format of exchanging documents between organizations, government sectors and individuals. Software developers are often asked to device a way to easily convert Microsoft Excel files into PDF documents.  Aspose.Cells for Android can convert spreadsheets to PDF directly (including PDF/A), without any other product. Aspose.Cell converts spreadsheets to PDF with a high degree of accuracy and fidelity. Save an Excel file directly to PDF using the Workbook class' Save method, and provide the FileFormatType.PDF interface member. Direct conversion like this is the most efficient conversion method. It does not lose data or formatting but keeps the output PDF looking like the input Excel file. To specify security options when saving to PDF, use PdfSaveOptions.
//Instantiate a new workbook with Excel file path
String sdCardPath = Environment.getExternalStorageDirectory().getPath()+ File.separator;
Workbook workbook = new Workbook(sdCardPath + "Book1.xls");
//Save the document in PDF format
workbook.save(sdCardPath + "MyPdfFile.pdf", FileFormatType.PDF);

//PDF/A Conversion

Aspose.Cells for Java also provides support for PDF/A compliance.
//Open an existing Excel file
String sdCardPath = Environment.getExternalStorageDirectory().getPath()+ File.separator;
Workbook workbook = new Workbook(sdCardPath + "Book1.xls");
//Define PdfSaveOptions
PdfSaveOptions saveOptions = new PdfSaveOptions();
//Set the compliance type
saveOptiions.setCompliance(PdfCompliance.PDF_A_1_B);
//Save the PDF file
workbook.save(sdCardPath + "out.pdf", saveOptions);

//Set Creation Time for Output PDF

//When using the PdfSaveOptions class, you can get or set the PDF creation time.

File sdDir = Environment.getExternalStorageDirectory();
String sdPath = sdDir.getCanonicalPath();
//Load an exiting workbook or create from scratch
Workbook book = new Workbook(sdPath + "/book2.xlsx");
//Create an instance of PdfSaveOptions and pass SaveFormat to the construnctor
PdfSaveOptions options = new PdfSaveOptions(SaveFormat.PDF);
//Set the CreatedTime for the PdfSaveOptions as per requirement
options.setCreatedTime(DateTime.getNow());
//Save the workbook to PDF format while passing the object of PdfSaveOptions
book.save(sdPath + "/output.pdf", SaveFormat.PDF);
PDF Microsoft Excel Android (robot) application

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Generate Fake Test Data
  • Your Old Laptop Is Your New Database Server
  • Java Hashtable, HashMap, ConcurrentHashMap: Performance Impact
  • DZone's Article Submission Guidelines

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo