use of org.docx4j.openpackaging.exceptions.Docx4JException in project Java-Tutorial by gpcodervn.
the class Docx4jUtils method setPageMargins.
/**
* Set document page margins to 50 pixels
*/
private void setPageMargins() {
try {
Body body = wordMLPackage.getMainDocumentPart().getContents().getBody();
PageDimensions page = new PageDimensions();
PgMar pgMar = page.getPgMar();
pgMar.setBottom(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setTop(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setLeft(BigInteger.valueOf(pixelsToDxa(50)));
pgMar.setRight(BigInteger.valueOf(pixelsToDxa(50)));
SectPr sectPr = factory.createSectPr();
body.setSectPr(sectPr);
sectPr.setPgMar(pgMar);
} catch (Docx4JException e) {
e.printStackTrace();
}
}
use of org.docx4j.openpackaging.exceptions.Docx4JException in project com.revolsys.open by revolsys.
the class XlsxRecordReader method initDo.
@Override
protected void initDo() {
super.initDo();
try (InputStream in = this.resource.newBufferedInputStream()) {
final SpreadsheetMLPackage spreadsheetPackage = (SpreadsheetMLPackage) OpcPackage.load(in);
final DocPropsCustomPart customProperties = spreadsheetPackage.getDocPropsCustomPart();
if (customProperties != null) {
int srid = 0;
try {
srid = Integer.parseInt(customProperties.getProperty("srid").getLpwstr());
} catch (final Throwable e) {
}
int axisCount = 2;
try {
axisCount = Integer.parseInt(customProperties.getProperty("axisCount").getLpwstr());
if (axisCount > 4) {
axisCount = 2;
}
} catch (final Throwable e) {
}
double scaleXy = 0;
try {
scaleXy = Double.parseDouble(customProperties.getProperty("scaleXy").getLpwstr());
} catch (final Throwable e) {
}
double scaleZ = 0;
try {
scaleZ = Double.parseDouble(customProperties.getProperty("scaleZ").getLpwstr());
} catch (final Throwable e) {
}
final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scaleXy, scaleXy, scaleZ);
setGeometryFactory(geometryFactory);
}
WorksheetPart worksheetPart = null;
for (final Part part : spreadsheetPackage.getParts().getParts().values()) {
if (part instanceof WorksheetPart) {
if (worksheetPart == null) {
worksheetPart = (WorksheetPart) part;
}
} else if (part instanceof SharedStrings) {
final SharedStrings sharedStrings = (SharedStrings) part;
final CTSst contents = sharedStrings.getContents();
this.sharedStringList = contents.getSi();
}
}
if (worksheetPart != null) {
final Worksheet worksheet = worksheetPart.getContents();
final SheetData sheetData = worksheet.getSheetData();
this.rows = sheetData.getRow();
final List<String> line = readNextRow();
final String baseName = this.resource.getBaseName();
newRecordDefinition(baseName, line);
}
} catch (final IOException | Docx4JException e) {
Logs.error(this, "Unable to open " + this.resource, e);
} catch (final NoSuchElementException e) {
}
}
use of org.docx4j.openpackaging.exceptions.Docx4JException in project docx4j-template by vindell.
the class Word_解压_Unzip_S3_Test method zipXml.
public void zipXml(String inputfilepath, String outFilePath) throws Exception {
System.out.println(inputfilepath);
// Load the docx
File baseDir = new File(inputfilepath);
UnzippedPartStore partLoader = new UnzippedPartStore(baseDir);
final Load3 loader = new Load3(partLoader);
OpcPackage opc = loader.get();
// Save it zipped
ZipPartStore zps = new ZipPartStore();
zps.setSourcePartStore(opc.getSourcePartStore());
Save saver = new Save(opc, zps);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(outFilePath));
saver.save(fos);
} catch (FileNotFoundException e) {
throw new Docx4JException("Couldn't save " + outFilePath, e);
} finally {
IOUtils.closeQuietly(fos);
}
}
use of org.docx4j.openpackaging.exceptions.Docx4JException in project docx4j-template by vindell.
the class Docx4jUtils method docxToPdf.
/**
* docx文档转换为PDF
*
* @param docx
* docx文档
* @param pdfPath
* PDF文档存储路径
* @throws Exception
* 可能为Docx4JException, FileNotFoundException, IOException等
*/
public static void docxToPdf(String docxPath, String pdfPath) throws Exception {
OutputStream output = null;
try {
output = new FileOutputStream(pdfPath);
WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new File(docxPath));
WMLPACKAGE_BUILDER.configChineseFonts(wmlPackage).configSimSunFont(wmlPackage);
WMLPACKAGE_WRITER.writeToPDF(wmlPackage, output);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(output);
}
}
use of org.docx4j.openpackaging.exceptions.Docx4JException in project flexmark-java by vsch.
the class DocxHelper method getNumPrFor.
// get a num pr for a list of given color (other than default)
//
public BigInteger getNumPrFor(BigInteger baseNumID, Color color) {
RPr rPr = getResolver().getEffectiveRPr(myOptions.PREFORMATTED_TEXT_STYLE);
if (rPr != null && rPr.getColor() != null) {
if (keepDiff(rPr.getColor(), color) == null) {
return baseNumID;
}
}
String colorID = String.format("%s:%s", baseNumID.toString(), color.getVal());
final BigInteger numID = myNumPrColorMap.get(colorID);
if (numID != null) {
return numID;
}
// we create a copy of the baseNubPr and add the changed color property
final NumberingDefinitionsPart ndp = myDocumentPart.getNumberingDefinitionsPart();
try {
final Numbering numbering = ndp.getContents();
final List<Numbering.Num> num = numbering.getNum();
final List<Numbering.AbstractNum> abstractNumList = numbering.getAbstractNum();
for (Numbering.AbstractNum abstractNum : abstractNumList) {
if (abstractNum.getAbstractNumId().compareTo(baseNumID) == 0) {
// we have our list to copy
// TODO: create a copy and set the color it the list's rpr.
}
}
return null;
} catch (Docx4JException e) {
e.printStackTrace();
}
return null;
}
Aggregations