我正在开发一个应用程序(Android 4.4 - API 20),我正在生成HTML格式的报告.我使用WebView对象在我的应用程序中显示报表.
我希望能够做的是将此WebView转换为pdf文档.
我已经能够使用PdfDocument转换它,并从WebView对象执行.draw到页面.我保存文件,这是有效的,但结果是单页文档.没有分页符.
View content = (View) webView;
PrintAttributes pdfPrintAttrs = new PrintAttributes.Builder().
setColorMode(PrintAttributes.COLOR_MODE_MONOCHROME).
setMediaSize(PrintAttributes.MediaSize.NA_LETTER.asLandscape()).
setResolution(new Resolution("zooey", PRINT_SERVICE, 300, 300)).
setMinMargins(PrintAttributes.Margins.NO_MARGINS).
build();
PdfDocument document = new PrintedPdfDocument(mContext,pdfPrintAttrs);
PageInfo pageInfo = new PageInfo.Builder(webView.getMeasuredWidth(), webView.getContentHeight(), 1).create();
Page page = document.startPage(pageInfo);
content.draw(page.getCanvas());
document.finishPage(page);
Run Code Online (Sandbox Code Playgroud)
如果我更改它以便我使用PrintedPdfDocumet并且不指定PageInfo我只获取WebView对象的可查看部分.
View content = (View) webView;
PrintAttributes pdfPrintAttrs = new PrintAttributes.Builder().
setColorMode(PrintAttributes.COLOR_MODE_MONOCHROME).
setMediaSize(PrintAttributes.MediaSize.NA_LETTER.asLandscape()).
setResolution(new Resolution("zooey", PRINT_SERVICE, 300, 300)).
setMinMargins(PrintAttributes.Margins.NO_MARGINS).
build();
PrintedPdfDocument document = new PrintedPdfDocument(mContext,pdfPrintAttrs);
Page page = document.startPage(0);
content.draw(page.getCanvas());
document.finishPage(page);
Run Code Online (Sandbox Code Playgroud)
如果我使用PrintManager并使用createPrintDocumentAdapter从WebView对象创建打印适配器,我可以选择"另存为PDF"选项,生成的pdf文件具有我在原始网页的CSS中指定的分页符.
PrintManager printManager = (PrintManager) …Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但无论如何我都会冒这个问题.
通常我需要创建一个final变量以供其他地方使用,并且需要根据某些条件设置该变量的值.这就是我通常这样做的方式:
String notFinalVersion = null;
if (someThing == 1) {
notFinalVersion = "The value was 1.";
} else {
notFinalVersion = "The value is not 1.";
}
final String finalVersion = notFinalVersion;
Run Code Online (Sandbox Code Playgroud)
然后我可以finalVersion在需要的地方使用变量.但是,这似乎有些不对劲.有一个更好的方法吗?
编辑:通过"更好",我的意思是我正在寻找一种方法来定义最终变量,不需要我创建一个额外的变量.我知道创建一个额外的变量是低效的,而不是一个好的做法,而且我很肯定必须有一种方法可以在没有额外步骤的情况下完成需要完成的工作.
我收到了一个答案,我已将其标记为已接受.正如我在评论中所述,我最初尝试过提供的解决方案,但收到了Eclipse的错误.我必须在第一次输入错误,或者Eclipse有一些"打嗝".
我接受有许多方法可以做某事,一个人接受的最佳方式不是别人会考虑的.但是,这里包含的所有答案都很明确,而且我觉得,解决了我的问题.
我正在使用msdeploy将网站代码推送到4个不同的服务器(测试和生产服务器).在前3个工作正常,但第4个给我一个ERROR_CERTIFICATE_VALIDATION_FAILED错误.我正在使用-allowUntrusted选项.
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:iisApp="E:\workspace\testDeploy\outproject\_PublishedWebsites\<webfolder>" -dest:iisApp="mycompany.com",ComputerName="https://<hostip>:8172/MsDeploy.axd",UserName="<userid>",Password="****",AuthType="Basic" -allowUntrusted -enableRule:AppOffline -skip:objectName=filePath,absolutePath="^.*<webfolder>\\web.*\.config$|^.*mycompany\.com\\web.*\.config"
Error Code: ERROR_CERTIFICATE_VALIDATION_FAILED
More Infenter code hereormation: Connected to the remote computer ("<hostip>") using the specified process ("Web Management Service"), but could not verify the server's certificate. If you trust the server, connect again and allow untrusted certificates. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_CERTIFICATE_VALIDATION_FAILED.
Error: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Error: The remote certificate is invalid according to the validation …Run Code Online (Sandbox Code Playgroud)