我在我的项目(java spring boot)中使用 openPDF 库来编辑 PDF.in microsoft edge 显示所有注释工具,如(标记、橡皮擦等)。但 chrome 和 firefox 没有显示任何注释工具(它正在显示放大——缩小保存等)。我需要所有的注释都应该显示在所有浏览器中。
我使用的是 1.3.30 版本的 librepdf/openpdf
下面是pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>1.3.30</version>
</dependency>
<dependency>
<groupId>SAMPLE</groupId>
<artifactId>SAMPLE</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我在 src/main/java 中创建了 com.javapoint 文件,文件名为 SpringBootHelloWorldExampleApplication.java
我的代码会像
package com.javatpoint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootHelloWorldExampleApplication
{
public static void main(String[] args)
{
SpringApplication.run(SpringBootHelloWorldExampleApplication.class, args);
}
}
然后我在 src/main/java 中创建了文件夹 com.javapoint.controller。文件名为 HelloWorldController.java
package com.javatpoint.controller;
import java.io.ByteArrayInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.javatpoint.service.PdfService;
@RestController
@RequestMapping("/pdf")
public class HelloWorldController
{
@Autowired
private PdfService pdfservice;
@GetMapping("/createPdf")
public ResponseEntity<InputStreamResource> createPdf() {
ByteArrayInputStream pdf=pdfservice.createPdf();
HttpHeaders httpHeaders=new HttpHeaders();
httpHeaders.add("Content-Disposition","inline;file=lcwd.pdf");
return ResponseEntity.ok().headers(httpHeaders).contentType(MediaType.APPLICATION_PDF).body(new InputStreamResource(pdf));
}
}
我在 src/main/java 中创建了另外 1 个文件夹 com.javapoint.service,文件名为 PdfService.java
可能代码会是
package com.javatpoint.service;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
@Service
public class PdfService {
private Logger logger=LoggerFactory.getLogger(PdfService.class);
public ByteArrayInputStream createPdf() {
logger.info("Create PDF Started:");
String title = "Welcome sahana";
String content = "PDF editor testing";
ByteArrayOutputStream out = new ByteArrayOutputStream();
Document document=new Document();
PdfWriter.getInstance(document, out);
document.open();
Font titleFont=FontFactory.getFont(FontFactory.HELVETICA_BOLD,25);
Paragraph titlePara=new Paragraph(title,titleFont);
titlePara.setAlignment(Element.ALIGN_CENTER);
document.add(titlePara);
Font paraFont=FontFactory.getFont(FontFactory.HELVETICA,18);
Paragraph paragraph=new Paragraph(content);
paragraph.add(new Chunk( content + "Wow this text is added after creating paragraph"));
document.add(paragraph);
document.close();
return new ByteArrayInputStream(out.toByteArray());
}
}
我在这里创建了 1 个 pdf ..现在它只在 Microsoft Edge 中显示注释工具,我需要它应该支持所有浏览器。我可以获得显示所有注释工具(标记、橡皮擦等)的解决方案吗??