I am using android.print.pdf.PrintedPdfDocument in order to export PDF with text layers and images.
But when applying an italic style to some text, The output of text layers with italic style has offset on the X axis .
I am using paint in order to draw the text, simple as it :
private void drawTextOnPDFCanvas(Canvas pdfDocumentCanvas)
{
boolean isDrawItalic = true; // just for demonstration
Paint paint = new Paint();
Typeface plain = PSDFontSets.get(i).getFontTypeface();
Typeface font = Typeface.create(plain, Typeface.NORMAL);
if(isDrawItalic)
{
font = Typeface.create(plain, Typeface.ITALIC);
}
paint.setTypeface(font);
pdfDocumentCanvas.drawText("test", 0, 0, paint);
}
PrintedPdfDocument code :
PrintAttributes attributesBuilder = new PrintAttributes.Builder()
.setMediaSize(new PrintAttributes.MediaSize("id","label",3750,2250)) // 270.162 points 1125,675 pixels in 300 dpi
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
.setResolution(new PrintAttributes.Resolution("id","label",72,72)) // has no effect , its bug
.setColorMode(PrintAttributes.COLOR_MODE_COLOR).build();
String outputPathExample = "test.pdf";
PrintedPdfDocument document = new PrintedPdfDocument(context, attributesBuilder);
PdfDocument.Page page = document.startPage(0);
drawTextOnPDFCanvas(page.getCanvas());
document.finishPage(page);
OutputStream ots = new FileOutputStream(outputPathExample );
document.writeTo(ots);
document.close();
ots.close();
Tried with different fonts all of them same result
any one have any idea what's wrong ?
input:
output:
question from:
https://stackoverflow.com/questions/65918820/android-using-printedpdfdocument-to-export-pdf-file-with-italic-style-text-issue 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…