求助:部分dwg 转换 pdf 失败,实际上由源文件里几个标识引起的问题!
image.png (3.0 KB)
image.png (13.1 KB)
请问,如何共享dwg文件?
无法转换文件在附件!
---- 回复的原邮件 ----
发件人 | Alex Gorokhovatskyi via Free Support Forum - aspose.comforum@aspose.com |
- | - |
发送日期 | 2024年5月15日 17:40 |
收件人 | dream.xg@qq.com |
主题 | [Free Support Forum - aspose.com] [中文技术支持] 求助:dwg 转换 pdf 失败!! |
| oleksii.gorokhovatskyi
May 15 |
- | - |
@dream.xg,
您可以将其以 zip 存档形式附加到此处,或通过某些第三方服务附加到此处,以便我们可以轻松下载。
FileContnot.zip (45.8 KB)
try(
net.lingala.zip4j.io.inputstream.ZipInputStream zis = zipFile.getInputStream(zipFile.getFileHeader(StringUtils.format(“{}{}”,fileName,fileExtension)));
BufferedInputStream bis = new BufferedInputStream(zis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
)
{
LoadOptions opts = new LoadOptions();
opts.setSpecifiedEncoding(CodePages.Utf8);
Image image = Image.load(bis, opts);
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.setBackgroundColor(Color.getWhite());
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
image.save(bos, pdfOptions);
ZipParameters parameters = new ZipParameters();
parameters.setFileNameInZip(StringUtils.format("{}{}",fileName,".pdf"));
try(
InputStream is = new ByteArrayInputStream(os.toByteArray());
BufferedInputStream bis2 = new BufferedInputStream(is)
)
{
zipFile.addStream(bis2, parameters);
}
catch (Exception e)
{
throw e;
}
}
catch (Exception e)
{
throw e;
}
@dream.xg,
这是我使用 Aspose.CAD for Java 24.3 的代码,结果附后。
String in = filename;
LoadOptions opts = new LoadOptions();
opts.setSpecifiedEncoding(CodePages.Utf8);
Image cadImage = Image.load(in, opts);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(pdfName, pdfOptions);
FileContnot.dwg_java_.pdf (362.8 KB)
没有文件实体路径的, 只能通过输入流读取, 并保存成输出流
@dream.xg,
整个示例也适用于我:
ZipFile zipFile = new ZipFile(basePath + "FileContnot.zip");
try(
net.lingala.zip4j.io.inputstream.ZipInputStream zis = zipFile.getInputStream(zipFile.getFileHeader("FileContnot.dwg"));
BufferedInputStream bis = new BufferedInputStream(zis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
)
{
LoadOptions opts = new LoadOptions();
opts.setSpecifiedEncoding(CodePages.Utf8);
Image image = Image.load(bis, opts);
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.setBackgroundColor(Color.getWhite());
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
image.save(bos, pdfOptions);
ZipParameters parameters = new ZipParameters();
parameters.setFileNameInZip("FileContnot.pdf");
try(
InputStream is = new ByteArrayInputStream(os.toByteArray());
BufferedInputStream bis2 = new BufferedInputStream(is)
)
{
zipFile.addStream(bis2, parameters);
}
catch (Exception e)
{
throw e;
}
}
catch (Exception e)
{
throw e;
}
FileContnot.zip (385.2 KB)
已经解决,是版本的问题 thank you!