Door Aspose.Total for Java te gebruiken, kunt u de conversiefunctie van PDF naar DIF in uw Java-toepassingen integreren in een proces van twee stappen. Ten eerste, door Aspose.PDF voor Java te gebruiken, kunt u PDF naar XLSX renderen. In de tweede stap kunt u XLSX naar DIF converteren met behulp van de Spreadsheet Programming API Aspose.Cells for Java .
Converteer PDF-bestand naar DIF via Java
Conversievereisten
U kunt Aspose.Total voor Java gemakkelijk rechtstreeks vanuit een op Maven gebaseerd project gebruiken en bevatten Aspose.PDF voor Java en Aspose.Cells voor Java in uw po.xml.
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// load PDF with an instance of Document | |
Document document = new Document("template.pdf"); | |
// save document in XLSX format | |
document.save("XlsxOutput.xlsx", SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
Workbook book = new Workbook("XlsxOutput.xlsx"); | |
// supports CSV, XLSB, XLSM, XLT, XLTX, XLTM, XLAM, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save XLSX as CSV | |
book.save("output.csv", SaveFormat.AUTO); |
Conversievereisten
Als uw PDF-document met een wachtwoord is beveiligd, kunt u het niet converteren naar DIF zonder het wachtwoord. Met behulp van de API kunt u eerst het beveiligde document openen met een geldig wachtwoord en het daarna converteren. Om het versleutelde bestand te openen, kunt u een nieuwe instantie van het Document class en geef bestandsnaam en wachtwoord door als argumenten.
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// open PDF document | |
Document doc = new Document("input.pdf", "Your@Password"); | |
// save PDF as XLSX format | |
document.save("XlsxOutput.xlsx", SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
Workbook book = new Workbook("XlsxOutput.xlsx"); | |
// supports CSV, XLSB, XLSM, XLT, XLTX, XLTM, XLAM, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save XLSX as CSV | |
book.save("output.csv", SaveFormat.AUTO); |
Converteer beveiligde PDF naar DIF via Java
Tijdens het converteren van het PDF-bestand naar DIF, kunt u ook een watermerk toevoegen aan uw uitvoer-DIF-bestandsformaat. Om een watermerk toe te voegen, maakt u een nieuwe werkmap om het geconverteerde XLSX-bestand te openen. Selecteer werkblad via de index, maak een vorm en gebruik de functie addTextEffect, stel kleuren, transparantie en meer in. Daarna kunt u uw XLSX-document opslaan als DIF met Watermark.
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// load PDF with an instance of Document | |
Document document = new Document("template.pdf"); | |
// save document in XLSX format | |
document.save("XlsxOutput.xlsx", SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
Workbook book = new Workbook("XlsxOutput.xlsx"); | |
// get the first default sheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// add Watermark | |
Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL", | |
"Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800); | |
// get the fill format of the word art | |
FillFormat wordArtFormat = wordart.getFill(); | |
// set the color | |
wordArtFormat.setOneColorGradient(Color.getRed(), 0.2, GradientStyleType.HORIZONTAL, 2); | |
// set the transparency | |
wordArtFormat.setTransparency(0.9); | |
// make the line invisible | |
LineFormat lineFormat = wordart.getLine(); | |
lineFormat.setWeight(0.0); | |
// supports CSV, XLSB, XLSM, XLT, XLTX, XLTM, XLAM, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save XLSX as CSV | |
book.save("output.csv", SaveFormat.AUTO); |