Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

Android using PrintedPdfDocument to export PDF file with italic style text issue

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: input

output: output

question from:https://stackoverflow.com/questions/65918820/android-using-printedpdfdocument-to-export-pdf-file-with-italic-style-text-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...