为有中文需求的客户提供多渠道中文技术支持.

Fri Jan 06, 2023 6:19 am

基于你们的软件生成doc 在转换成PDF 然后采用com.aspose.pdf.Document 转图片 加粗字体直接丢失了

a6636088
 
Posts: 4
Joined: Fri Jan 06, 2023 6:15 am

Fri Jan 06, 2023 6:24 am

生成的是采用贵公司的DEMO
//创建Word文档
Document document = new Document();
Section sec = document.addSection();

//添加段落
Paragraph paragraph = sec.addParagraph();
paragraph.appendText("这是一段样式繁多的文字,我是");

//在段落中添加文字,并返回TextRange对象
TextRange tr = paragraph.appendText("带删除线的文字");

//通过TextRange对象设置文字带删除线
tr.getCharacterFormat().isStrikeout(true);

//设置文字阴影效果
paragraph.appendText(",我是");
tr = paragraph.appendText("带阴影的文字");
tr.getCharacterFormat().isShadow(true);

//设置文字字号
paragraph.appendText(",我是");
tr = paragraph.appendText("加大的文字");
tr.getCharacterFormat().setFontSize(20);

//设置文字颜色
paragraph.appendText(",我是");
tr = paragraph.appendText("红色的文字");
tr.getCharacterFormat().setTextColor(Color.red);

//设置文字斜体加粗
paragraph.appendText(",我是");
tr = paragraph.appendText("斜体加粗的文字");
tr.getCharacterFormat().setBold(true);
tr.getCharacterFormat().setItalic(true);

//设置文字斜体加粗
paragraph.appendText(",我是");
tr = paragraph.appendText("加粗的文字");
tr.getCharacterFormat().setBold(true);

//设置文字带下划线
paragraph.appendText(",我是");
tr = paragraph.appendText("带下划线的文字");
tr.getCharacterFormat().setUnderlineStyle(UnderlineStyle.Single);

//设置文字背景色
paragraph.appendText(",我是");
tr = paragraph.appendText("带背景色的文字");
tr.getCharacterFormat().setTextBackgroundColor(Color.GREEN);

//为文字添加上标
paragraph.appendText(",这里还有一个公式:a");
tr = paragraph.appendText("2");
tr.getCharacterFormat().setSubSuperScript(SubSuperScript.Super_Script);
paragraph.appendText(" + b");
tr = paragraph.appendText("2");
tr.getCharacterFormat().setSubSuperScript(SubSuperScript.Super_Script);
paragraph.appendText(" = c");
tr = paragraph.appendText("2");
tr.getCharacterFormat().setSubSuperScript(SubSuperScript.Super_Script);
paragraph.appendText("。");

//对整个段落设置为宋体(默认为英文字体)
ParagraphStyle style1 = new ParagraphStyle(document);
style1.setName("style");
style1.getCharacterFormat().setFontName("宋体");
document.getStyles().add(style1);
paragraph.applyStyle(style1.getName());

//保存文档
// document.saveToFile("D:\\codeGenerator\\documentWhite.docx", FileFormat.Docx);
document.saveToFile("D:\\codeGenerator\\documentWhite.pdf",FileFormat.PDF);

a6636088
 
Posts: 4
Joined: Fri Jan 06, 2023 6:15 am

Fri Jan 06, 2023 6:25 am

采用PDFBOX进行PDF拆分,然后使用 com.aspose.pdf.Document 进行PDF转图片
PDDocument doc = Loader.loadPDF(new File("D:\\codeGenerator\\documentWhite.pdf"));
// 分割操作
Splitter split = new Splitter();
// 设置从那页开始分割
split.setStartPage(1);
// 设置每个文件多少页
split.setSplitAtPage(1);
// 分割文档
List<PDDocument> docs = split.split(doc);
int i = 1;
// 生成分割文档
for (PDDocument document : docs) {
String fileName = "D:\\codeGenerator\\" + "_Page" + (i - 1) + ".pdf";
String fileName2 = "D:\\codeGenerator\\" + "_Page" + (i - 1) + ".png";
String fileName3 = "D:\\codeGenerator\\" + "_Page1" + (i - 1) + ".png";
File file = new File(fileName);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
document.save(fos);
i++;

ByteArrayOutputStream out = new ByteArrayOutputStream();
document.save(out);
// BufferedImage image = PdfAsposeUtil.pdfToImage(out, 1);
ByteArrayInputStream sbs = new ByteArrayInputStream(out.toByteArray());
com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(sbs);
GifDevice gifDevice = new GifDevice(new Resolution(300));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
gifDevice.process(pdf.getPages().get_Item(1), byteArrayOutputStream);
BufferedImage read = ImageIO.read(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
ImageIO.write(read, "jpg", new File(fileName2));

PDFRenderer renderer = new PDFRenderer(document);
BufferedImage image2 = renderer.renderImageWithDPI(0, 300);
File file2 = new File( "D:\\codeGenerator\\" + "_Page2" + (i - 1) + ".png");
ImageIO.write(image2, "jpg", file2);
image2.flush();

document.close();
}

a6636088
 
Posts: 4
Joined: Fri Jan 06, 2023 6:15 am

Fri Jan 06, 2023 8:15 am

您好,

感谢您的来帖。
我测试您用我们产品代码生成的pdf文档,使用Adobe工具打开手动转换到图片,内容没有出现任何问题。我们不清楚com.aspose.pdf.Document产品转换为何会导致内容丢失,恐怕您需要联系aspose技术支持去调查此转换问题,后面有需要我们进行配合的,请告知我们。

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Mon Jan 09, 2023 3:21 am

我在思考是否是你们的加粗字体在转换PDF的过程当中加了一些不一样的样式,导致PDF解析成图片的时候出现了内容丢失。因为一样的内容 通过abode操作过以后转换就不会出现内容丢失

a6636088
 
Posts: 4
Joined: Fri Jan 06, 2023 6:15 am

Mon Jan 09, 2023 3:36 am

您好,

这个需要先了解Aspose产品转换时如何处理的,是否和我们的处理机制不一样。请您将Aspose产品调查的结果反馈给我们,我们将配合调查。

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Return to 中文技术支持