我们已经使用iText一年多来使用自定义页眉和页脚生成PDF文档(在驱动器上)。
为此,我们在google doc的pdf中阅读如下:
URL url = DriveController.getUrlFromFile(fileId);
if(url != null) {
PdfReader reader = new PdfReader(url);
int n = reader.getNumberOfPages();
PdfImportedPage page;
....
public static URL getUrlFromFile(String fileId) {
fileId = "1macLOQW0YG9KMq0iTiMkMbs4-be07fNWtWAksVkjVvk";
Drive service = null;
try {
service = DriveDirectoryServiceManager.getDriveService(SERVICE_ACCOUNT);
File file = service.files().get(fileId).execute();
try {
if (file.getExportLinks() != null) {
return new URL(file.getExportLinks().get("application/pdf"));
.....
自3月23日起,iText正在投掷" com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not found.
"在这一行:
PdfReader reader = new PdfReader(url);
当你在浏览器中手动浏览时,没有代码会改变,而且奇怪的是pdf的URL似乎返回了完美的pdf。
当我检查URL返回的内容的内容输入流时,我可以看到它以"%PDF-1.5"开头。看起来很好,并且返回的URL的标题看起来非常好:
{
cache-control=[private, max-age=0],
content-type=[application/pdf; charset=utf-8],
date=[Mon, 27 Mar 2017 09:23:24 GMT],
expires=[Mon, 27 Mar 2017 09:23:24 GMT],
x-robots-tag=[noindex, nofollow, nosnippet],
content-disposition=[attachment;filename="BUCK-PP-6L-RO-HNDL-209-211-QDS-GLOB-PMS0001.pdf"],
transfer-encoding=[chunked],
p3p=[CP="This is not a P3P policy! See https://support.google.com/accounts/answer/151657?hl=en for more info.", CP="This is not a P3P policy! See https://support.google.com/accounts/answer/151657?hl=en for more info."],
x-content-type-options=[nosniff],
x-frame-options=[SAMEORIGIN],
x-xss-protection=[1; mode=block],
server=[GSE],
set-cookie=[NID=99=m3XiYqz60y3VfDLAXLLcMnakRT7TbAYOqFABcvJIuRM8hs8zo9yfylmcnPY4y0bTv-j2RjVf4QTj7dC7TKTE-Mvg1lZlpGQJl0Q1EmbfjYHZtx8RqYLjtbNMIc18Ac6J;Domain=.google.com;Path=/;Expires=Tue, 26-Sep-2017 09:23:24 GMT;HttpOnly, NID=99=FO3FQ6tVAsgeq2_GbdJlOSCVegOfqgou2uR_uc_tIkeXhUbXVnrgHrV9SJIz01-IhlE5SmUf5caLYhN1rlnVo0ROcYlzozBwCESPOWOEHnFZhHl3Nv99q7MCiUu-AUro;Domain=.google.com;Path=/;Expires=Tue, 26-Sep-2017 09:23:24 GMT;HttpOnly],
alt-svc=[quic=":443"; ma=2592000; v="37,36,35"]
}
如果有人知道为什么iText不会将其识别为pdf,欢迎任何帮助。
亲切的问候