I'm trying to generate PDF file on android with some Chinese characters using below code.It is working fine without Chinese characters(Only English) and PDF size is around 40-50Kb. But when I try to generate PDF with Chinese characters ,it is working and PDF size is 3-4MB.
Number of characters for both cases are almost same. Any idea how to reduce the PDF size? Because i need to upload the PDF to server.
public void generatePDFDoc(Activity activity, View view, String pdfFileName){
{
File pdfFile = null;
PrintAttributes printAttrs = new PrintAttributes.Builder().
setColorMode(PrintAttributes.COLOR_MODE_COLOR).
setMediaSize(PrintAttributes.MediaSize.NA_LETTER).
setResolution(new PrintAttributes.Resolution("print", activity.PRINT_SERVICE,
25, 25)).
setMinMargins(PrintAttributes.Margins.NO_MARGINS).
build();
PdfDocument document = new PrintedPdfDocument(activity, printAttrs);
View content = view;
int width = content.getWidth();
int height = content.getHeight();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(width, height, 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
content.draw(page.getCanvas());
document.finishPage(page);
try {
pdfFile = new File(pdfFileName);
if (pdfFile != null) {
FileOutputStream os = new FileOutputStream(pdfFile);
document.writeTo(os);
document.close();
os.close();
}
} catch (Exception e) {
throw new RuntimeException("Error generating file", e);
} finally {
if (pdfFile != null) {
//Success Generate PDF file
}
}
}
}