我在Kitkat中使用以下代码来生成pdf文件。它是如何根据我给定的文本生成pdf文件名的。
,但在lollipop中,同一段代码不起作用。它的生成文件名"RepoDocument.pdf"其中Repo是我的应用程序名称
@Override
public void onLayout(PrintAttributes oldAttributes,
PrintAttributes newAttributes,
CancellationSignal cancellationSignal,
LayoutResultCallback callback,
Bundle metadata)
{
// Create a new PdfDocument with the requested page attributes
mPdfDocument = new PrintedPdfDocument(m_context, newAttributes);
// Respond to cancellation request
if (cancellationSignal.isCanceled() )
{
callback.onLayoutCancelled();
return;
}
// Compute the expected number of printed pages
int pages = computePageCount(newAttributes);
if (pages > 0)
{
// Return print information to print framework
PrintDocumentInfo info = new PrintDocumentInfo.Builder("mycustomname.pdf")
.setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
.setPageCount(pages).build();
// Content layout reflow is complete
callback.onLayoutFinished(info, true);
}
else
{
// Otherwise report an error to the print framework
callback.onLayoutFailed("Page count calculation failed.");
}
}
这个问题的原因是什么?如果你需要更多的输入,请告诉我
文件名可以在这里定义
private void doPrint() {
// Get a PrintManager instance
PrintManager printManager = (PrintManager) getActivity()
.getSystemService(Context.PRINT_SERVICE);
// Set job name, which will be displayed in the print queue
String jobName = "DocumentName.pdf";
// Start a print job, passing in a PrintDocumentAdapter implementation
// to handle the generation of a print document
printManager.print(jobName, new MyPrintDocumentAdapter(getActivity()),
null); //
}
我认为jobname不是文件名,因为它只用于命名打印作业。