Skip to content

Instantly share code, notes, and snippets.

@aspose-pdf
Last active November 3, 2020 20:00
Show Gist options
  • Save aspose-pdf/474c352a71ac9477aa0d604fd32e1c6a to your computer and use it in GitHub Desktop.
Save aspose-pdf/474c352a71ac9477aa0d604fd32e1c6a to your computer and use it in GitHub Desktop.
This Gist contains examples of Aspose.Pdf for Java
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create a new instance of PsLoadOptions
com.aspose.pdf.LoadOptions options = new com.aspose.pdf.PsLoadOptions();
// Open .ps document with created load options
Document pdfDocument = new Document("input.ps", options);
// Save document
pdfDocument.save("PSToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//Instantiate Document Object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
//Instantiate document Collection object
doc.setCollection(new com.aspose.pdf.Collection());
//Get Files to add to Portfolio
com.aspose.pdf.FileSpecification xps = new com.aspose.pdf.FileSpecification("printoutput.xps");
com.aspose.pdf.FileSpecification word = new com.aspose.pdf.FileSpecification("sample.doc");
com.aspose.pdf.FileSpecification image = new com.aspose.pdf.FileSpecification("aspose.png");
com.aspose.pdf.FileSpecification pdf = new com.aspose.pdf.FileSpecification("363699.PDF");
//Provide description of the files
xps.setDescription("XPS File");
word.setDescription("Word File");
image.setDescription("Image File");
pdf.setDescription("PDF File");
//Add files to document collection
doc.getCollection().add(xps);
doc.getCollection().add(word);
doc.getCollection().add(image);
doc.getCollection().add(pdf);
//Save Portfolio document
doc.save("PortFoliio_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String myDir = "PathToDir";
// Load source PDF file
Document doc = new Document();
com.aspose.pdf.Page page = doc.getPages().add();
for (int i = 0; i < 4; i++)
{
TextFragment text = new TextFragment("Lorem ipsum \r\ndolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
text.getTextState().setFontSize(20);
page.getParagraphs().add(text);
}
doc.save(myDir + "DetermineLineBreak_out.pdf");
String notifications = doc.getPages().get_Item(1).getNotifications();
System.out.println(notifications);
// For complete examples project, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Android-via-java
String outputPath = "/mnt/sdcard/GradientColor_out.xlsx";
// Initialize Document object
Document doc = new Document();
// Add a new page
Page page = doc.getPages().add();
Graph graph = new Graph(300, 300);
// Add a Graph
page.getParagraphs().add(graph);
com.aspose.pdf.drawing.Rectangle rect = new com.aspose.pdf.drawing.Rectangle(0, 0, 300, 300);
graph.getShapes().add(rect);
rect.getGraphInfo().setFillColor(new com.aspose.pdf.Color());
// Use GradientAxialShadding for Gradient
GradientAxialShading gradientAxialShading = new GradientAxialShading(Color.getRed(), Color.getBlue());
gradientAxialShading.setStart(new Point(0, 0));
gradientAxialShading.setEnd(new Point(300, 300));
rect.getGraphInfo().getFillColor().setPatternColorSpace(gradientAxialShading);
// Save the document
doc.save(outputPath);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Delete all annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete();
// Save the update document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
for (TextSegment ts : (Iterable<TextSegment>) textFragment.getSegments()) {
StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.getPage(), ts.getRectangle());
// Create a new section in the Pdf object
strikeOut.setOpacity(.80);
strikeOut.setBorder(new Border(strikeOut));
strikeOut.setColor(com.aspose.pdf.Color.getRed());
textFragment.getPage().getAnnotations().add(strikeOut);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfBookmarkEditor
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkEditor.bindPdf("input.pdf");
// Extract bookmarks
Bookmarks bookmarks = bookmarkEditor.extractBookmarks();
for (Bookmark bookmark : (Iterable<Bookmark>) bookmarks) {
String strLevelSeprator = "";
for (int i = 1; i < bookmark.getLevel(); i++) {
strLevelSeprator += "---- ";
}
System.out.println("Title :- " + strLevelSeprator + bookmark.getTitle());
System.out.println("Page Number :- " + strLevelSeprator + bookmark.getPageNumber());
System.out.println("Page Action :- " + strLevelSeprator + bookmark.getAction());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String myDir = "PathToDir";
Document pdf = new Document(myDir + "Redis.pdf");
// configure font substitution
CustomSubst1 subst1 = new CustomSubst1();
FontRepository.getSubstitutions().add(subst1);
// Configure notifier to console
pdf.FontSubstitution.add(new Document.FontSubstitutionHandler() {
public void invoke(Font font, Font newFont) {
// print substituted FontNames into console
System.out.println("Warning: Font " + font.getFontName() + " was substituted with another font -> " + newFont.getFontName());
}
});
HtmlSaveOptions htmlSaveOps = new HtmlSaveOptions();
pdf.save(myDir + "Redis_1150_substitutedWithMSGothic_release.html", htmlSaveOps);
/**
* The class to implement font substitution
*/
private static class CustomSubst1 extends CustomFontSubstitutionBase {
public boolean trySubstitute(OriginalFontSpecification originalFontSpecification, /* out */com.aspose.pdf.Font[] substitutionFont) {
// 1. substitute Arial font with TimesNewRoman font
// if("Arial".equals(originalFontSpecification.getOriginalFontName())) {
// substitutionFont[0] = FontRepository.findFont("TimesNewRoman");
// return true;
// } else {
// return super.trySubstitute(originalFontSpecification, /*out*/substitutionFont);
// }
// 2. or substitute all the fonts with the MSGothic font
substitutionFont[0] = FontRepository.findFont("MSGothic");
return true;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// input HTML
String HTML = "< b >BIG TEXT< /b>< ol>SOME VALUE< /ol>< li >item1< /li >< li >item2 & 3 < /li >< /ol >";
// CSS for input HTML contents
String CSS = " *{font-weight : normal !important ; margin :0 !important ; padding:0 !important ; list-style-type:none !important}";
// instantiate Document instance
Document doc = new Document();
// add page to pages collection of Document object
Page page = doc.getPages().add();
// add HTMLFragment to paragraphs collection of PDF page
page.getParagraphs().add(new com.aspose.pdf.HtmlFragment(CSS + HTML));
// save resultant PDF file
doc.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// The path to the documents directory.
String dataDir = "pathToDir";
// Load existing PDf file
Document pdfDoc = new Document(dataDir + "input.pdf");
final Map names = new HashMap();
pdfDoc.FontSubstitution.add(new Document.FontSubstitutionHandler() {
public void invoke(Font font, Font newFont) {
// add substituted FontNames into map.
names.put(font.getFontName(), newFont.getFontName());
// or print the message into console
System.out.println("Warning: Font " + font.getFontName() + " was substituted with another font -> " + newFont.getFontName());
}
});
// instantiate HTMLSave option to save output in HTML
HtmlSaveOptions htmlSaveOps = new HtmlSaveOptions();
// save resultant file
pdfDoc.save(dataDir + "output.html", htmlSaveOps);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(PDFToEMF.class);
// instantiate EmfDevice object
EmfDevice device = new EmfDevice(new Resolution(96));
// load existing PDF file
Document doc = new Document(dataDir + "Input.pdf");
// save first page of PDF file as Emf image
device.process(doc.getPages().get_Item(1), dataDir + "output.emf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document doc = new Document("input.pdf");
// Convert to PDF/A3 compliant document
doc.convert("file.log", PdfFormat.PDF_A_3B, ConvertErrorAction.Delete);
// Save resultant document
doc.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
final String myDir = "PathToDir/";
Document doc = new Document(myDir + "outFile.pdf");
// Create callBack - logic recognize text for pdf images. Use outer OCR supports HOCR standard(http://en.wikipedia.org/wiki/HOCR).
// We have used free google tesseract OCR(http://en.wikipedia.org/wiki/Tesseract_%28software%29)
CallBackGetHocr cbgh = new CallBackGetHocr() {
@Override
public String invoke(java.awt.image.BufferedImage img) {
File outputfile = new File(myDir + "test.jpg");
try {
ImageIO.write(img, "jpg", outputfile);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
java.lang.Process process = Runtime.getRuntime().exec("tesseract" + " " + myDir + "test.jpg" + " " + myDir + "out hocr");
System.out.println("tesseract" + " " + myDir + "test.jpg" + " " + myDir + "out hocr");
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
// reading out.html to string
File file = new File(myDir + "out.html");
StringBuilder fileContents = new StringBuilder((int) file.length());
Scanner scanner = null;
try {
scanner = new Scanner(file);
String lineSeparator = System.getProperty("line.separator");
while (scanner.hasNextLine()) {
fileContents.append(scanner.nextLine() + lineSeparator);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
// deleting temp files
File fileOut = new File(myDir + "out.html");
if (fileOut.exists()) {
fileOut.delete();
}
File fileTest = new File(myDir + "test.jpg");
if (fileTest.exists()) {
fileTest.delete();
}
return fileContents.toString();
}
};
// End callBack
doc.convert(cbgh);
doc.save(myDir + "output971.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("Original.pdf");
// Optimize for web
pdfDocument.optimize();
// Save output document
pdfDocument.save("Optimized_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
BufferedImage originalImage = ImageIO.read(new File("AnyImage.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
baos.flush();
Page page2 = pdfDocument1.getPages().get_Item(i + 1);
page2.getResources().getImages().add(new ByteArrayInputStream(baos.toByteArray()));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Document Object
Document doc = new Document();
// Add a page to pages collection of document
Page page = doc.getPages().add();
// Load the source image file to Stream object
java.io.FileInputStream fs = new java.io.FileInputStream("source.tif");
// Set margins so image will fit, etc.
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
page.setCropBox(new Rectangle(0, 0, 400, 400));
// Create an image object
Image image1 = new Image();
// Add the image into paragraphs collection of the section
page.getParagraphs().add(image1);
// Set the image file stream
image1.setImageStream(fs);
// Save resultant PDF file
doc.save("Image2PDF_DOM.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF file
Document doc = new Document("input.pdf");
// Get rectangular region of first page of PDF
com.aspose.pdf.Rectangle rect = doc.getPages().get_Item(1).getRect();
// Instantiate PdfPageEditor instance
PdfPageEditor ppe = new PdfPageEditor();
// Bind source PDF
ppe.bindPdf("input.pdf");
// Set zoom coefficient
ppe.setZoom((float) (rect.getWidth() / rect.getHeight()));
// Update page size
ppe.setPageSize(new com.aspose.pdf.PageSize((float) rect.getHeight(), (float) rect.getWidth()));
// Save resultant PDF
ppe.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document instance
Document doc = new Document();
// add page to pages collection of PDF file
Page page = doc.getPages().add();
// create a loop to add 300 TextFragment instances
for (int i = 0; i < 300; i++)
// add TextFragment to paragraphs collection of first page of PDF
page.getParagraphs().add(new TextFragment("Pages count test"));
// process paragraphs to get page count information
doc.processParagraphs();
System.out.println("Number of Pages in PDF = " + doc.getPages().size());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Insert a empty page at the end of PDF
pdfDocument1.getPages().add();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// load the source PDF document
PdfFileInfo fileInfo = new PdfFileInfo("source.pdf");
// determine that source PDF file is Encrypted with password
Boolean encrypted = fileInfo.isEncrypted();
// MessageBox displays the current status related to PDf encryption
System.out.println(encrypted.toString());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
Document pdfDocument = new Document("input.pdf");
// create text stamp
TextStamp textStamp = new TextStamp("Sample Stamp");
// set whether stamp is background
textStamp.setBackground(true);
// set origin
textStamp.setXIndent(100);
textStamp.setYIndent(100);
// rotate stamp
textStamp.setRotate(Rotation.on90);
// set text properties
textStamp.getTextState().setFont(new FontRepository().findFont("Arial"));
textStamp.getTextState().setFontSize(14.0F);
textStamp.getTextState().setFontStyle(FontStyles.Bold);
textStamp.getTextState().setFontStyle(FontStyles.Italic);
textStamp.getTextState().setForegroundColor(Color.getGreen());
// add stamp to particular page
pdfDocument.getPages().get_Item(1).addStamp(textStamp);
// save output document
pdfDocument.save("TextStamp_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// iterate through all pages of PDF file
for (int Page_counter = 1; Page_counter <= pdfDocument.getPages().size(); Page_counter++) {
// add stamp to all pages of PDF file
pdfDocument.getPages().get_Item(Page_counter).addStamp(textStamp);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
for (Row row : (Iterable<Row>) table.getRows()) {
TextFragment updatedfragment = (TextFragment) row.getCells().get_Item(1).getParagraphs().get_Item(1);
String text;
if (updatedfragment != null)
text = updatedfragment.getText();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
Document pdfDocument = new Document("input.pdf");
// get particular page
Page pdfPage = pdfDocument.getPages().get_Item(1);
// create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.setPosition(new Position(100, 600));
// set text properties
textFragment.getTextState().setFont(FontRepository.findFont("Verdana"));
textFragment.getTextState().setFontSize(14);
textFragment.getTextState().setForegroundColor(Color.getBlue());
textFragment.getTextState().setBackgroundColor(Color.getGray());
// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text fragment to the PDF page
textBuilder.appendText(textFragment);
// save updated PDF file
pdfDocument.save("Text_Added.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Accept the absorber for particular PDF page
pdfDocument.getPages().get_Item(1).accept(textAbsorber);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
MemoryCleaner.clear();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// accept the absorber for first page of document
pdfDocument.getPages().get_Item(1).accept(textFragmentAbsorber);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Accept the absorber for first page of document
pdfDocument.getPages().get_Item(1).accept(textFragmentAbsorber);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Create TextAbsorber object to find all instances of the input search
// phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("\\d{4}-\\d{4}"); // like
// 1999-2000
// Set text search option to specify regular expression usage
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.setTextSearchOptions(textSearchOptions);
// Accept the absorber for first page of document
pdfDocument.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Loop through the fragments
for (TextFragment textFragment : (Iterable<TextFragment>) textFragmentCollection) {
// Update text and other properties
textFragment.setText("New Pharase");
textFragment.getTextState().setFont(FontRepository.findFont("Verdana"));
textFragment.getTextState().setFontSize(22);
textFragment.getTextState().setForegroundColor(Color.getBlue());
textFragment.getTextState().setBackgroundColor(Color.getGray());
}
// Save the updated PDF file
pdfDocument.save("Updated_Text.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Accept the absorber for the first page of the document.
pdfDocument.getPages().get_Item(1).accept(textFragmentAbsorber);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(?i)Line", new TextSearchOptions(true));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[\\S]+");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Accept the absorber for first page of document
pdfDocument.getPages().get_Item(1).accept(textFragmentAbsorber);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Accept the absorber for the first page of document.
pdfDocument.getPages().get_Item(1).accept(textFragmentAbsorber);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// The path to the resource directory.
String dataDir = Utils.getSharedDataDir(PDFToHTMLRenderPDFDataLayersAsSeparateHTMLLayerElement.class) + "PDFToHTML/";
// Open the PDF file
Document doc = new Document(dataDir + "input.pdf");
// Instantiate HTML SaveOptions object
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
// Specify to render PDF document layers separately in output HTML
htmlOptions.setConvertMarkedContentToLayers(true);
// Save the document
doc.save(dataDir + "output.html", htmlOptions);
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Open document
Document pdfDocument = new Document();
// Add page to PDF file
pdfDocument.getPages().add();
// Create LinkAnnotation object and specify rectangular region
LinkAnnotation link = new LinkAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(100, 100, 110, 110));
// Set color for Annotation object
link.setColor(com.aspose.pdf.Color.fromRgb(java.awt.Color.green));
// Specify the target PDF file and set page number
link.setAction(new GoToRemoteAction(dataDir + "SampleDataTable.pdf", 1));
// Add link annotation to first page of PDF file
pdfDocument.getPages().get_Item(1).getAnnotations().add(link);
//Save the document with link
pdfDocument.save(dataDir + "Hyerplink_to_PDF.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF document
Document doc = new Document(dataDir + "input.pdf");
// Initializes a new instance of the Table
Table table = new Table();
// Set the table border color as LightGray
table.setBorder(new BorderInfo(BorderSide.All, .5f, Color.getLightGray()));
// set the border for table cells
table.setDefaultCellBorder(new BorderInfo(BorderSide.All, .5f, Color.getLightGray()));
// create a loop to add 10 rows
for (int row_count = 1; row_count < 10; row_count++) {
// add row to table
Row row = table.getRows().add();
// add table cells
row.getCells().add("Column (" + row_count + ", 1)");
row.getCells().add("Column (" + row_count + ", 2)");
row.getCells().add("Column (" + row_count + ", 3)");
}
// Add table object to first page of input document
doc.getPages().get_Item(1).getParagraphs().add(table);
// Save updated document containing table object
doc.save(dataDir + "document_with_table.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//Instantiate the PDF object by calling its empty constructor
Document doc = new Document();
//Create the section in the PDF object
Page page = doc.getPages().add();
//Instantiate a table object
Table tab = new Table();
//Add the table in paragraphs collection of the desired section
page.getParagraphs().add(tab);
//Set with column widths of the table
tab.setColumnWidths("50 50 50");
tab.setColumnAdjustment(ColumnAdjustment.AutoFitToWindow);
//Set default cell border using BorderInfo object
tab.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 0.1F));
//Set table border using another customized BorderInfo object
tab.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 1F));
//Create MarginInfo object and set its left, bottom, right and top margins
com.aspose.pdf.MarginInfo margin = new com.aspose.pdf.MarginInfo();
margin.setTop(5f);
margin.setLeft(5f);
margin.setRight(5f);
margin.setBottom(5f);
//Set the default cell padding to the MarginInfo object
tab.setDefaultCellPadding(margin);
//Create rows in the table and then cells in the rows
com.aspose.pdf.Row row1 = tab.getRows().add();
row1.getCells().add("col1");
row1.getCells().add("col2");
row1.getCells().add("col3");
com.aspose.pdf.Row row2 = tab.getRows().add();
row2.getCells().add("item1");
row2.getCells().add("item2");
row2.getCells().add("item3");
//Save the PDF
doc.save(dataDir + "ResultantFile.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
pdf1.isBookmarked(true);
pdf1.setBookMarkLevel(1);
// Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();
Heading heading1 = new Heading(pdf1, sec1, 1);
Segment segment1 = new Segment(heading1);
heading1.getSegments().add(segment1);
heading1.isAutoSequence(true);
segment1.setContent("this is heading of level 1");
sec1.getParagraphs().add(heading1);
Heading heading2 = new Heading(pdf1, sec1, 2);
Segment segment2 = new Segment(heading2);
heading2.getSegments().add(segment2);
heading2.isAutoSequence(true);
segment2.setContent("this is heading of level 2");
sec1.getParagraphs().add(heading2);
Heading heading3 = new Heading(pdf1, sec1, 1);
Segment segment3 = new Segment(heading3);
heading3.getSegments().add(segment3);
heading3.isAutoSequence(false);
heading3.setLabelWidth(60);
heading3.setUserLabel("bullet1");
segment3.setContent("this is bullet style 1");
sec1.getParagraphs().add(heading3);
FileOutputStream out = new FileOutputStream(new File("testHeading.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a section to the Pdf document
Section sec1 = pdf1.getSections().add();
// Set the page border of the section using BorderInfo object
sec1.getPageInfo().setPageBorder(new BorderInfo(BorderSide.All, 0.2F));
// Set the left margin of page border of the section
sec1.getPageInfo().getPageBorderMargin().setLeft(20);
// Add a text paragraph to the paragraphs collection of the section
sec1.getParagraphs().add(new Text(sec1, "Hello World"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a new text paragraph and pass the text to its constructor as argument
Text t1 = new Text(sec1, "This is a text paragraph.");
// Set the id of the paragraph to "text1" so that it can referenced uniquely
// text1.ID = "text1";
// Add this left hanging text paragraph to the section
sec1.getParagraphs().add(t1);
// Create a graph object in the section with Width=100 and Height=400
Graph graph1 = new Graph(sec1, 400, 400);
// Add the circle in the shapes collection of the graph
graph1.getShapes().add(new Rectangle(100, 300, 200, 50));
// Add the graph object to the paragraphs collection of the section
sec1.getParagraphs().add(graph1);
// Instantiate attachment instance by calling its empty constructor
Attachment noteAttachment = new Attachment();
// Add attachment in the paragraphs collection of the section
sec1.getParagraphs().add(noteAttachment);
// Set attachment type to File using AttachmentType enumeration
noteAttachment.setAttachmentType(AttachmentType.Note);
// Set the content of the note annotation
noteAttachment.setNoteContent("This is a note." + pdf1.version());
// Set the title or heading of the note
noteAttachment.setNoteHeading("The title");
// set the note position
noteAttachment.setNoteWindowPosition(new RectangleArea(215, 770, 0, 0));
// Set the note to be opened when PDF document is opened
noteAttachment.isNoteOpen(true);
FileOutputStream out = new FileOutputStream(new File("Test.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object
Pdf pdf1 = new Pdf();
// Add a section to the Pdf
Section sec1 = pdf1.getSections().add();
// Add two columns in the section
sec1.getColumnInfo().setColumnCount(2);
// Set the spacing between the columns
sec1.getColumnInfo().setColumnSpacing("15");
// Set the widths of the columns
sec1.getColumnInfo().setColumnWidths("250 150");
// Save the Pdf
pdf1.save();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object
Pdf pdf1 = new Pdf();
// Add a section to the Pdf
Section sec1 = pdf1.getSections().add();
// Set the number of columns in the section to 3
sec1.getColumnInfo().setColumnCount(3);
// Save the Pdf
pdf1.save("Test1.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Row row1 = table1.getRows().add();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Row row1 = new Row(table1);
table1.getRows().add(row1);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Cell cell1 = row1.getCells().add("cell1");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Cell cell1 = new Cell(row1);
row1.getCells().add(cell1);
Text text1 = new Text(sec1);
cell1.getParagraphs().add(text1);
Segment segment1 = new Segment(text1);
text1.getSegments().add(segment1);
segment1.setContent("cell1");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Arc arc = new Arc(graph, 200, 50, 30, 30, 90);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Arc arc = new Arc(graph);
arc.setPosX(200);
arc.setPosY(50);
arc.setRadius(30);
arc.setAlpha(30);
arc.setBeta(90);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
cell1.setBorder(new BorderInfo(BorderSide.All.getValue(), 1, Color.getRed()));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
BorderInfo border2 = new BorderInfo();
GraphInfo graphInfo1 = new GraphInfo();
graphInfo1.setColor(Color.getRed());
border2.setLeft(graphInfo1);
border2.setRight(graphInfo1);
border2.setBottom(graphInfo1);
border2.setTop(graphInfo1);
cell1.setBorder(border2);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Circle circle = new Circle(graph, 200, 50, 30);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Circle circle = new Circle(graph);
circle.setPosX(200);
circle.setPosY(50);
circle.setRadius(30);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
float[] posArr = new float[] { 0, 0, 200, 80, 300, 40, 350, 90 };
Curve curve = new Curve(graph, posArr);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Curve curve = new Curve(graph);
curve.setPosition1X(0);
curve.setPosition1Y(0);
curve.setPosition2X(200);
curve.setPosition2Y(80);
curve.setPosition3X(300);
curve.setPosition3Y(40);
curve.setPosition4X(350);
curve.setPosition4Y(90);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Graph graph = new Graph(section, 100, 400);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Graph graph = new Graph(section);
graph.setGraphHeight(100);
graph.setGraphWidth(400);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
float[] posArr = new float[] { 100, 0, 300, 0 };
Line l1 = new Line(graph1, posArr);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Line l1 = new Line(graph);
float[] posArr = new float[4];
posArr[0] = 100;
posArr[1] = 0;
posArr[2] = 300;
posArr[3] = 0;
l1.setPositionArray(posArr);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Rectangle rectangle = new Rectangle(50, 10, 100, 50);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Rectangle rectangle = new Rectangle();
rectangle.setposX(50);
rectangle.setposY(10);
rectangle.setWidth(100);
rectangle.setHeight(50);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
text2.getSegments().add(new Segment(text2, "cell2"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Segment segment2 = new Segment(text2);
text2.getSegments().add(segment2);
segment2.setContent("cell2");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Text text1 = new Text(section, "this is text content");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Text text1 = new Text(section);
Segment segment1 = new Segment(text1);
text1.getSegments().add(segment1);
segment1.setContent("this is text content");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Instantiate attachment instance by calling its empty constructor
Attachment fileAttachment = new Attachment();
// Add attachment in the paragraphs collection of the section
sec1.getParagraphs().add(fileAttachment);
// Set attachment type to File using AttachmentType enumeration
fileAttachment.setAttachmentType(AttachmentType.File);
// Set the path of the attachment file
fileAttachment.setAttachedFileName("ccitt.tif");
// Set the file icon type to Graph
fileAttachment.setFileIconType(FileIconType.Graph);
// Set the color of the icon to Brown
fileAttachment.setIconColor(new Color("Blue"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Instantiate attachment instance by calling its empty constructor
Attachment noteAttachment = new Attachment();
// Add attachment in the paragraphs collection of the section
sec1.getParagraphs().add(noteAttachment);
// Set attachment type to File using AttachmentType enumeration
noteAttachment.setAttachmentType(AttachmentType.Note);
// Set the content of the note annotation
noteAttachment.setNoteContent("This is a note.");
// Set the title or heading of the note
noteAttachment.setNoteHeading("The title");
// Set the note to be opened when PDF document is opened
noteAttachment.isNoteOpen(true);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Instantiate attachment instance by calling its empty constructor
Attachment noteAttachment = new Attachment();
// Add attachment in the paragraphs collection of the section
sec1.getParagraphs().add(noteAttachment);
// Set attachment type to File using AttachmentType enumeration
noteAttachment.setAttachmentType(AttachmentType.Note);
// Set the content of the note annotation
noteAttachment.setNoteContent("This is a note.");
// Set the title or heading of the note
noteAttachment.setNoteHeading("The title");
// set the note position
noteAttachment.setNoteWindowPosition(new RectangleArea(36, 72, 0, 0));
// Set the note to be opened when PDF document is opened
noteAttachment.isNoteOpen(true);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate PDF object
Pdf pdf1 = new Pdf();
// bind the source PCL file with Pdf object
pdf1.bindPCL("input.pcl");
// save the resultant PDF document
pdf1.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a PDF Object
Pdf pdf = new Pdf();
// Call the Add method and pass JavaScript statement as an argument, to show Print Dialog
pdf.getJavaScripts().add("this.print(true);");
// Call the Add method and JavaScript statement as an argument, to show alert
pdf.getJavaScripts().add("app.alert(\"hello world\");");
FileOutputStream out = new FileOutputStream(new File("test.pdf"));
// Save Pdf Document
pdf.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Set the properties of Pdf instance
pdf1.setAuthor("Nayyer Shahbaz");
pdf1.setCreator("Aspose.Pdf");
pdf1.setKeywords("Hello World");
pdf1.setSubject("Example");
pdf1.setTitle("Example");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance
Pdf pdf1 = new Pdf();
// You may set OpenType poperty to full screen
pdf1.setOpenType(OpenType.FullScreen);
// Set PageTransitionType poperty of Pdf instance to a pre-defined desired value
pdf1.setPageTransitionType(PageTransitionType.Dissolve);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance
Pdf pdf1 = new Pdf();
// Set OpenType property of Pdf instance to any pre-defined value
pdf1.setOpenType(OpenType.Thumbnails);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance
Pdf pdf1 = new Pdf();
// Set the DestinationType property of Pdf instance to any pre-defined value
pdf1.setDestinationType(DestinationType.FitPage);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PDF document
Pdf pdf1 = new Pdf();
// Add a section into the PDF document
Section sec1 = pdf1.getSections().add();
// Add a text paragraph into the section
sec1.getParagraphs().add(new Text("Hello World"));
// Save the document
pdf1.save("HelloWorld.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create pdf instance
Pdf pdf1 = new Pdf();
// Bind the source XML
pdf1.bindXML("source.xml", null);
// Save the document
pdf1.save("HelloWorld-java.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a text paragraph inheriting text format settings from the section
Text text1 = new Text(sec1);
// Add the text paragraph to the section
sec1.getParagraphs().add(text1);
// Create 1st text segment
Segment s1 = new Segment("Symbols");
// Set the font name to the TextInfo.FontName property of segment
s1.getTextInfo().setFontName("Symbol");
// Add 1st text segment to the text paragraph
text1.getSegments().add(s1);
// Create 2nd text segment
Segment s2 = new Segment(" the first item");
// Add 2nd text segment to the text paragraph
text1.getSegments().add(s2);
// Save the Pdf
FileOutputStream output = new FileOutputStream(new File("..."));
pdf1.save(output);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a new text paragraph with an initial text segment "Aspose"
Text text1 = new Text(sec1, "Arial Bold MT");
// Set the font name of a segment in the text object
text1.getSegments().get_Item(0).getTextInfo().setFontName("Arial-BoldMT");
// Set the PFM file for the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontPfmFile("_AB_____.PFM");
// Set the font encoding file for the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontEncodingFile("CP1250.txt");
// Set the font encoding name of the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontEncoding("cp1250");
// Set the font outline file for the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontOutlineFile("_AB_____.PFB");
// Set IsFontEmbedded to true
text1.getSegments().get_Item(0).getTextInfo().isFontEmbedded(true);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a new text paragraph with an initial text segment "Aspose"
Text text1 = new Text(sec1, "Arial Bold MT");
// Set the font name of a segment in the text object
text1.getSegments().get_Item(0).getTextInfo().setFontName("Arial-BoldMT");
// Set the PFM file for the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontPfmFile("_AB_____.PFM");
// Set the font encoding file for the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontEncodingFile("CP1250.txt");
// Set the font encoding name of the text segment
text1.getSegments().get_Item(0).getTextInfo().setFontEncoding("cp1250");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a text object in the section
Text t1 = new Text(sec1, "Courier New Bold font");
// Set font name of a specific text segment to courier new
t1.getSegments().get_Item(0).getTextInfo().setFontName("Courier New");
// Set the font to bold
t1.getSegments().get_Item(0).getTextInfo().isTrueTypeFontBold(true);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a text object in the section
Text text1 = new Text(sec1, "Courier New font");
// Set font name of a specific text segment to courier new
text1.getSegments().get_Item(0).getTextInfo().setFontName("Courier New");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// To assign a unicode character by it's coding
Text text1 = new Text(sec1, String.valueOf(((char) 0x25a0)));
// Set font name of a specific text segment
text1.getSegments().get_Item(0).getTextInfo().setFontName("Times New Roman");
// Set unicode to a specific text segment
text1.getSegments().get_Item(0).getTextInfo().isUnicode(true);
// Get paragraph where to add text
sec1.getParagraphs().add(text1);
FileOutputStream out = new FileOutputStream(new File("Unicode.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf document by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a section to the Pdf document
Section sec1 = pdf1.getSections().add();
// Create a graph object in the section with Width=100 and Height=400
Graph graph1 = new Graph(sec1, 400, 400);
// Add the graph object to the paragraphs collection of the section
sec1.getParagraphs().add(graph1);
// Create a circle shape in the graph with X=200, Y=50 and Radius=30
Circle circle1 = new Circle(200, 50, 30);
// Add the circle in the shapes collection of the graph
graph1.getShapes().add(circle1);
// Set fill color of the circle using GraphInfo property of circle object
circle1.getGraphInfo().setFillColor(new aspose.pdf.Color("Green"));
// Enable the circle to be filled with the color specified above line
circle1.getGraphInfo().isFilled(true);
// Save the Pdf
FileOutputStream out = new FileOutputStream(new File("Unicode.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf document by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a section to the Pdf document
Section sec1 = pdf1.getSections().add();
// Create a graph object in the section with Width=100 and Height=400
Graph graph1 = new Graph(sec1, 400, 400);
// Add the graph object to the paragraphs collection of the section
sec1.getParagraphs().add(graph1);
// Create a rectangle shape with specified coordinates
Rectangle rect1 = new Rectangle(85, 100, 100, 50);
// Add the rectangle into the shapes collection of the 1st graph
graph1.getShapes().add(rect1);
// Create 2nd graph in the section with width=100 and height=400
Graph graph2 = new Graph(sec1, 400, 400);
// the Graph will display in a new page
graph2.isFirstParagraph(true);
// Add the graph object to the paragraphs collection of the section
sec1.getParagraphs().add(graph2);
// Create a rectangle shape with specified coordinates
Rectangle rect2 = new Rectangle(85, 100, 100, 50);
// Add the rectangle into the shapes collection of the 2nd graph
graph2.getShapes().add(rect2);
// Rotate the 2nd graph to 30 degree using RotationAngle property
graph2.getGraphInfo().setRotationAngle(30);
// Create 3rd graph in the section with width=100 and height=400
Graph graph3 = new Graph(sec1, 400, 400);
// the Graph will display in a new page
graph3.isFirstParagraph(true);
// Add 3rd graph into the paragraphs collection of the section
sec1.getParagraphs().add(graph3);
// Create a rectangle shape with specified coordinates
Rectangle rect3 = new Rectangle(85, 100, 100, 50);
// Add the rectangle into the shapes collection of the 3rd graph
graph3.getShapes().add(rect3);
// Adjust the horizontal size of the 3rd graph using ScalingRateX property
graph3.getGraphInfo().setScalingRateX(1.5f);
// Save the Pdf file
FileOutputStream out = new FileOutputStream(new File("Unicode.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf document object
Pdf pdf1 = new Pdf();
// Add a section to the Pdf document
Section sec1 = pdf1.getSections().add();
// Create a graph object in the section with Width=100 and Height=400
Graph graph1 = new Graph(sec1, 400, 400);
// Add the graph object to the paragraphs collection of the section
sec1.getParagraphs().add(graph1);
// Create an array containing the (X,Y) values of 4 control points
// required to position a curve
float[] posArr = new float[] { 0, 0, 200, 80, 300, 40, 350, 90 };
// Create a curve in the graph with the coordinates given as an array to
// the constructor of curve class
Curve curve1 = new Curve(posArr);
// Add the curve shape into the shapes collection of the graph
graph1.getShapes().add(curve1);
// Save the Pdf
FileOutputStream out = new FileOutputStream(new File("Unicode.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
/*
* Create 1st heading in the Pdf object's section with level=1. Then create
* a text segment and add it in the heading. Set its numbering style to "Arab"
* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
* If IsAutoSeguence property is set to true then the heading's sequence is
* controlled automatically by Aspose.Pdf. After setting all properties, add
* heading into the paragraphs collection of the section
*/
Heading heading1 = new Heading(pdf1, sec1, 1);
Segment segment1 = new Segment("Arab");
heading1.getSegments().add(segment1);
heading1.setHeadingType(HeadingType.Arab);
heading1.isAutoSequence(true);
sec1.getParagraphs().add(heading1);
/*
* Create 2nd heading in the Pdf object's section with level=2. Then create
* a text segment and add it in the heading. And don't forget to set
* IsAutoSequence=true.If IsAutoSeguence property is set to true then the
* heading's sequence is controlled automatically by Aspose.Pdf. After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading2 = new Heading(pdf1, sec1, 1);
Segment segment2 = new Segment("RomanUpper");
heading2.getSegments().add(segment2);
heading2.setHeadingType(HeadingType.RomanUpper);
heading2.isAutoSequence(true);
sec1.getParagraphs().add(heading2);
/*
* Create 3rd heading in the Pdf object's section with level=1. Then create
* a text segment and add it in the heading. Set its numbering style to "RomanLower"
* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
* If IsAutoSeguence property is set to true then the heading's sequence is
* controlled automatically by Aspose.Pdf. After setting all properties, add
* heading into the paragraphs collection of the section
*/
Heading heading3 = new Heading(pdf1, sec1, 1);
Segment segment3 = new Segment("RomanLower");
heading3.getSegments().add(segment3);
heading3.setHeadingType(HeadingType.RomanLower);
heading3.isAutoSequence(true);
sec1.getParagraphs().add(heading3);
/*
* Create 4th heading in the Pdf object's section with level=1. Then create a
* text segment and add it in the heading. Set its numbering style to "EnglishUpper"
* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
* If IsAutoSeguence property is set to true then the heading's sequence is
* controlled automatically by Aspose.Pdf. After setting all properties, add
* heading into the paragraphs collection of the section
*/
Heading heading4 = new Heading(pdf1, sec1, 1);
Segment segment4 = new Segment("EnglishUpper");
heading4.getSegments().add(segment4);
heading4.setHeadingType(HeadingType.EnglishUpper);
heading4.isAutoSequence(true);
sec1.getParagraphs().add(heading4);
/*
* Create 5th heading in the Pdf object's section with level=1. Then create a
* text segment and add it in the heading. Set its numbering style to "EnglishLower"
* using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
* If IsAutoSeguence property is set to true then the heading's sequence is
* controlled automatically by Aspose.Pdf. After setting all properties, add
* heading into the paragraphs collection of the section
*/
Heading heading5 = new Heading(pdf1, sec1, 1);
Segment segment5 = new Segment("EnglishLower");
heading5.getSegments().add(segment5);
heading5.setHeadingType(HeadingType.EnglishLower);
heading5.isAutoSequence(true);
sec1.getParagraphs().add(heading5);
//Save the Pdf
FileOutputStream out = new FileOutputStream(new File("Test.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
/*
* Create 1st heading in the Pdf object's section with level=1. Then create a text
* segment and add it in the heading. Set its UserLabel="98" to use a user defined
* bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading1 = new Heading(pdf1, sec1, 1);
Segment segment1 = new Segment(heading1);
heading1.getSegments().add(segment1);
segment1.setContent("Symbol");
heading1.setBulletFontName("Symbol");
heading1.setUserLabel("98");
sec1.getParagraphs().add(heading1);
/*
* Create 2nd heading in the Pdf object's section with level=2. Then create a text
* segment and add it in the heading. Set its UserLabel="99" to use a user defined
* bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading2 = new Heading(pdf1,sec1,2);
Segment segment2 = new Segment(heading2);
heading2.getSegments().add(segment2);
segment2.setContent("Symbol");
heading2.setBulletFontName("Symbol") ;
heading2.setUserLabel("99");
sec1.getParagraphs().add(heading2);
/*
* Create 3rd heading in the Pdf object's section with level=3. Then create a text
* segment and add it in the heading. Set its UserLabel="100" to use a user defined
* bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading3 = new Heading(pdf1,sec1,3);
Segment segment3 = new Segment(heading3);
heading3.getSegments().add(segment3);
segment3.setContent("Symbol");
heading3.setBulletFontName("Symbol") ;
heading3.setUserLabel("100");
sec1.getParagraphs().add(heading3);
//Save the Pdf
FileOutputStream out = new FileOutputStream(new File("Test.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
/*
* Create 1st heading in the Pdf object's section with level=1. Then create
* a text segment and add it in the heading. Set its StartNumber=6 to start
* the numbering from 6 and onwards. And don't forget to set IsAutoSequence=true.
* If IsAutoSeguence property is set to true then the heading's sequence is
* controlled automatically by Aspose.Pdf. After setting all properties, add
* heading into the paragraphs collection of the section
*/
Heading heading1 = new Heading(pdf1, sec1, 1);
Segment segment1 = new Segment("Level 1");
heading1.getSegments().add(segment1);
heading1.setStartNumber(6);
heading1.isAutoSequence(true);
sec1.getParagraphs().add(heading1);
/*
* Create 2nd heading in the Pdf object's section with level=2. Then create
* a text segment and add it in the heading. And don't forget to set
* IsAutoSequence=true.If IsAutoSeguence property is set to true then the
* heading's sequence is controlled automatically by Aspose.Pdf. After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading2 = new Heading(pdf1, sec1, 2);
Segment segment2 = new Segment("Level 2");
heading2.getSegments().add(segment2);
heading2.isAutoSequence(true);
sec1.getParagraphs().add(heading2);
/*
* Create 3rd heading in the Pdf object's section with level=3. Then create
* a text segment and add it in the heading. And don't forget to set
* IsAutoSequence=true.If IsAutoSeguence property is set to true then the
* heading's sequence is controlled automatically by Aspose.Pdf. After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading3 = new Heading(pdf1, sec1, 3);
Segment segment3 = new Segment("Level 3");
heading3.getSegments().add(segment3);
heading3.isAutoSequence(true);
sec1.getParagraphs().add(heading3);
//Save the Pdf
FileOutputStream out = new FileOutputStream(new File("test.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//Instntiate the Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create the section in the Pdf object
Section sec1 = pdf1.getSections().add();
/*
* Create 1st heading in the Pdf object's section with level=1. Then create
* a text segment and add it in the heading. Set its UserLabel="Bullet1" to
* use system defined bullet. After setting all properties, add heading into
* the paragraphs collection of the section
*/
Heading heading1 = new Heading(pdf1, sec1, 1);
Segment segment1 = new Segment(heading1);
heading1.getSegments().add(segment1);
segment1.setContent("Bullet1");
heading1.setLabel("Bullet1");
sec1.getParagraphs().add(heading1);
/*
* Create 2nd heading in the Pdf object's section with level=2. Then create
* a text segment and add it in the heading. And don't forget to set
* IsAutoSequence=true.If IsAutoSeguence property is set to true then the
* heading's sequence is controlled automatically by Aspose.Pdf. After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading2 = new Heading(pdf1, sec1, 2);
Segment segment2 = new Segment(heading2);
heading2.getSegments().add(segment2);
segment2.setContent("Bullet2");
heading2.setLabel("Bullet2");
sec1.getParagraphs().add(heading2);
/*
* Create 3rd heading in the Pdf object's section with level=3. Then create
* a text segment and add it in the heading. And don't forget to set
* IsAutoSequence=true.If IsAutoSeguence property is set to true then the
* heading's sequence is controlled automatically by Aspose.Pdf. After setting
* all properties, add heading into the paragraphs collection of the section
*/
Heading heading3 = new Heading(pdf1, sec1, 3);
Segment segment3 = new Segment(heading3);
heading3.getSegments().add(segment3);
segment3.setContent("Bullet3");
heading3.setLabel("Bullet3");
sec1.getParagraphs().add(heading3);
//Save the Pdf
FileOutputStream out = new FileOutputStream(new File("Test.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create an image object in the section
aspose.pdf.Image img1 = new aspose.pdf.Image();
// Add image object into the Paragraphs collection of the section
sec1.getParagraphs().add(img1);
// Specify the Image file type as JPEG
img1.getImageInfo().setImageFileType(ImageFileType.Jpeg);
// Set the path of image file
img1.getImageInfo().setFile("Apple.jpg");
// Set the path of image file
img1.getImageInfo().setTitle("JPEG image");
// Save the Pdf
pdf1.save("test.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf document
Section sec1 = new Section(pdf1);
// Create an image object in the section
Image img1 = new Image(sec1);
// Add image object into the Paragraphs collection of the section
sec1.getParagraphs().add(img1);
Path path = Paths.get("Sample.jpg");
byte[] data = Files.readAllBytes(path);
// Set the path of image file
img1.getImageInfo().setMemoryData(data);
// Save the Pdf
FileOutputStream out = new FileOutputStream(new File("Test.pdf"));
pdf1.save(out);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf document
Section sec1 = new Section(pdf1);
// Create an image object in the section
Image image1 = new Image(sec1);
// Set the path of image file
image1.getImageInfo().setFile("http://www.aspose.com/Images/Apple.jpg ");
// Set image title
image1.getImageInfo().setTitle("JPEG image");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf document
Section sec1 = new Section(pdf1);
// Instantiate an image object
Image img1 = new Image(sec1);
// Set the path of image file
img1.getImageInfo().setFile("resources/Bag11083_X.fax");
// Specify the image format
img1.getImageInfo().setImageFileType(ImageFileType.Ccitt);
// Set the image width
img1.getImageInfo().setCcittImageWidth(2560);
// Set the image height
img1.getImageInfo().setCcittImageHeight(1779);
// Set the desired scaling of the image
img1.setImageScale(0.1f);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a section in the pdf object
Section sec1 = pdf1.getSections().add();
// Create a HeaderFooter object for the section
HeaderFooter hf = new HeaderFooter(sec1);
// Set the HeaderFooter object to odd and even footers
sec1.setOddFooter(hf);
sec1.setEvenFooter(hf);
// Add a text paragraph containing current page number of total number of pages
hf.getParagraphs().add(new Text(hf, "page $p of $P"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a new section to the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a text paragraph with the reference of a section, sec1
Text text3 = new Text(sec1, "product 1 info ...");
// Add the text paragraph in the section
sec1.getParagraphs().add(text3);
// Set the text paragraph to be the first paragraph among the other ones
text3.isFirstParagraph(true);
// Assign and ID to the text paragraph
text3.setID("product1");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf = new Pdf();
// Create a section in the Pdf document
Section sec1 = pdf.getSections().add();
// Add a text paragraph in the section
sec1.getParagraphs().add(new Text(sec1, "page 1"));
// Create another text paragraph that has to be rendered
Text t2 = new Text(sec1, "page2");
// Set the IsFirstParagraph property of the text paragraph to true to render it to a new page
t2.isFirstParagraph(true);
// Add the text paragraph to be rendered to the section
sec1.getParagraphs().add(t2);
pdf.save(new FileOutputStream(new File("HelloWorld.pdf")));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Get section of the Pdf object
Section sec1 = pdf1.getSections().get_Item(0);
// Assign the image file path to BackgroundImageFile property of section
sec1.setBackgroundImageFile("apple.jpg");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a new section to the Pdf object
Section sec1 = pdf1.getSections().add();
// Instantiate HeaderFooter object and pass the Section reference in which the header or footer is to be added
HeaderFooter hf1 = new HeaderFooter(sec1);
// Set the header of odd pages of the PDF document
sec1.setOddHeader(hf1);
// Set the header of even pages of the PDF document
sec1.setEvenHeader(hf1);
// Instantiate a Text paragraph that will store the content to show as header
Text text = new Text(hf1, "header");
// Add the text object to the Paragraphs collection of HeaderFooter object to display header on the pages of PDF document
hf1.getParagraphs().add(text);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Get section of the Pdf object
Section sec1 = pdf1.getSections().get_Item(0);
// Instantiate the MarginInfo instance
MarginInfo marginInfo = new MarginInfo();
// Set the margin Top.
marginInfo.setTop(72);
// Set the margin Bottom. This value is in points, but if using XML to PDF conversion,
// other units like inches and centimeters can also be used i.e. 12inch or 12cm
marginInfo.setBottom(72);
// Set the margin Left.
marginInfo.setLeft(90);
// Set the margin Right.
marginInfo.setRight(90);
// Assign the marginInfo instance to Margin property of sec1.PageInfo
sec1.getPageInfo().setMargin(marginInfo);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Get section of the Pdf object
Section sec1 = pdf1.getSections().get_Item(0);
sec1.getPageInfo().setPageWidth(576);
sec1.getPageInfo().setPageWidth((float) 707.5);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Get section of the Pdf object
Section sec1 = pdf1.getSections().get_Item(0);
sec1.getPageInfo().setPageWidth(PageSize.A3_WIDTH);
sec1.getPageInfo().setPageHeight(PageSize.A3_HEIGHT);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a new section to the Pdf object
Section sec1 = pdf1.getSections().add();
// Add a Text
Text text = new Text(sec1, "hello");
sec1.getParagraphs().add(text);
// Set the value of left margin
text.getMargin().setLeft(150);
// Set the value of top margin and assign a negative value to it
text.getMargin().setTop(-100);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Assign a security instance to Pdf object
pdf1.setSecurity(new Security());
// Restrict annotation modification
pdf1.getSecurity().isAnnotationsModifyingAllowed(false);
// Restrict contents modification
pdf1.getSecurity().isContentsModifyingAllowed(false);
// Restrict copying the data
pdf1.getSecurity().isCopyingAllowed(false);
// Allow to print the document
pdf1.getSecurity().isCopyingAllowed(true);
// Restrict form filling
pdf1.getSecurity().isFormFillingAllowed(false);
// Add a section in the Pdf
Section sec1 = pdf1.getSections().add();
// Create a text paragraph
Text text1 = new Text(sec1, "this is text content");
// Set the top maring of text paragraph to 30
text1.getMargin().setTop(30);
// Add the text paragraph to the section
sec1.getParagraphs().add(text1);
// Save the Pdf
FileOutputStream fileOut = new FileOutputStream(new File("Test.pdf"));
pdf1.save(fileOut);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Assign a security instance to Pdf object
pdf1.setSecurity(new Security());
// Set encryption level to 128 bits
pdf1.getSecurity().setIs128BitsEncrypted(true);
// Add a section in the Pdf
Section sec1 = pdf1.getSections().add();
// Create a text paragraph
Text text1 = new Text(sec1, "this is text content");
// Set the top maring of text paragraph to 30
text1.getMargin().setTop(30);
// Add the text paragraph to the section
sec1.getParagraphs().add(text1);
// Save the Pdf
FileOutputStream fileOut = new FileOutputStream(new File("Test.pdf"));
pdf1.save(fileOut);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Assign a security instance to Pdf object
pdf1.setSecurity(new Security());
// Set the master password for the PDF document
pdf1.getSecurity().setMasterPassword("master");
// Set the user password for the PDF document
pdf1.getSecurity().setUserPassword("user");
// Add a section in the Pdf
Section sec1 = pdf1.getSections().add();
// Create a text paragraph
Text text1 = new Text(sec1, "this is text content");
// Set the top maring of text paragraph to 30
text1.getMargin().setTop(30);
// Add the text paragraph to the section
sec1.getParagraphs().add(text1);
// Save the Pdf
FileOutputStream fileOut = new FileOutputStream(new File("Test.pdf"));
pdf1.save(fileOut);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
table1.setIsFirstRowRepeated(true);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
table.setIsBroken(false);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a new section to the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a table
Table tab1 = new Table(sec1);
// Add the table into the paragraphs collection of section
sec1.getParagraphs().add(tab1);
// Set the column widths of the table
tab1.setColumnWidths("100 200");
// Set the default cell border using BorderInfo instance
tab1.setDefaultCellBorder(new aspose.pdf.BorderInfo(BorderSide.All));
// Add a row into the table
Row row1 = tab1.getRows().add();
// Add 1st cell in the row
row1.getCells().add("left cell");
// Add 2nd cell in the row
Cell cell2 = row1.getCells().add();
// Create a table to be nested with the reference of 2nd cell in the row
Table tab2 = new Table(sec1);
// Add the nested table into the paragraphs collection of the 2nd cell
cell2.getParagraphs().add(tab2);
// Set the column widths of the nested table
tab2.setColumnWidths("100 100");
// Create 1st row in the nested table
Row row21 = tab2.getRows().add();
// Create 1st cell in the 1st row of the nested table
Cell cell21 = row21.getCells().add("top cell");
// Set the column span of the 1st cell (in the 1st row of the nested table) to 2
cell21.setColumnsSpan(2);
// Create 2nd row in the nested table
Row row22 = tab2.getRows().add();
// Create 1st cell in the 2nd row of the nested table
row22.getCells().add("left bottom cell");
// Create 2nd cell in the 2nd row of the nested table
row22.getCells().add("right bottom cell");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate an object PDF class
Pdf pdf = new Pdf();
// add the section to PDF document sections collection
Section section = pdf.getSections().add();
// Instantiate a table object
Table table1 = new Table();
table1.getMargin().setTop(300);
// Add the table in paragraphs collection of the desired section
section.getParagraphs().add(table1);
// Set with column widths of the table
table1.setColumnWidths("100 100 100");
// Set default cell border using BorderInfo object
table1.setDefaultCellBorder(new BorderInfo((int) BorderSide.All, 0.1F));
// Set table border using another customized BorderInfo object
table1.setBorder(new BorderInfo((int) BorderSide.All, 1F));
// Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.setTop(5f);
margin.setLeft(5f);
margin.setRight(5f);
margin.setBottom(5f);
// Set the default cell padding to the MarginInfo object
table1.setDefaultCellPadding(margin);
// if you increase the counter to 17, table will break because it cannot be accommodated any more over this page
for (int RowCounter = 0; RowCounter <= 16; RowCounter++) {
// Create rows in the table and then cells in the rows
Row row1 = table1.getRows().add();
row1.getCells().add("col " + RowCounter + ", 1");
row1.getCells().add("col " + RowCounter + ", 2");
row1.getCells().add("col " + RowCounter + ", 3");
}
// get the Page Height information
float PageHeight = pdf.getPageSetup().getPageHeight();
// get the total height information of Page Top & Bottom margin, table Top margin and table height.
float TotalObjectsHeight = section.getPageInfo().getMargin().getTop() + section.getPageInfo().getMargin().getBottom() + table1.getMargin().getTop() + table1.getHeight(pdf);
// Display Page Height, Table Height, table Top margin and Page Top and Bottom margin information
System.out.println("PDF document Height = " + pdf.getPageSetup().getPageHeight() + "\nTop Margin Info = " + section.getPageInfo().getMargin().getTop() + "\nBottom Margin Info = " + section.getPageInfo().getMargin().getBottom() + "\n\nTable-Top Margin Info = " + table1.getMargin().getTop() + "\nAverage Row Height = " + table1.getRows().get_Item(0).getHeight(pdf) + " \nTable height " + table1.getHeight(pdf) + "\n ----------------------------------------" + "\nTotal Page Height =" + PageHeight + "\nCumulative height including Table =" + TotalObjectsHeight);
// check if we deduct the sum of Page top margin + Page Bottom margin + Table Top margin and table height from Page height and its less
// than 10 (an average row can be greater than 10)
if ((PageHeight - TotalObjectsHeight) <= 10)
// if the value is less than 10, then display the message. Which shows that another row cannot be placed and if we add new
// row, table will break. It depends upon the row height value.
System.out.println("Page Height - Objects Height < 10, so table will break");
// Save the pdf document
pdf.save("TableIsBrokenTest.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a new section to the Pdf object
Section sec1 = pdf1.getSections().add();
// Instantiate a table object
Table table = new Table(sec1);
// Add the table in paragraphs collection of the desired section
sec1.getParagraphs().add(table);
// Set with column widths of the table
table.setColumnWidths("50 50 50");
// Set default cell border using BorderInfo object
table.setDefaultCellBorder(new BorderInfo(BorderSide.All, 0.1F));
// Set table border using another customized BorderInfo object
table.setBorder(new BorderInfo(BorderSide.All, 1F));
// Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.setLeft(5f);
margin.setRight(5f);
margin.setTop(5f);
margin.setBottom(5f);
// Set the default cell padding to the MarginInfo object
table.setDefaultCellPadding(margin);
// Create rows in the table and then cells in the rows
Row row1 = table.getRows().add();
row1.getCells().add("col1");
row1.getCells().add("col2");
row1.getCells().add("col3");
Row row2 = table.getRows().add();
row2.getCells().add("item1");
row2.getCells().add("item2");
row2.getCells().add("item3");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
cell1.setColumnSpan(2);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
table.setColumnWidths("70 2cm");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
cell1.setFitWidth(2);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
// Add a new section to the Pdf object
Section sec1 = pdf1.getSections().add();
// Create Table instance
Table table = new Table(sec1);
// Add the table object in the paragraphs collection of the section
sec1.getParagraphs().add(table);
// Set with column widths of the table
table.setColumnWidths("50 50 50");
// Set default text color for the text contents of each cell in the table to blue
table.getDefaultCellTextInfo().setColor(new Color("Blue"));
// Set default left side padding of the cell
table.getDefaultCellPadding().setLeft(5);
// Set default border of the cell using BorderInfo object
table.setDefaultCellBorder(new BorderInfo(BorderSide.All, 0.1F));
// After setting default cell format information for the table, you can add rows and columns in the table
Row row1 = table.getRows().add();
row1.getCells().add("col1");
row1.getCells().add("col2");
row1.getCells().add("col3");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().get_Item(0);
// Instantiate Text object by calling one of its overloaded constructors that takes an instance of section as parameter
Text t3 = new Text(sec1);
t3.getTextInfo().setFontSize(16);
// Make a cloned object of TextInfo by calling its Clone method
TextInfo info1 = (TextInfo) t3.getTextInfo().clone;
// Modify the font side to 16 pt
info1.setFontSize(16);
// Set TextInfo property of the text paragraph to newly cloned instance "info1"
t3.setTextInfo(info1);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Set text color to blue in the whole section
sec1.getTextInfo().setColor(new Color("BLUE"));
// Add 1st paragraph (inheriting the text format settings from the section)
// to the section
sec1.getParagraphs().add(new Text(sec1, "paragraph 1 "));
// Add 2nd paragraph (inheriting the text format settings from the section)
// to the section
sec1.getParagraphs().add(new Text(sec1, "paragraph 2 "));
// Create 3rd paragraph (inheriting the text format settings from the section)
Text t3 = new Text(sec1);
// Create a segment "seg1" in the paragraph "t3"
Segment seg1 = new Segment(t3);
// Assign some content to the segment
seg1.setContent("paragraph 3 segment 1");
// Set the color of the segment to red
seg1.getTextInfo().setColor(new Color("RED"));
// Add segment (with red text color) to the paragraph
t3.getSegments().add(seg1);
// Create a new segment "seg2" in the paragraph "t3"
Segment seg2 = new Segment(t3);
// Assign some content to the segment
seg2.setContent("paragraph 3 segment 2");
// Set the color of the segment to green
seg1.getTextInfo().setColor(new Color("GREEN"));
// Add segment (with green text color) to the paragraph
t3.getSegments().add(seg2);
// Add 3rd text paragraph to the section with overridden text format settings
sec1.getParagraphs().add(t3);
// Add 4th paragraph (inheriting the text format settings from the section)
// to the section
sec1.getParagraphs().add(new Text(sec1, "paragraph 4"));
// Save the Pdf
FileOutputStream output = new FileOutputStream(new File("..."));
pdf1.save(output);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a new text paragraph
Text text1 = new Text(sec1, "Hello Aspose.Pdf");
// Set the BackgroundColor of the text paragraph to Red
text1.getTextInfo().setBackgroundColor(new Color("RED"));
// Add the text paragraph to the section
sec1.getParagraphs().add(text1);
// Save the Pdf
FileOutputStream output = new FileOutputStream(new File("..."));
pdf1.save(output);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create 1st text paragraph
Text text1 = new Text(sec1, "FillText mode");
// Set rendering mode to FillText
text1.getTextInfo().setRenderingMode(RenderingMode.FillText);
// Create 2nd text paragraph
Text text2 = new Text(sec1, "StrokeText mode (outline)");
// Set rendering mode to StrokeText
text2.getTextInfo().setRenderingMode(RenderingMode.StrokeText);
// Create 3rd text paragraph
Text text3 = new Text(sec1, "FillStrokeText mode");
// Set rendering mode to FillStrokeText
text3.getTextInfo().setRenderingMode(RenderingMode.FillStrokeText);
// Create 4th text paragraph
Text text4 = new Text(sec1, "InvisibleText mode");
// Set rendering mode to InvisibleText
text4.getTextInfo().setRenderingMode(RenderingMode.InvisibleText);
// Add 1st, 2nd and 3rd text paragraphs to the section
sec1.getParagraphs().add(text1);
sec1.getParagraphs().add(text2);
sec1.getParagraphs().add(text3);
sec1.getParagraphs().add(text4);
// Save the Pdf
FileOutputStream output = new FileOutputStream(new File("..."));
pdf1.save(output);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create a new text paragraph with an initial text segment "Aspose"
Text text1 = new Text(sec1, "Aspose");
// Add the text paragraph to the section
sec1.getParagraphs().add(text1);
// Create a new text segment into the text paragraph
Segment seg2 = text1.getSegments().add("TM");
seg2.getTextInfo().setFontSize(4);
// Set the vertical alignment of text segment "seg2" to Topline by setting
// passing false as argument to setIsBaseline
seg2.getTextInfo().isBaseline(false);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create 1st text paragraph
Text text1 = new Text(sec1, "Text underline");
// Set IsUnderline property of Text.TextInfo to true
text1.getTextInfo().isUnderline(true);
// Create 2nd text paragraph
Text text2 = new Text(sec1, "Text overline");
// OverLine is not supported at present
// text2.getTextInfo().setOverLine(true);
// Create 3rd text paragraph
Text text3 = new Text(sec1, "Text strike out");
// Set IsStrikeOut property of Text.TextInfo to true
text3.getTextInfo().isStrikeOut(true);
// Add 1st, 2nd and 3rd text paragraphs to the section
sec1.getParagraphs().add(text1);
sec1.getParagraphs().add(text2);
sec1.getParagraphs().add(text3);
// Save the Pdf
FileOutputStream output = new FileOutputStream(new File("..."));
pdf1.save(output);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Pdf pbject by calling its empty constructor
Pdf pdf = new Pdf();
// Create a new section in the Pdf object
Section sec1 = pdf.getSections().add();
// Set the left margin of the section
sec1.getPageInfo().getMargin().setLeft(110);
// Set the right margin of the section
sec1.getPageInfo().getMargin().setRight(120);
// Create a new text paragraph and pass the text to its constructor as argument
Text t2 = new Text(sec1, "A bool value that indicates" + "whether the TrueType font is bold. " + "This attribute is valid for TrueType fonts only.");
// Set the font size of the text in a text segment
t2.getSegments().get_Item(0).getTextInfo().setFontSize(16);
// Set the left margin of the text paragraph
t2.getMargin().setLeft(60);
// Set the first line indentation of the text paragraph to a negative value for
// producing the effect of left hanging text paragraph
t2.setFirstLineIndent(-6);
// Add this left hanging text paragraph to the section
sec1.getParagraphs().add(t2);
// Save the Pdf
FileOutputStream output = new FileOutputStream(new File("..."));
pdf.save(output);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document("input.pdf");
// Initialize ExcelSaveOptions
ExcelSaveOptions options = new ExcelSaveOptions();
// Set output format
options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);
// Save output file
doc.save("ouput.xlsx", options);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Initialize new PDF Document
Document doc = new Document();
com.aspose.pdf.Page page1 = doc.getPages().add();
// Create image
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
// Assign image file
image.setFile("aspose-logo.jpg");
// Create BBox element
com.aspose.pdf.Rectangle BBox = new com.aspose.pdf.Rectangle(30, 70, 300, 720);
// Create tagged figure element
com.aspose.pdf.taggedpdf.TaggedPdfFigureElement figureElement = new com.aspose.pdf.taggedpdf.TaggedPdfFigureElement(doc, image, BBox);
com.aspose.pdf.Rectangle BBox1 = new com.aspose.pdf.Rectangle(550, 570, 300, 720);
com.aspose.pdf.taggedpdf.TaggedPdfFigureElement figureElement1 = new com.aspose.pdf.taggedpdf.TaggedPdfFigureElement(doc, image, BBox1);
// Add tagged figure element into content
page1.getTaggedPdfContent().add(figureElement);
page1.getTaggedPdfContent().add(figureElement1);
// Save PDF Document
doc.save("PDFwithTaggedImage_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Initialize new PDF Document
Document doc = new Document();
com.aspose.pdf.Page page1 = doc.getPages().add();
com.aspose.pdf.Page page2 = doc.getPages().add();
com.aspose.pdf.Page page3 = doc.getPages().add();
// Create TextState and configure it
com.aspose.pdf.TextState ts = new com.aspose.pdf.TextState();
ts.setFont(com.aspose.pdf.FontRepository.findFont("Arial"));
// Creating tagged text element
// Supported tags P, H,H1-H6
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement1 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "text", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement2 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test1", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement3 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test2", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement4 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test3", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement5 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test4", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement6 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test5", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement7 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test6", ts);
com.aspose.pdf.taggedpdf.TaggedPdfTextElement textElement8 = new com.aspose.pdf.taggedpdf.TaggedPdfTextElement(doc, "P", "test7", ts);
// Add tagged text element to content
page1.getTaggedPdfContent().add(textElement1);
page1.getTaggedPdfContent().add(textElement2);
page1.getTaggedPdfContent().add(textElement3);
page2.getTaggedPdfContent().add(textElement4);
page2.getTaggedPdfContent().add(textElement5);
page3.getTaggedPdfContent().add(textElement6);
page3.getTaggedPdfContent().add(textElement7);
page3.getTaggedPdfContent().add(textElement8);
// Save PDF Document
doc.save("PDFwithTaggedText_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document documet = new Document("page-0000000004.pdf");
for (XImage image: documet.getPages().get_Item(1).getResources().getImages())
{
XImage.RawParameters rawParameters = image.getRawParameters();
System.out.println(rawParameters.Type);
System.out.println(rawParameters.Name);
System.out.println(rawParameters.BitsPerComponent);
System.out.println(rawParameters.DecodeParms);
System.out.println(rawParameters.Filter);
System.out.println(rawParameters.Height);
System.out.println(rawParameters.Width);
System.out.println(rawParameters.Length);
System.out.println(image.toString());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.bindPdf("input.pdf");
// crate rectangle
java.awt.Rectangle rect = new java.awt.Rectangle(50, 50, 100, 100);
// create annotation
contentEditor.createFreeText(rect, "Sample content", 1);
// save updated PDF file
contentEditor.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
PdfAnnotationEditor annotationEditor = new PdfAnnotationEditor();
annotationEditor.bindPdf("input.pdf");
// delete all annotations
annotationEditor.deleteAnnotations("Text");
// save updated PDF
annotationEditor.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfAnnotationEditor object
PdfAnnotationEditor AnnotationEditor = new PdfAnnotationEditor();
// open PDF document
AnnotationEditor.bindPdf("input.pdf");
// import annotations
int[] annotTypes = new int[] { com.aspose.pdf.AnnotationType.Text, com.aspose.pdf.AnnotationType.Highlight };
FileOutputStream fileStream = new FileOutputStream("annotations.xfdf");
AnnotationEditor.exportAnnotationsXfdf(fileStream, 1, 5, annotTypes);
// close objects
AnnotationEditor.close();
fileStream.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
bookmarkEditor.bindPdf("Input.pdf");
// create bookmark of all pages
bookmarkEditor.createBookmarks();
// save updated PDF file
bookmarkEditor.save("Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Path to Directorty
String myDir = "PathToDir";
// open document
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
bookmarkEditor.bindPdf("Input.pdf");
// create bookmark of all pages
bookmarkEditor.createBookmarks(Color.GREEN, true, true);
// save updated PDF file
bookmarkEditor.save(myDir + "Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfBookmarkEditor object
PdfBookmarkEditor bookmarkeditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkeditor.bindPdf("Input.pdf");
OutputStream os = new FileOutputStream("bookmark.xml");
bookmarkeditor.exportBookmarksToXML(os);
bookmarkeditor.dispose();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfBookmarkEditor object
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkEditor.bindPdf("Input.pdf");
// Export bookmarks
bookmarkEditor.exportBookmarksToXML("bookmarks.xml");
bookmarkEditor.dispose();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfBookmarkEditor object
PdfBookmarkEditor bookmarkeditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkeditor.bindPdf("Input.pdf");
InputStream is = new FileInputStream("bookmark.xml");
bookmarkeditor.importBookmarksWithXML(is);
bookmarkeditor.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfBookmarkEditor class
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkEditor.bindPdf("Input.pdf");
// Import bookmarks
bookmarkEditor.importBookmarksWithXML("bookmarks.xml");
// Save updated PDF file
bookmarkEditor.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfContentEditor object to manipulate contents
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf("input.pdf");
// create Javascript link
Rectangle rect7 = new Rectangle(50, 50, 200, 200);
java.awt.Color clr4 = new java.awt.Color(0, 255, 0);
String code = "app.alert('welcome to aspose!');";
editor.createJavaScriptLink(code, rect7, 1, clr4);
// save the output file
editor.save("JavaScriptAdded_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
PdfFileInfo fileInfo = new PdfFileInfo("input.pdf");
// get PDF information
System.out.println("Subject :-" + fileInfo.getSubject());
System.out.println("Title :-" + fileInfo.getTitle());
System.out.println("Keywords :-" + fileInfo.getKeywords());
System.out.println("Creator :-" + fileInfo.getCreator());
System.out.println("Creation Date :-" + fileInfo.getCreationDate());
System.out.println("Modification Date :-" + fileInfo.getModDate());
// find whether is it valid PDF and it is encrypted as well
System.out.println("Is Valid PDF :-" + fileInfo.isPdfFile());
// in case the file is encrypted, you need to provide file opening password
// as second argument to PdfFileInfo constructor
System.out.println("Is Encrypted :-" + fileInfo.isEncrypted());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfXmpMetadata object
PdfXmpMetadata xmpMetaData = new PdfXmpMetadata();
// bind PDF file to the object
xmpMetaData.bindPdf("TextAnnotation_output.pdf");
// get XMP Meta Data properties
System.out.println("Creation Date : " + xmpMetaData.getByDefaultMetadataProperties(DefaultMetadataProperties.CreateDate));
System.out.println("MetaData Date : " + xmpMetaData.getByDefaultMetadataProperties(DefaultMetadataProperties.MetadataDate));
System.out.println("Creator Tool : " + xmpMetaData.getByDefaultMetadataProperties(DefaultMetadataProperties.CreatorTool));
System.out.println("User Property Name : " + xmpMetaData.getXmpMetadata("customNamespace:UserPropertyName"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// load source PDF file
Document doc = new Document("xslt_output.pdf");
// instantiate PdfFileEditor object
PdfFileEditor editor = new PdfFileEditor();
// Specify Parameter to be used for resizing
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
// left margin = 10% of page width
PdfFileEditor.ContentsResizeValue.percents(0),
// new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
null,
// right margin is 10% of page
PdfFileEditor.ContentsResizeValue.percents(0),
// top margin = 10% of height
PdfFileEditor.ContentsResizeValue.percents(10),
// new contents height is calculated automatically (similar to width)
null,
// bottom margin is 10%
PdfFileEditor.ContentsResizeValue.percents(10));
// re-size contents of the first page of PDF file
editor.resizeContents(doc, new int[] { 1 }, parameters);
// save PDF file
doc.save("ContentsResized.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open source document
PdfFileInfo fileInfo = new PdfFileInfo("input.pdf");
// set PDF information
fileInfo.setAuthor("Nayyer");
fileInfo.setTitle("Hello World!");
fileInfo.setKeywords("Peace and Development");
fileInfo.setCreator("Aspose");
// save updated file
fileInfo.saveNewInfo("Updated_Info_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.bindPdf("input.pdf");
// change Viewer Preferences
contentEditor.changeViewerPreference(ViewerPreference.CENTER_WINDOW);
contentEditor.changeViewerPreference(ViewerPreference.HIDE_MENUBAR);
contentEditor.changeViewerPreference(ViewerPreference.PAGE_MODE_USE_NONE);
// save output PDF file
contentEditor.save("ChangePreference_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfXmpMetadata object
PdfXmpMetadata xmpMetaData = new PdfXmpMetadata();
// bind pdf file to the object
xmpMetaData.bindPdf("input.pdf");
// add create date
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.CreateDate, new java.util.Date());
// change meta data date
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.MetadataDate, new java.util.Date());
// add creator tool
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.CreatorTool, "Creator tool name");
// add Nick for MetaData
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.Nickname, "Aspose Nick");
// remove modify date
xmpMetaData.remove(DefaultMetadataProperties.ModifyDate);
// add user defined property
// step #1: register namespace prefix and URI
xmpMetaData.registerNamespaceURI("customNamespace", "http://www.customNameSpaces.com/ns/");
// step #2: add user property with the prefix
xmpMetaData.addItem("customNamespace:UserPropertyName", "UserPropertyValue");
// save xmp meta data in the pdf file
xmpMetaData.save("Updated_MetaData.pdf");
// close the object
xmpMetaData.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
Form form = new Form();
form.bindPdf("student.pdf");
// create fdf file.
FileOutputStream fdfOutputStream = new FileOutputStream("student.fdf");
// export data
form.exportFdf(fdfOutputStream);
// close file stream
fdfOutputStream.close();
// save updated document
form.dispose();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
Form form = new Form();
form.bindPdf("student.pdf");
// create XML file.
OutputStream xmlOutputStream = new FileOutputStream("student.xml");
// export data
form.exportXml(xmlOutputStream);
// close file stream
xmlOutputStream.close();
// dispose the form object
form.dispose();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
Form pdfForm = new Form();
// bind source PDF file
pdfForm.bindPdf("input.pdf");
// flatten fields
pdfForm.flattenAllFields();
// save output
pdfForm.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate PdfPageEditor class to get particular page region
PdfPageEditor editor = new PdfPageEditor();
// bind the source PDF file
editor.bindPdf("Exported.pdf");
// move the origin of PDF file to particular point
editor.movePosition(100, 200);
// create a memory stream object
java.io.FileOutputStream fout = new java.io.FileOutputStream("TempFile.pdf");
// save the updated document to stream object
editor.save(fout);
// create PdfConverter object
PdfConverter objConverter = new PdfConverter();
// bind input pdf file
objConverter.bindPdf(new java.io.FileInputStream("TempFile.pdf"));
// set StartPage and EndPage properties to the page number to
// you want to convert images from
objConverter.setStartPage(1);
objConverter.setEndPage(1);
// Counter
int page = 1;
// initialize the converting process
objConverter.doConvert();
// check if pages exist and then convert to image one by one
while (objConverter.hasNextImage())
objConverter.getNextImage("Specific_Region-Image" + page++ + ".jpeg");
// close the PdfConverter object
objConverter.close();
// close MemoryStream object holding the updated document
fout.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfConverter object
PdfConverter objConverter = new PdfConverter();
// bind input pdf file
objConverter.bindPdf("input.pdf");
// initialize the converting process
objConverter.doConvert();
int i = 1;
// check if pages exist and then convert to image one by one
while (objConverter.hasNextImage()) {
objConverter.getNextImage(i + ".jpg", ImageType.getJpeg());
i++;
}
// close the PdfConverter object
objConverter.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.bindPdf("Input.pdf");
// extract all the images
pdfExtractor.extractImage();
int imageCount = 1;
// get all the extracted images
while (pdfExtractor.hasNextImage()) {
pdfExtractor.getNextImage("Image" + imageCount + ".jpg");
imageCount++;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.bindPdf("Input.pdf");
// replace image on a particular page
pdfContentEditor.replaceImage(1, 1, "Aspose-logo.bmp");
// save output PDF
pdfContentEditor.save("Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfFileEditor object
PdfFileEditor pdfEditor = new PdfFileEditor();
// array of files
String[] filesArray = new String[2];
filesArray[0] = "input1.pdf";
filesArray[1] = "input2.pdf";
// concatenate files
pdfEditor.concatenate(filesArray, "output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfFileEditor object
PdfFileEditor editor = new PdfFileEditor();
// output stream
FileOutputStream outStream = new FileOutputStream("outFile");
// array of streams
FileInputStream[] inputStream = new FileInputStream[2];
inputStream[0] = new FileInputStream("inFile1");
inputStream[1] = new FileInputStream("inFile2");
// concatenate file
editor.concatenate(inputStream, outStream);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfFileEditor object
PdfFileEditor pdfEditor = new PdfFileEditor();
// concatenate files
pdfEditor.concatenate("input1.pdf", "input2.pdf", "output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
PdfFileEditor pfe = new PdfFileEditor();
pfe.setCopyOutlines(false);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfFileEditor Object
PdfFileEditor fileEditor = new PdfFileEditor();
// Open PDF Document
Document doc = new Document("Input.pdf");
// Specify Parameter to be used for resizing
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
// left margin = 10% of page width
PdfFileEditor.ContentsResizeValue.percents(10),
// new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
null,
// right margin is 10% of page
PdfFileEditor.ContentsResizeValue.percents(10),
// top margin = 10% of height
PdfFileEditor.ContentsResizeValue.percents(10),
// new contents height is calculated automatically (similar to width)
null,
// bottom margin is 10%
PdfFileEditor.ContentsResizeValue.percents(10));
// Resize Page Contents
fileEditor.resizeContents(doc, new int[] { 1, 3 }, parameters);
// save resized document
doc.save("Rsizecontents.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create PdfViewer object
PdfViewer viewer = new PdfViewer();
// Open input PDF file
viewer.openPdfFile("input.pdf");
// Set attributes for printing
viewer.setAutoResize(true); // Print the file with adjusted size
viewer.setAutoRotate(true); // Print the file with adjusted rotation
viewer.setPrintPageDialog(false); // Do not produce the page number dialog when printing
// gets a printjob object.
PrinterJob printJob = PrinterJob.getPrinterJob();
// gets the default page.
PageFormat pf = printJob.defaultPage();
// print PDF document
viewer.printDocument();
// close the Pdf file.
viewer.closePdfFile();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Path to Directory
String myDir = "PathToDir";
// create PdfFileSignature object and bind input PDF files
PdfFileSignature pdfSign = new PdfFileSignature();
pdfSign.bindPdf("input.pdf");
// create a rectangle for signature location
java.awt.Rectangle rect = new java.awt.Rectangle(100, 100, 200, 100);
// set signature appearance
pdfSign.setSignatureAppearance(myDir + "imgLogoPdf1.png");
// create any of the three signature types
PKCS1 signature = new PKCS1(myDir + "temp.pfx", "password");
// PKCS7 signature = new PKCS7(myDir + "temp.pfx", "password"); // PKCS#7 or
// PKCS7Detached signature = new PKCS7Detached("temp.pfx", "password"); // PKCS#7 detached
pdfSign.sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);
// save output PDF file
pdfSign.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create DocumentPrivileges object
DocumentPrivilege privilege = DocumentPrivilege.getForbidAll();
privilege.setChangeAllowLevel(1);
privilege.setAllowPrint(true);
privilege.setAllowCopy(true);
// Open PDF document
PdfFileSecurity fileSecurity = new PdfFileSecurity();
fileSecurity.bindPdf("input.pdf");
// Set document privileges
fileSecurity.setPrivilege(privilege);
fileSecurity.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
PdfFileStamp fileStamp = new PdfFileStamp();
fileStamp.bindPdf("input.pdf");
// get total number of pages
int totalPages = new PdfFileInfo("input.pdf").getNumberOfPages();
// create formatted text for page number
FormattedText formattedText = new FormattedText("Page # Of " + totalPages, Color.BLUE, Color.GRAY, com.aspose.pdf.facades.FontStyle.Courier, EncodingType.Winansi, false, 14);
// set starting number for first page; you might want to start from 2 or more
fileStamp.setStartingNumber(1);
// add page number
fileStamp.addPageNumber(formattedText, 0);
// save updated PDF file
fileStamp.save("output.pdf");
fileStamp.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create PdfFileMend object to add text
PdfFileMend mender = new PdfFileMend();
mender.bindPdf("Input.pdf");
// create formatted text
FormattedText text = new FormattedText("Aspose - Your File Format Experts!", Color.BLUE, Color.GRAY, FontStyle.Courier, EncodingType.Winansi, true, 14);
// set whether to use Word Wrap or not and using which mode
mender.setWordWrap(true);
mender.setWrapMode(WordWrapMode.Default);
// add text in the PDF file
mender.addText(text, 1, 100, 200, 200, 400);
// save output PDF
mender.save("Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.bindPdf("Input.pdf");
// specify start and end pages
pdfExtractor.setStartPage(2);
pdfExtractor.setEndPage(3);
// use parameterless ExtractText method
pdfExtractor.extractText();
// Save the extracted text to a text file
pdfExtractor.getText("Output.txt");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.bindPdf("Input.pdf");
// use parameterless ExtractText method
pdfExtractor.extractText();
int pageNumber = 1;
while (pdfExtractor.hasNextPageText()) {
pdfExtractor.getNextPageText("output" + pageNumber + ".txt");
pageNumber++;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.bindPdf("Input.pdf");
// use parameterless ExtractText method
pdfExtractor.extractText();
// Save the extracted text to a text file
pdfExtractor.getText("Output.txt");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.bindPdf("Input.pdf");
// replace text on all pages
pdfContentEditor.replaceText("Hello", "World");
// save output PDF
pdfContentEditor.save("ReplaceTextOnAllPages.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open input PDF
PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.bindPdf("Input.pdf");
// replace text on a particular page
pdfContentEditor.replaceText("Content", 2, "World");
// save output PDF
pdfContentEditor.save("ReplaceTextOnAllPages.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document(path + "PdfWithAcroForm.pdf");
TextBoxField text = (TextBoxField) doc.getForm().get_Item("textField");
text.getActions().setOnFormat(new JavascriptAction("AFNumber_Format(2, 0, 0, \"\", true);"));
text.getActions().setOnModifyCharacter(new JavascriptAction("AFNumber_Keystroke(2, 0, 0, \"\", true);"));
text.getActions().setOnValidate(new JavascriptAction("AFRange_Validate(true, 1, true, 100);"));
text.setValue("100");
doc.save(path + "formatted.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a PDF Document
Document doc = new Document("inuput.pdf");
// Adding JavaScript at Document Level
// Instantiate JavascriptAction with desried JavaScript statement
JavascriptAction javaScript = new JavascriptAction("this.print({bUI:true,bSilent:false,bShrinkToFit:true});");
// Assign JavascriptAction object to desired action of Document
doc.setOpenAction(javaScript);
// Adding JavaScript at Page Level
doc.getPages().get_Item(2).getActions().setOnOpen(new JavascriptAction("app.alert('page 2 is opened')"));
doc.getPages().get_Item(2).getActions().setOnClose(new JavascriptAction("app.alert('page 2 is closed')"));
// Save PDF Document
doc.save("JavaScript-Added.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Printing
document.getActions().setAfterPrinting(new JavascriptAction("app.alert('File was printed')"));
// Saving
document.getActions().setAfterSaving(new JavascriptAction("app.alert('File was Saved')"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document();
Page page = doc.getPages().add();
Layer layer = new Layer("oc1", "Red Line");
layer.getContents().add(new Operator.SetRGBColorStroke(1, 0, 0));
layer.getContents().add(new Operator.MoveTo(500, 700));
layer.getContents().add(new Operator.LineTo(400, 700));
layer.getContents().add(new Operator.Stroke());
page.setLayers(new ArrayList());
page.getLayers().add(layer);
layer = new Layer("oc2", "Green Line");
layer.getContents().add(new Operator.SetRGBColorStroke(0, 1, 0));
layer.getContents().add(new Operator.MoveTo(500, 750));
layer.getContents().add(new Operator.LineTo(400, 750));
layer.getContents().add(new Operator.Stroke());
page.getLayers().add(layer);
layer = new Layer("oc3", "Blue Line");
layer.getContents().add(new Operator.SetRGBColorStroke(0, 0, 1));
layer.getContents().add(new Operator.MoveTo(500, 800));
layer.getContents().add(new Operator.LineTo(400, 800));
layer.getContents().add(new Operator.Stroke());
page.getLayers().add(layer);
doc.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load an existing PDF files
com.aspose.pdf.Document doc = new com.aspose.pdf.Document("source.pdf");
// Get access to first page of PDF file
com.aspose.pdf.Page tocPage = doc.getPages().insert(1);
// Create object to represent TOC information
com.aspose.pdf.TocInfo tocInfo = new com.aspose.pdf.TocInfo();
com.aspose.pdf.TextFragment title = new com.aspose.pdf.TextFragment("Table Of Contents");
title.getTextState().setFontSize(20);
title.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
// Set the title for TOC
tocInfo.setTitle(title);
tocPage.setTocInfo(tocInfo);
// Create string objects which will be used as TOC elements
String[] titles = new String[4];
titles[0] = "First page";
titles[1] = "Second page";
titles[2] = "Third page";
titles[3] = "Fourth page";
for (int i = 0; i < 4; i++) {
// Create Heading object
com.aspose.pdf.Heading heading2 = new com.aspose.pdf.Heading(1);
com.aspose.pdf.TextSegment segment2 = new com.aspose.pdf.TextSegment();
heading2.setTocPage(tocPage);
heading2.getSegments().add(segment2);
// Specify the destination page for heading object
heading2.setDestinationPage(doc.getPages().get_Item(i + 2));
// Destination page
heading2.setTop(doc.getPages().get_Item(i + 2).getRect().getHeight());
// Destination coordinate
segment2.setText(titles[i]);
// Add heading to page containing TOC
tocPage.getParagraphs().add(heading2);
}
// Save the updated document
doc.save("TOC_Output_Java.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open the source PDF document
Document pdfDocument = new Document("input.pdf");
// Create annotation
TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.getPages().get_Item(1), new Rectangle(200, 400, 400, 600));
// Set annotation title
textAnnotation.setTitle("Sample Annotation Title");
// Set annotation subject
textAnnotation.setSubject("Sample Subject");
textAnnotation.setState(AnnotationState.Accepted);
// Specify the annotation contents
textAnnotation.setContents("Sample contents for the annotation");
textAnnotation.setOpen(true);
textAnnotation.setIcon(TextIcon.Key);
Border border = new Border(textAnnotation);
border.setWidth(5);
border.setDash(new Dash(1, 1));
textAnnotation.setBorder(border);
textAnnotation.setRect(new Rectangle(200, 400, 400, 600));
// Add annotation in the annotations collection of the page
pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
// Save the output file
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document();
doc.getPages().add();
FreeTextAnnotation annotation = new FreeTextAnnotation(doc.getPages().get_Item(1), new Rectangle(50, 600, 250, 650), new DefaultAppearance("Helvetica", 16, java.awt.Color.RED));
annotation.setContents("ABCDEFG");
annotation.getCharacteristics().setBorder(java.awt.Color.RED);
annotation.setFlags(AnnotationFlags.Print | AnnotationFlags.NoView);
doc.getPages().get_Item(1).getAnnotations().add(annotation);
doc.save("Invisible_Annotation.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Delete particular annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete();
// Save the update document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Delete particular annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete(1);
// Save the update document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF document
Document pdfDocument = new Document("Annotated_output.pdf");
// Loop through all the annotations
for (int annotCounter = 1; annotCounter <= pdfDocument.getPages().get_Item(1).getAnnotations().size(); annotCounter++) {
// Get annotation properties
System.out.printf("Full Name :- " + pdfDocument.getPages().get_Item(annotCounter).getAnnotations().get_Item(annotCounter).getFullName());
System.out.printf("Page Number :- " + pdfDocument.getPages().get_Item(annotCounter).getAnnotations().get_Item(annotCounter).getPage().getNumber());
System.out.printf("Contents :- " + pdfDocument.getPages().get_Item(annotCounter).getAnnotations().get_Item(annotCounter).getContents());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Get particular annotation
TextAnnotation textAnnotation = (TextAnnotation) pdfDocument.getPages().get_Item(1).getAnnotations().get_Item(1);
// Get annotation properties
System.out.printf("Title :- " + textAnnotation.getTitle());
System.out.printf("Subject :- " + textAnnotation.getSubject());
System.out.printf("Contents :- " + textAnnotation.getContents());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
PdfAnnotationEditor editor = new PdfAnnotationEditor();
editor.bindPdf("HelloWorld.pdf");
// redact certain page region
editor.redactArea(1, new Rectangle(100, 100, 20, 70), java.awt.Color.WHITE);
editor.save("Redaction_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document("HelloWorld.pdf");
Rectangle rect = new Rectangle(200, 500, 300, 600);
RedactionAnnotation annot = new RedactionAnnotation(doc.getPages().get_Item(1), rect);
annot.setFillColor(Color.getBlack());
annot.setBorderColor(Color.getYellow());
annot.setColor(Color.getBlue());
annot.setOverlayText("REDACTED");
annot.setTextAlignment(HorizontalAlignment.Center);
annot.setRepeat(true);
doc.getPages().get_Item(1).getAnnotations().add(annot);
doc.save("Redaction_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Document object
Document document = new Document("test.pdf");
// Create TextFragment Absorber instance to search particular text fragment
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Estoque");
// Iterate through pages of PDF document
for (int i = 1; i <= document.getPages().size(); i++) {
// Get first page of PDF document
Page page = document.getPages().get_Item(i);
page.accept(textFragmentAbsorber);
}
// Create a collection of Absorbed text
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Iterate on above collection
for (int j = 1; j <= textFragmentCollection.size(); j++) {
TextFragment textFragment = textFragmentCollection.get_Item(j);
// Get rectangular dimensions of TextFragment object
Rectangle rect = new Rectangle((float) textFragment.getPosition().getXIndent(), (float) textFragment.getPosition().getYIndent(), (float) textFragment.getPosition().getXIndent() + (float) textFragment.getRectangle().getWidth(), (float) textFragment.getPosition().getYIndent() + (float) textFragment.getRectangle().getHeight());
// Instantiate StrikeOut Annotation instance
StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.getPage(), rect);
// Set opacity for annotation
strikeOut.setOpacity(.80);
// Set the border for annotation instance
strikeOut.setBorder(new Border(strikeOut));
// Set the color of annotation
strikeOut.setColor(Color.getRed());
// Add annotation to annotations collection of TextFragment
textFragment.getPage().getAnnotations().add(strikeOut);
}
// Save updated document
document.save("StrikeOut.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Set up a new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification("sample.txt", "Sample text file");
// Add an attachment to document's attachment collection
pdfDocument.getEmbeddedFiles().add(fileSpecification);
// Save the updated document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Delete all attachments
pdfDocument.getEmbeddedFiles().delete();
// Save the updated file
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// get reference of source/input file
java.nio.file.Path path = java.nio.file.Paths.get("input.pdf");
// read all the contents from source file into ByteArray
byte[] data = java.nio.file.Files.readAllBytes(path);
// create an instance of Stream object from ByteArray contents
InputStream is = new ByteArrayInputStream(data);
// Instantiate Document object from stream instance
Document pdfDocument = new Document(is);
// setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification("test.txt", "Sample text file");
// Specify Encoding property setting it to FileEncoding.None
fileSpecification.setEncoding(FileEncoding.None);
// add attachment to document's attachment collection
pdfDocument.getEmbeddedFiles().add(fileSpecification);
// save new output
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Get particular embedded file
FileSpecification fileSpecification = pdfDocument.getEmbeddedFiles().get_Item(1);
// Get the file properties
System.out.println("Name:-" + fileSpecification.getName());
System.out.println("Description:- " + fileSpecification.getDescription());
System.out.println("Mime Type:-" + fileSpecification.getMIMEType());
// Check if parameter object contains the parameters
if (fileSpecification.getParams() != null) {
System.out.println("CheckSum:- " + fileSpecification.getParams().getCheckSum());
System.out.println("Creation Date:- " + fileSpecification.getParams().getCreationDate());
System.out.println("Modification Date:- " + fileSpecification.getParams().getModDate());
System.out.println("Size:- " + fileSpecification.getParams().getSize());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Get particular embedded file
FileSpecification fileSpecification = pdfDocument.getEmbeddedFiles().get_Item(1);
// Get the file properties
System.out.printf("Name: - " + fileSpecification.getName());
System.out.printf("\nDescription: - " + fileSpecification.getDescription());
System.out.printf("\nMime Type: - " + fileSpecification.getMIMEType());
// Get attachment form PDF file
try {
InputStream input = fileSpecification.getContents();
File file = new File(fileSpecification.getName());
// Create path for file from pdf
file.getParentFile().mkdirs();
// Create and extract file from pdf
java.io.FileOutputStream output = new java.io.FileOutputStream(fileSpecification.getName(), true);
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer)))
output.write(buffer, 0, n);
// Close InputStream object
input.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
// Close Document object
pdfDocument.dispose();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open the source PDF document
Document pdfDocument = new Document("input.pdf");
// Create a bookmark object
OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.getOutlines());
pdfOutline.setTitle("Test Outline");
pdfOutline.setItalic(true);
pdfOutline.setBold(true);
// Set the destination page number
pdfOutline.setAction(new GoToAction(pdfDocument.getPages().get_Item(1)));
// Add a bookmark in the document's outline collection.
pdfDocument.getOutlines().add(pdfOutline);
// Save the update document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Create a parent bookmark object
OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.getOutlines());
pdfOutline.setTitle("Parent Outline");
pdfOutline.setItalic(true);
pdfOutline.setBold(true);
// Set the destination page number
pdfOutline.setDestination(new GoToAction(pdfDocument.getPages().get_Item(2)));
// Create a child bookmark object
OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.getOutlines());
pdfChildOutline.setTitle("Child Outline");
pdfChildOutline.setItalic(true);
pdfChildOutline.setBold(true);
// Set the destination page number for child outline
pdfChildOutline.setDestination(new GoToAction(pdfDocument.getPages().get_Item(10)));
// Add child bookmark to parent bookmark's collection
pdfOutline.add(pdfChildOutline);
// Add parent bookmark to the document's outline collection.
pdfDocument.getOutlines().add(pdfOutline);
// Save output
pdfDocument.save("PDF_with_ChildBookmarks.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String path = "";
Document pdfDocument = new Document(path + "PdfViewerPreference_Changed_out.pdf");
// Editing existing bookmark
OutlineItemCollection pdfOutline = pdfDocument.getOutlines().get_Item(1);
pdfOutline.setDestination(
// 1st variant new FitVExplicitDestination(pdfDocument.getPages().get_Item(1),0)
// 2nd variant. You can tweak using the bookmark links using different parameters of ExplicitDestinationType
ExplicitDestination.createDestination(pdfDocument.getPages().get_Item(1), ExplicitDestinationType.FitH, new double[] { pdfDocument.getPages().get_Item(1).getMediaBox().getHeight() }));
pdfDocument.save();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String path = "";
Document pdfDocument = new Document(path + "PdfViewerPreference_Changed_out.pdf");
OutlineItemCollection pdfOutline_new = new OutlineItemCollection(pdfDocument.getOutlines());
pdfOutline_new.setTitle("Test bookmark");
pdfOutline_new.setItalic(true);
pdfOutline_new.setBold(true);
// Set the destination page number and position
pdfOutline_new.setAction(new GoToAction(new FitVExplicitDestination(pdfDocument.getPages().get_Item(2), 0)));
// Add bookmark in the document's outline collection.
pdfDocument.getOutlines().add(pdfOutline_new);
pdfDocument.save();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf(path + "test.pdf");
editor.changeViewerPreference(ViewerPreference.PAGE_LAYOUT_SINGLE_PAGE);
editor.save(path + "test_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Delete all bookmarks
pdfDocument.getOutlines().delete();
// Save output
pdfDocument.save("NoBookmarks.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("source.pdf");
// Delete a specific bookmarks
pdfDocument.getOutlines().delete("Child Outline");
// Save output
pdfDocument.save("noBookmark.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create Document instance
Document doc = new Document("BookmarkIssue_8_1_0.pdf");
// set page view mode i.e. show thumbnails, full-screen, show attachment panel
doc.setPageMode(PageMode.UseOutlines);
// print total count of Bookmarks in PDF file
System.out.println(doc.getOutlines().size());
// traverse through each Outline item in outlines collection of PDF file
for (int counter = 1; counter <= doc.getOutlines().size(); counter++) {
// set open status for outline item
doc.getOutlines().get_Item(counter).setOpen(true);
}
// save the PDF file
doc.save("Bookmarks_Expanded.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Loop through all the bookmarks
for (OutlineItemCollection outlineItem : (Iterable<OutlineItemCollection>) pdfDocument.getOutlines()) {
System.out.println("Title :- " + outlineItem.getTitle());
System.out.println("Is Italic :- " + outlineItem.getItalic());
System.out.println("Is Bold :- " + outlineItem.getBold());
System.out.println("Color :- " + outlineItem.getColor());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("BookmarkInheritZoom.pdf");
// Get a bookmark object
OutlineItemCollection pdfOutline = pdfDocument.getOutlines().get_Item(1);
// Set the target page as 10
pdfOutline.setDestination(new GoToAction(pdfDocument.getPages().get_Item(2)));
// Save output
pdfDocument.save("Bookmarkupdated_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document(path + "PdfWithAcroForm.pdf");
TextBoxField text = (TextBoxField) doc.getForm().get_Item("textField");
text.getActions().setOnFormat(new JavascriptAction("AFNumber_Format(2, 0, 0, \"\", true);"));
text.getActions().setOnModifyCharacter(new JavascriptAction("AFNumber_Keystroke(2, 0, 0, \"\", true);"));
text.getActions().setOnValidate(new JavascriptAction("AFRange_Validate(true, 1, true, 100);"));
text.setValue("100");
doc.save(path + "formatted.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Printing
document.getActions().setAfterPrinting(new JavascriptAction("app.alert('File was printed')"));
// Saving
document.getActions().setAfterSaving(new JavascriptAction("app.alert('File was Saved')"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a PDF Document
Document doc = new Document("inuput.pdf");
// Adding JavaScript at Document Level
// Instantiate JavascriptAction with desried JavaScript statement
JavascriptAction javaScript = new JavascriptAction("this.print({bUI:true,bSilent:false,bShrinkToFit:true});");
// Assign JavascriptAction object to desired action of Document
doc.setOpenAction(javaScript);
// Adding JavaScript at Page Level
doc.getPages().get_Item(2).getActions().setOnOpen(new JavascriptAction("app.alert('page 2 is opened')"));
doc.getPages().get_Item(2).getActions().setOnClose(new JavascriptAction("app.alert('page 2 is closed')"));
// Save PDF Document
doc.save("JavaScript-Added.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document document = new Document("input.pdf");
com.aspose.pdf.RgbToDeviceGrayConversionStrategy strategy = new com.aspose.pdf.RgbToDeviceGrayConversionStrategy();
for (int idxPage = 1; idxPage <= document.getPages().size(); idxPage++) {
Page page = document.getPages().get_Item(idxPage);
strategy.convert(page);
}
document.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate LoadOption object using EPUB load option
EpubLoadOptions optionsepub = new EpubLoadOptions();
// Create Document object
Document docepub = new Document("wasteland.epub", optionsepub);
// Save the resultant PDF document
docepub.save("wasteland.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Specify the The base path/url for the html file which serves as images database
String basePath = "pdftest";
HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);
// Load HTML file
Document doc = new Document(basePath + "EmailDemo_updated.html", htmloptions);
// Save HTML file
doc.save("Web+URL_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
HtmlLoadOptions options = new HtmlLoadOptions();
options.CustomLoaderOfExternalResources = new LoadOptions.ResourceLoadingStrategy() {
public LoadOptions.ResourceLoadingResult invoke(String resourceURI) {
// Creating clear template resource for replacing:
LoadOptions.ResourceLoadingResult res = new LoadOptions.ResourceLoadingResult(new byte[] {});
// Return empty byte array in case i.imgur.com server
if (resourceURI.contains("i.imgur.com")) {
return res;
} else {
// Process resources with default resource loader
res.LoadingCancelled = true;
return res;
}
}
};
// Do conversion
Document pdfDocument = new Document("in.html", options);
pdfDocument.save("out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate LoadOption object using PCL load option
PclLoadOptions loadoptions = new PclLoadOptions();
// Create Document object
Document doc = new Document("Document.pcl", loadoptions);
// Save the resultant PDF document
doc.save("test1-converted.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load PDF document
Document pdfDocument = new Document("input.pdf");
// Instantiate XPS Save options
XpsSaveOptions saveOptions = new XpsSaveOptions();
// Save the XPS document
pdfDocument.save("output.xps", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open the source PDF document
Document pdfDocument = new Document("SampleDataTable.pdf");
// Save the file into Microsoft document format
pdfDocument.save("TableHeightIssue.doc", SaveFormat.Doc);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF file
Document doc = new Document("input.pdf");
// Instantiate Doc SaveOptions instance
DocSaveOptions saveOptions = new DocSaveOptions();
// Set output file format as DOCX
saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);
// Save resultant DOCX file
doc.save("resultant.docx", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
// Path of input PDF document
String filePath = "source.pdf";
// Instantiate the Document object
Document document = new Document(filePath);
// Create DocSaveOptions object
DocSaveOptions saveOption = new DocSaveOptions();
// Set the recognition mode as Flow
saveOption.setMode(DocSaveOptions.RecognitionMode.Flow);
// Set the Horizontal proximity as 2.5
saveOption.setRelativeHorizontalProximity(2.5f);
// Enable the value to recognize bullets during conversion process
saveOption.setRecognizeBullets(true);
// Save the resultant DOC file
document.save("Resultant.doc", saveOption);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load PDF document
Document pdfDocument = new Document("BlueBackground.pdf");
// Instantiate EPUB Save options
EpubSaveOptions options = new EpubSaveOptions();
// Specify the layout for contents
options.ContentRecognitionMode = EpubSaveOptions.RecognitionMode.Flow;
// Save the EPUB document
pdfDocument.save("BlueBackground.epub", options);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load PDF document
Document pdfDocument = new Document("LegacyProduct_test.pdf");
// Instantiate ExcelSave Option object
ExcelSaveOptions excelsave = new ExcelSaveOptions();
// Save the output to XLS format
pdfDocument.save("ConvertedFile.xls", excelsave);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document instance
Document doc = new Document();
// add page to PDF file
doc.getPages().add();
// load XML file
FileSpecification fileSpecification = new FileSpecification(myDir + "attachment.xml", "Sample xml file");
// Add attachment to document's attachment collection
doc.getEmbeddedFiles().add(fileSpecification);
// perform PDF/A_3a conversion
doc.convert(myDir + "log.xml", PdfFormat.PDF_A_3A/* or PDF_A_3B */, ConvertErrorAction.Delete);
// save final PDF file
doc.save(myDir + "attached_PDFA_3A.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
String myDir = "pathToDir";
Document pdfDocument = new Document("input.pdf");
// Convert to PDF/A compliant document
pdfDocument.validate("Validation_log.xml", PdfFormat.PDF_A_1B);
pdfDocument.convert("Conversion_log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
// Save updated document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document doc = new Document("input.pdf");
// Convert to PDF/A2_a compliant document
doc.convert("file.log", PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);
// Save resultant document
doc.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document doc = new Document("input.pdf");
// Convert to PDF/A3 compliant document
doc.convert("file.log", PdfFormat.PDF_A_3A, ConvertErrorAction.Delete);
// Save resultant document
doc.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load PDF document
Document doc = new Document("input.pdf");
// Instantiate PptxSaveOptions instance
PptxSaveOptions pptx_save = new PptxSaveOptions();
// Save the output in PPTX format
doc.save("output.pptx", pptx_save);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// load PDF document
Document doc = new Document("Input.pdf");
// instantiate an object of SvgSaveOptions
SvgSaveOptions saveOptions = new SvgSaveOptions();
// do not compress SVG image to Zip archive
saveOptions.CompressOutputToZipArchive = false;
// resultant file name
String outFileName = "Output.svg";
// save the output in SVG files
doc.save(outFileName, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document object
Document doc = new Document("input.pdf");
// save the output in XML format
doc.save("resultant.xml", SaveFormat.Xml);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String file = "Document.svg";
// Instantiate LoadOption object using SVG load option
LoadOptions options = new SvgLoadOptions();
// Create Document object
Document document = new Document(file, options);
// Save the resultant PDF document
document.save("Result.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Source PDF file
java.io.File file = new java.io.File("AsposeDocument.txt");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
// System.out.println(file.exists() + "!!");
// InputStream in = resource.openStream();
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); // no doubt here is 0
// Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
System.out.println("read " + readNum + " bytes,");
}
} catch (java.io.IOException ex) {
}
byte[] bytes = bos.toByteArray();
java.io.ByteArrayInputStream srcStream = new java.io.ByteArrayInputStream(bytes);
java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(srcStream));
String line;
StringBuilder builder = new StringBuilder(5024);
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (java.io.IOException e) {
} finally {
try {
reader.close();
} catch (java.io.IOException e) {
}
// Instantiate a Document object by calling its empty constructor
Document doc = new Document();
// Add a new page in Pages collection of Document
Page page = doc.getPages().add();
// Create an instance of TextFragmet and pass the text from reader object to its constructor as argument
TextFragment text = new TextFragment(builder.toString());
// text.TextState.Font = FontRepository.FindFont("Arial Unicode MS");
// Add a new text paragraph in paragraphs collection and pass the TextFragment object
page.getParagraphs().add(text);
// Save resultant PDF file
doc.save("TExtFile_TexttoPDF.pdf");
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document object
Document doc = new Document();
// bind source XML file
doc.bindXml("Source.xml");
// get reference of page object from XML
Page page = (Page) doc.getObjectById("mainSection");
// get reference of first TextSegment with ID boldHtml
TextSegment segment = (TextSegment) doc.getObjectById("boldHtml");
// get reference of second TextSegment with ID strongHtml
segment = (TextSegment) doc.getObjectById("strongHtml");
// update TextSegement text
segment.setText("TestSegment");
// save resultant PDF file
doc.save("Resultant.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate LoadOption object using XPS load option
LoadOptions options = new XpsLoadOptions();
// Create document object
Document document = new Document("printoutput.xps", options);
// Save the resultant PDF document
document.save("resultant.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate XSLFO load options instance
XslFoLoadOptions xslLoadOptions = new XslFoLoadOptions();
// Open document
Document doc = new Document("samplefile.fo", xslLoadOptions);
// Save PDF document
doc.save("XSL_FO.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document("Input.pdf");
// tune conversion parameters
HtmlSaveOptions newOptions = new HtmlSaveOptions();
newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
newOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.setSplitIntoPages(false);// force write HTMLs of all pages into one output document
newOptions.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy() {
@Override
public void invoke(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo) {
// TODO Auto-generated method stub
byte[] resultHtmlAsBytes = new byte[(int) htmlSavingInfo.ContentStream.getLength()];
htmlSavingInfo.ContentStream.read(resultHtmlAsBytes, 0, resultHtmlAsBytes.length);
// here You can use any writable stream, file stream is taken just as example
FileOutputStream fos;
try {
fos = new FileOutputStream("PDFtoHTML.html");
fos.write(resultHtmlAsBytes);
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
// we can use some non-existing file name all real saving will be done in CustomerHtmlSavingStrategy
String outHtmlFile = "SomeUnexistingFile.html";
doc.save(outHtmlFile, newOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
String outHtmlFile = "resultant.html";
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setFixedLayout(true);
// save images in PNG format instead of SVG
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
// save output as HTML
pdfDocument.save(outHtmlFile, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF file
Document doc = new Document("input.pdf");
// Instantiate HTML Save options object
HtmlSaveOptions newOptions = new HtmlSaveOptions();
// Enable option to embed all resources inside the HTML
newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
// This is just optimization for IE and can be omitted
newOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
// Output file path
String outHtmlFile = "Single_output.html";
// Save the output file
doc.save(outHtmlFile, newOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load PDF document
Document pdfDocument = new Document("input.pdf");
// Instantiate HtmlSaveOptions instance
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
// Specify the folder to save images during conversion process
// Save the resultant HTML file
pdfDocument.save("resultant.html", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load PDF document
Document doc = new Document("source.pdf");
// Instantiate HtmlSaveOptions instance
HtmlSaveOptions html = new HtmlSaveOptions();
// Specify the folder to save images during conversion process
html.setSplitIntoPages(true);
// Save the resultant HTML file
doc.save("resultant.html", html);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open the document
com.aspose.pdf.Document doc = new com.aspose.pdf.Document("input.pdf");
// Iterate through all the pages
for (com.aspose.pdf.Page page : (Iterable<com.aspose.pdf.Page>) doc.getPages()) {
if (page.getResources().getFonts() != null) {
for (com.aspose.pdf.Font pageFont : (Iterable<com.aspose.pdf.Font>) page.getResources().getFonts()) {
// Check if font is already embedded
if (!pageFont.isEmbedded())
pageFont.isEmbedded(true);
}
}
// Check for the Form objects
for (com.aspose.pdf.XForm form : (Iterable<com.aspose.pdf.XForm>) page.getResources().getForms()) {
if (form.getResources().getFonts() != null) {
for (com.aspose.pdf.Font formFont : (Iterable<com.aspose.pdf.Font>) form.getResources().getFonts()) {
// Check if the font is embedded
if (!formFont.isEmbedded())
formFont.isEmbedded(true);
}
}
}
}
// Save the document
doc.save("FontEmbedded_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String outFile = "EmbedFonts.pdf";
// Instantiate Pdf object by calling its empty constructor
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// Create a section in the Pdf object
com.aspose.pdf.Page page = doc.getPages().add();
com.aspose.pdf.TextFragment fragment = new com.aspose.pdf.TextFragment("");
com.aspose.pdf.TextSegment segment = new com.aspose.pdf.TextSegment(" This is a sample text using Custom font.");
com.aspose.pdf.TextState ts = new com.aspose.pdf.TextState();
ts.setFont(FontRepository.findFont("Univers Condensed"));
ts.getFont().setEmbedded(true);
segment.setTextState(ts);
fragment.getSegments().add(segment);
page.getParagraphs().add(fragment);
doc.save(outFile);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// load source PDF Portfolio
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Portfolio_output.pdf");
// get collection of embedded files
com.aspose.pdf.EmbeddedFileCollection embeddedFiles = pdfDocument.getEmbeddedFiles();
// iterate through individual file of Portfolio
for (int counter = 1; counter <= pdfDocument.getEmbeddedFiles().size(); counter++) {
com.aspose.pdf.FileSpecification fileSpecification = embeddedFiles.get_Item(counter);
try {
InputStream input = fileSpecification.getContents();
File file = new File(fileSpecification.getName());
// create path for file from pdf
file.getParentFile().mkdirs();
// create and extract file from pdf
java.io.FileOutputStream output = new java.io.FileOutputStream(fileSpecification.getName(), true);
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer)))
output.write(buffer, 0, n);
// close InputStream object
input.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// delete all files from Embedded files collection
pdfDocument.getEmbeddedFiles().delete();
// save updated document
pdfDocument.save("NotFolio.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Create a field
TextBoxField textBoxField1 = new TextBoxField(pdfDocument.getPages().get_Item(1), new Rectangle(100, 200, 300, 300));
// Set the field name
textBoxField1.setPartialName("textbox1");
// Set the field value
textBoxField1.setValue("Text Box");
// Create a border object
Border border = new Border(textBoxField1);
// Set the border width
border.setWidth(5);
// Set the border dash style
border.setDash(new Dash(1, 1));
// Set the field border
textBoxField1.setBorder(border);
// Add the field to the document
pdfDocument.getForm().add(textBoxField1, 1);
// Save the modified PDF
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// create Document object
Document doc = new Document();
// add page to document object
doc.getPages().add();
// instantiate ComboBox Field object
ComboBoxField combo = new ComboBoxField(doc.getPages().get_Item(1), new Rectangle(100, 600, 150, 616));
// add option to ComboBox
combo.addOption("Red");
combo.addOption("Yellow");
combo.addOption("Green");
combo.addOption("Blue");
// add combo box object to form fields collection of document object
doc.getForm().add(combo);
// save the PDF document
doc.save("ComboBox_Added.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("Input.pdf");
// Create a field
SignatureField signatureField = new SignatureField(pdfDocument.getPages().get_Item(1), new Rectangle(100, 200, 300, 300));
signatureField.setPartialName("signature1");
// Add field to the document
pdfDocument.getForm().add(signatureField, 1);
// Save modified PDF
pdfDocument.save("Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document object
Document pdfDocument = new Document();
// add a page to PDF file
pdfDocument.getPages().add();
// instantiate RadioButtonField object with page number as argument
RadioButtonField radio = new RadioButtonField(pdfDocument.getPages().get_Item(1));
// add first radio button option and also specify its origin using Rectangle object
radio.addOption("Test", new Rectangle(20, 720, 40, 740));
// add second radio button option
radio.addOption("Test1", new Rectangle(120, 720, 140, 740));
// add radio button to form object of Document object
pdfDocument.getForm().add(radio);
// save the PDF file
pdfDocument.save("RadioButtonSample.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document();
Page page = doc.getPages().add();
Table table = new Table();
table.setColumnWidths("120 120 120");
page.getParagraphs().add(table);
Row r1 = table.getRows().add();
Cell c1 = r1.getCells().add();
Cell c2 = r1.getCells().add();
Cell c3 = r1.getCells().add();
RadioButtonField rf = new RadioButtonField(page);
rf.setPartialName("radio");
doc.getForm().add(rf, 1);
RadioButtonOptionField opt1 = new RadioButtonOptionField();
RadioButtonOptionField opt2 = new RadioButtonOptionField();
RadioButtonOptionField opt3 = new RadioButtonOptionField();
opt1.setOptionName("Item1");
opt2.setOptionName("Item2");
opt3.setOptionName("Item3");
opt1.setWidth(15);
opt1.setHeight(15);
opt2.setWidth(15);
opt2.setHeight(15);
opt3.setWidth(15);
opt3.setHeight(15);
rf.add(opt1);
rf.add(opt2);
rf.add(opt3);
opt1.setBorder(new Border(opt1));
opt1.getBorder().setWidth(1);
opt1.getBorder().setStyle(BorderStyle.Solid);
opt1.getCharacteristics().setBorder(Color.BLACK);
opt1.getDefaultAppearance().setTextColor(Color.RED);
opt1.setCaption(new TextFragment("Item1"));
opt2.setBorder(new Border(opt2));
opt2.getBorder().setWidth(1);
opt2.getBorder().setStyle(BorderStyle.Solid);
opt2.getCharacteristics().setBorder(Color.BLACK);
opt2.getDefaultAppearance().setTextColor(Color.RED);
opt2.setCaption(new TextFragment("Item2"));
opt3.setBorder(new Border(opt3));
opt3.getBorder().setWidth(1);
opt3.getBorder().setStyle(BorderStyle.Solid);
opt3.getCharacteristics().setBorder(Color.BLACK);
opt3.getDefaultAppearance().setTextColor(Color.RED);
opt3.setCaption(new TextFragment("Item3"));
c1.getParagraphs().add(opt1);
c2.getParagraphs().add(opt2);
c3.getParagraphs().add(opt3);
doc.save("RadioButtonField.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Get a field
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("textbox1");
// Set the tooltip for textfield
textBoxField.setAlternateName("Text box tool tip");
// Save modified document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load dynamic XFA form
Document document = new Document("XFAform.pdf");
// Set the form fields type as standard AcroForm
document.getForm().setType(FormType.Standard);
// Save the resultant PDF
document.save("Standard_AcroForm.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Delete a named field by name
pdfDocument.getForm().delete("textbox1");
// Save the modified PDF
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Get a field
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("textbox1");
// Set the field value
textBoxField.setValue("Value of TextField");
// Save the updated document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("Field_Added_output.pdf");
// Create rectangle object to get fields in that area
Rectangle rectangle = new Rectangle(35, 703, 126, 753);
// Get the PDF form
Form form = pdfDocument.getForm();
// Get fields in the rectangular area
Field[] fields = form.getFieldsInRect(rectangle);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("Field_Added_output.pdf");
// Get a field
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("textbox1");
// Get the field name
System.out.printf("PartialName :-" + textBoxField.getPartialName());
// Get the field value
System.out.printf("Value :-" + textBoxField.getValue());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdf = new Document("Form.pdf");
Field[] fields = pdf.getForm().getFields();
for (int i = 0; i < fields.length; i++) {
System.out.println("Form field: " + fields[i].getFullName());
System.out.println("Form field: " + fields[i].getValue());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document object
Document pdfDocument = new Document();
// add a page to PDF file
Page page = pdfDocument.getPages().add();
// instatiate RadioButtonField object with page number as argument
RadioButtonField radio = new RadioButtonField(pdfDocument.getPages().get_Item(1));
// add first radio button option and also specify its origin using Rectangle object
RadioButtonOptionField opt1 = new RadioButtonOptionField(page, new Rectangle(0, 0, 20, 20));
RadioButtonOptionField opt2 = new RadioButtonOptionField(page, new Rectangle(100, 0, 120, 20));
opt1.setOptionName("Test1");
opt2.setOptionName("Test2");
radio.add(opt1);
radio.add(opt2);
opt1.setStyle(BoxStyle.Square);
opt2.setStyle(BoxStyle.Square);
opt1.setStyle(BoxStyle.Cross);
opt2.setStyle(BoxStyle.Cross);
opt1.setBorder(new Border(opt1));
opt1.getBorder().setStyle(BorderStyle.Solid);
opt1.getBorder().setWidth(1);
opt1.getCharacteristics().setBorder(java.awt.Color.black);
opt2.setBorder(new Border(opt2));
opt2.getBorder().setWidth(1);
opt2.getBorder().setStyle(BorderStyle.Solid);
opt2.getCharacteristics().setBorder(java.awt.Color.black);
// add radio button to form object of Document object
pdfDocument.getForm().add(radio);
// save the PDF file
pdfDocument.save("RadioButtonSample.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Get a field
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("textbox1");
// Modify the field value
textBoxField.setValue("Updated Value");
// Set the field as read only
textBoxField.setReadOnly(true);
// Save the updated document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Get a field
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("textbox1");
// Modify the field location
textBoxField.setRect(new Rectangle(300, 400, 600, 500));
// Save the modified document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Get a field
TextBoxField textBoxField = (TextBoxField) pdfDocument.getForm().get("textbox1");
// Create an instance of font object and try loading ComicSansMS font
// from system font repository
Font font = FontRepository.findFont("ComicSansMS");
// Set the font information for form field by using Font object
textBoxField.setDefaultAppearance(new DefaultAppearance(font, 10, Color.black));
// Set the font information for form field by using its name
// textBoxField.setDefaultAppearance(new DefaultAppearance("ComicSansMS", 10, Color.black));
// Save updated document
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Original.pdf");
// Get different document properties
// Position of document's window - Default: false
System.out.printf("CenterWindow :- " + pdfDocument.getCenterWindow());
// Predominant reading order; determine the position of page
// when displayed side by side - Default: L2R
System.out.printf("Direction :- " + pdfDocument.getDirection());
// Whether window's title bar should display document title.
// If false, title bar displays PDF file name - Default: false
System.out.printf("DisplayDocTitle :- " + pdfDocument.getDisplayDocTitle());
// Whether to resize the document's window to fit the size of
// first displayed page - Default: false
System.out.printf("FitWindow :- " + pdfDocument.getFitWindow());
// Whether to hide menu bar of the viewer application - Default: false
System.out.printf("HideMenuBar :-" + pdfDocument.getHideMenubar());
// Whether to hide tool bar of the viewer application - Default: false
System.out.printf("HideToolBar :-" + pdfDocument.getHideToolBar());
// Whether to hide UI elements like scroll bars
// and leaving only the page contents displayed - Default: false
System.out.printf("HideWindowUI :-" + pdfDocument.getHideWindowUI());
// The document's page mode. How to display document on exiting
// full-screen mode.
System.out.printf("NonFullScreenPageMode :-" + pdfDocument.getNonFullScreenPageMode());
// The page layout i.e. single page, one column
System.out.printf("PageLayout :-" + pdfDocument.getPageLayout());
// How the document should display when opened.
System.out.printf("pageMode :-" + pdfDocument.getPageMode());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Original.pdf");
// Get document information
com.aspose.pdf.DocumentInfo docInfo = pdfDocument.getInfo();
// Show document information
System.out.printf("Author:-" + docInfo.getAuthor());
System.out.printf("\n Creation Date:-" + docInfo.getCreationDate());
System.out.printf("\n Keywords:-" + docInfo.getKeywords());
System.out.printf("\n Modify Date:-" + docInfo.getModDate());
System.out.printf("\n Subject:-" + docInfo.getSubject());
System.out.printf("\n Title:-" + docInfo.getTitle());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
double zoom = .5;
// instantiate new Document object
Document doc = new Document(myDir + "HelloWorld.pdf");
// setting zoom factor of document
GoToAction actionzoom = new GoToAction(new XYZExplicitDestination(doc.getPages().get_Item(1), doc.getPages().get_Item(1).getMediaBox().getWidth(), doc.getPages().get_Item(1).getMediaBox().getHeight(), zoom));
// setting action to fit to page width zoom
GoToAction actionFittoWidth = new GoToAction(new FitHExplicitDestination(doc.getPages().get_Item(1), doc.getPages().get_Item(1).getMediaBox().getWidth()));
// setting action to fit to page height zoom
GoToAction actionFittoHeight = new GoToAction(new FitVExplicitDestination(doc.getPages().get_Item(1), doc.getPages().get_Item(1).getMediaBox().getHeight()));
doc.setOpenAction(actionzoom);
doc.save(myDir + "Zoomed_actionzoom.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate new Document object
Document doc1 = new Document(myDir + "Zoomed_actionzoom.pdf");
// Create GoToAction object
GoToAction action = (GoToAction) doc1.getOpenAction();
// Get the Zoom factor of PDF file
System.out.println(((XYZExplicitDestination) action.getDestination()).getZoom());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Get properties
System.out.println("xmp:CreateDate: " + pdfDocument.getMetadata().get_Item("xmp:CreateDate"));
System.out.println("xmp:Nickname: " + pdfDocument.getMetadata().get_Item("xmp:Nickname"));
System.out.println("xmp:CustomProperty: " + pdfDocument.getMetadata().get_Item("xmp:CustomProperty"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.getPages().add();
// Create Graph instance
Graph graph = new Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.getParagraphs().add(graph);
// Create Rectangle instance
Line line = new Line(new float[] { 100, 100, 200, 100 });
// Specify fill color for Graph object
line.getGraphInfo().setDashArray(new int[] { 0, 1, 0 });
line.getGraphInfo().setDashPhase(1);
// Add rectangle object to shapes collection of Graph object
graph.getShapes().add(line);
// Save PDF file
doc.save("LineAdded.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.getPages().add();
// set size of PDF page
page.setPageSize(375, 300);
// set left margin for page object as 0
page.getPageInfo().getMargin().setLeft(0);
// set top margin of page object as 0
page.getPageInfo().getMargin().setTop(0);
// create a new rectangle with Color as Red, Z-Order as 0 and certain
// dimensions
addRectangle(page, 50, 40, 60, 40, Color.getRed(), 2);
// create a new rectangle with Color as Blue, Z-Order as 0 and certain
// dimensions
addRectangle(page, 20, 20, 30, 30, Color.getBlue(), 1);
// create a new rectangle with Color as Green, Z-Order as 0 and certain
// dimensions
addRectangle(page, 40, 40, 60, 30, Color.getGreen(), 0);
// save resultant PDF file
doc.save("Z-Order_Test.pdf");
private static void addRectangle(Page page, float x, float y, float width, float height, Color color, int zindex) {
// create graph object with dimensions same as specified for Rectangle object
Graph graph = new Graph(width, height);
// can we change the position of graph instance
graph.setChangePosition(false);
// set Left coordinate position for Graph instance
graph.setLeft(x);
// set Top coordinate position for Graph object
graph.setTop(y);
// Add a rectangle inside the "graph"
Rectangle rect = new Rectangle(0, 0, width, height);
// set rectangle fill color
rect.getGraphInfo().setFillColor(color);
// color of graph object
rect.getGraphInfo().setColor(color);
// add rectangle to shapes collection of graph instance
graph.getShapes().add(rect);
// set Z-Index for rectangle object
graph.setZIndex(zindex);
// add graph to paragraphs collection of page object
page.getParagraphs().add(graph);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.getPages().add();
// Create Graph instance
Graph graph = new Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.getParagraphs().add(graph);
// Create Rectangle instance
Rectangle rect = new Rectangle(100, 100, 200, 120);
// Specify fill color for Graph object
rect.getGraphInfo().setFillColor(Color.getRed());
// Add rectangle object to shapes collection of Graph object
graph.getShapes().add(rect);
// save resultant PDF file
doc.save("Filled_Rect.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.getPages().add();
// set page margin on all sides as 0
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
// create Graph object with Width and Height equal to page dimensions
Graph graph = new Graph((float) page.getPageInfo().getWidth(), (float) page.getPageInfo().getHeight());
// create first line object starting from Lower-Left to Top-Right corner of page
Line line = new Line(new float[] { (float) page.getRect().getLLX(), 0, (float) page.getPageInfo().getWidth(), (float) page.getRect().getURY() });
// add line to shapes collection of Graph object
graph.getShapes().add(line);
// draw line from Top-Left corner of page to Bottom-Right corner of page
Line line2 = new Line(new float[] { 0, (float) page.getRect().getURY(), (float) page.getPageInfo().getWidth(), (float) page.getRect().getLLX() });
// add line to shapes collection of Graph object
graph.getShapes().add(line2);
// add Graph object to paragraphs collection of page
page.getParagraphs().add(graph);
// save resultant PDF file
doc.save("Line_Across_Page.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document pdfDoc = new Document();
pdfDoc.getPageInfo().setWidth(612.0);
pdfDoc.getPageInfo().setHeight(792.0);
pdfDoc.getPageInfo().getMargin().setLeft(72);
pdfDoc.getPageInfo().getMargin().setRight(72);
pdfDoc.getPageInfo().getMargin().setTop(72);
pdfDoc.getPageInfo().getMargin().setBottom(72);
Page pdfPage = pdfDoc.getPages().add();
pdfPage.getPageInfo().setWidth(612.0);
pdfPage.getPageInfo().setHeight(792.0);
pdfPage.getPageInfo().getMargin().setLeft(72);
pdfPage.getPageInfo().getMargin().setRight(72);
pdfPage.getPageInfo().getMargin().setTop(72);
pdfPage.getPageInfo().getMargin().setBottom(72);
FloatingBox floatBox = new FloatingBox();
floatBox.setMargin(pdfPage.getPageInfo().getMargin());
pdfPage.getParagraphs().add(floatBox);
Heading heading = new Heading(1);
heading.setInList(true);
heading.setStartNumber(1);
heading.setText("List 1");
heading.setStyle(NumberingStyle.NumeralsRomanLowercase);
heading.setAutoSequence(true);
floatBox.getParagraphs().add(heading);
Heading heading2 = new Heading(1);
heading2.setInList(true);
heading2.setStartNumber(13);
heading2.setText("List 2");
heading2.setStyle(NumberingStyle.NumeralsRomanLowercase);
heading2.setAutoSequence(true);
floatBox.getParagraphs().add(heading2);
Heading heading3 = new Heading(2);
heading3.setInList(true);
heading3.setStartNumber(1);
heading3.setText("the value, as of the effective date of the plan, of property to be distributed under the plan onaccount of each allowed");
heading3.setStyle(NumberingStyle.LettersLowercase);
heading3.setAutoSequence(true);
floatBox.getParagraphs().add(heading3);
pdfDoc.save("RomanNumber.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// load source PDF file
PdfFileInfo info = new PdfFileInfo();
info.bindPdf("source.pdf");
// determine if the source PDF is encrypted
System.out.println("File is password protected " + info.isEncrypted());
String[] passwords = new String[] { "test", "test1", "user", "test3", "sample" };
for (int passwordcount = 0; passwordcount < passwords.length; passwordcount++) {
try {
Document doc = new Document("source.pdf", passwords[passwordcount]);
if (doc.getPages().size() > 0) {
System.out.println("Password = " + passwords[passwordcount] + " is correct");
System.out.println("Number of Page in document are = " + doc.getPages().size());
}
} catch (InvalidPasswordException ex) {
System.out.println("------------------------------------------");
System.out.println("Password = " + passwords[passwordcount] + " is not correct");
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate FielInfo object
PdfFileInfo fileInfo = new PdfFileInfo();
// bind source PDF file
fileInfo.bindPdf("source.pdf");
// print if source file is password encrypted
System.out.println("Is document encrypted = " + fileInfo.isEncrypted());
// determine if the password type for document is User
if (fileInfo.getPasswordType() == PasswordType.User)
;
// print password type information
System.out.println("Password type = " + fileInfo.getPasswordType() + " (type = User)");
fileInfo = new PdfFileInfo();
fileInfo.bindPdf("source.pdf", "user");
// print if document is encrypted
System.out.println("Document is encrypted = " + fileInfo.isEncrypted());
// determine if the password type for document is Owner
if (fileInfo.getPasswordType() == PasswordType.Owner)
;
// print password type information
System.out.println("Password type = " + fileInfo.getPasswordType() + " (type = Owner)");
// print if document has open password specified
System.out.println("Document has Open Password = " + fileInfo.hasOpenPassword());
// print if document has edit password specified
System.out.println("Document has Edit Password = " + fileInfo.hasEditPassword());
fileInfo = new PdfFileInfo();
fileInfo.bindPdf("c:/pdftest/source.pdf");
// print if document is encrypted
System.out.println("Document is encrypted = " + fileInfo.isEncrypted());
if (fileInfo.getPasswordType() == PasswordType.Inaccessible)
;
// print password type information
System.out.println("Password type = " + fileInfo.getPasswordType() + " (type = Inaccessible)");
if (fileInfo.hasOpenPassword())
;
// Document has open password enable
System.out.println("Document has open password enabled = " + fileInfo.hasOpenPassword());
try {
boolean hasOwnerPassword = fileInfo.hasEditPassword();
System.out.println("When PasswordType is Inaccessible we can't read HasEditPassword property.");
} catch (Exception e) {
// write what we expect
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument1 = new Document("input.pdf");
// Set coordinates
int lowerLeftX = 100;
int lowerLeftY = 100;
int upperRightX = 200;
int upperRightY = 200;
// Get the page you want to add the image to
Page page = pdfDocument1.getPages().get_Item(1);
// Load image into stream
java.io.FileInputStream imageStream = new java.io.FileInputStream(new java.io.File("input_image1.jpg"));
// Add an image to the Images collection of the page resources
page.getResources().getImages().add(imageStream);
// Using the GSave operator: this operator saves current graphics state
page.getContents().add(new Operator.GSave());
// Create Rectangle and Matrix objects
Rectangle rectangle = new Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Matrix matrix = new Matrix(new double[] { rectangle.getURX() - rectangle.getLLX(), 0, 0, rectangle.getURY() - rectangle.getLLY(), rectangle.getLLX(), rectangle.getLLY() });
// Using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed
page.getContents().add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = page.getResources().getImages().get_Item(page.getResources().getImages().size());
// Using Do operator: this operator draws image
page.getContents().add(new Operator.Do(ximage.getName()));
// Using GRestore operator: this operator restores graphics state
page.getContents().add(new Operator.GRestore());
// Save the new PDF
pdfDocument1.save("Updated_document.pdf");
// Close image stream
imageStream.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
BufferedImage originalImage = ImageIO.read(new File("anyImage.jpg"));
Document pdfDocument1 = new Document();
Page page2 = pdfDocument1.getPages().add();
page2.getResources().getImages().add(originalImage);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// instantiate Document instance
Document doc = new Document();
// add a page to pages collection of Pdf file
Page page = doc.getPages().add();
// create image instance
Image image1 = new Image();
// create BufferedImage instance
java.awt.image.BufferedImage bufferedImage = ImageIO.read(new File("source.gif"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// write buffered Image to OutputStream instance
ImageIO.write(bufferedImage, "gif", baos);
baos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// add image to paragraphs collection of first page
page.getParagraphs().add(image1);
// set image stream as OutputStream holding Buffered image
image1.setImageStream(bais);
// save resultant PDF file
doc.save("BufferedImage.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// open document
Document document = new Document("Input.pdf");
// Get rectangle of particular page region
Rectangle pageRect = new Rectangle(20, 671, 693, 1125);
// set CropBox value as per rectangle of desired page region
document.getPages().get_Item(1).setCropBox(pageRect);
// save cropped document into stream
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
document.save(outStream);
// open cropped PDF document from stream and convert to image
document = new Document(new ByteArrayInputStream(outStream.toByteArray()));
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create BMP device with specified attributes
BmpDevice bmpDevice = new BmpDevice(resolution);
// Convert a particular page and save the image to stream
bmpDevice.process(document.getPages().get_Item(1), "Output.bmp");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Loop through all the pages of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++) {
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image" + pageCount + ".bmp");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create BmpDevice object with particular resolution
BmpDevice bmpDevice = new BmpDevice(resolution);
// Convert a particular page and save the image to stream
bmpDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
// Close the stream
imageStream.close();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image.bmp");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create BmpDevice object with particular resolution
BmpDevice bmpDevice = new BmpDevice(resolution);
// Convert a particular page and save the image to stream
bmpDevice.process(pdfDocument.getPages().get_Item(1), imageStream);
// Close the stream
imageStream.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Loop through all the pages of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++)
{
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image" + pageCount + ".jpg");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create JpegDevice object where second argument indicates the quality of resultant image
JpegDevice jpegDevice = new JpegDevice(resolution, 100);
// Convert a particular page and save the image to stream
jpegDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
// Close the stream
imageStream.close();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image.jpg");
// Create JPEG device with specified attributes
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create JpegDevice object where second argument indicates the quality of resultant image
JpegDevice jpegDevice = new JpegDevice(resolution, 100);
// Convert a particular page and save the image to stream
jpegDevice.process(pdfDocument.getPages().get_Item(1), imageStream);
// Close the stream
imageStream.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Loop through all the pages of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++) {
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image" + pageCount + ".png");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create PngDevice object with particular resolution
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
// Close the stream
imageStream.close();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image.png");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create PngDevice object with particular resolution
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.process(pdfDocument.getPages().get_Item(1), imageStream);
// Close the stream
imageStream.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Convert a all pages of PDF file to TIFF format
tiffDevice.process(pdfDocument, imageStream);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document("input.pdf");
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image.tiff");
// Create Resolution object
Resolution resolution = new Resolution(300);
// instantiate TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
// set the compression of resultant TIFF image
tiffSettings.setCompression(CompressionType.CCITT4);
// set the color depth for resultant image
tiffSettings.setDepth(ColorDepth.Format8bpp);
// skip blank pages while rendering PDF to TIFF
tiffSettings.setSkipBlankPages(true);
// Create TiffDevice object with particular resolution
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Convert a particular page (Page 1) and save the image to stream
tiffDevice.process(pdfDocument, 1, 1, imageStream);
// Close the stream
imageStream.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String myDir = "";
Document document = new Document(myDir + "mde1257231R.pdf");
// Extract actions
AnnotationSelector selector = new AnnotationSelector(new LinkAnnotation(document.getPages().get_Item(1), Rectangle.getTrivial()));
document.getPages().get_Item(1).accept(selector);
java.util.List list = selector.getSelected();
for (int listItem = 0; listItem < list.size(); listItem++) {
Annotation annotation = (Annotation) list.get(listItem);
// Create ImagePlacementAbsorber object to perform image placement
// search
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
// Accept the absorber for all the pages
document.getPages().get_Item(1).accept(abs);
// Loop through all ImagePlacements
for (ImagePlacement imagePlacement : (Iterable<ImagePlacement>) abs.getImagePlacements()) {
// Determine if URY of Hyperlink and image are matching
if ((int) annotation.getRect().getURY() == (int) imagePlacement.getRectangle().getURY()) {
System.out.println("Image with Hyperlink...");
imagePlacement.getImage().delete();// delete a particular image from resources
}
}
}
// Save updated document
document.save(myDir + "ImageRemoved_output_3.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Delete a particular image
pdfDocument.getPages().get_Item(1).getResources().getImages().delete(1);
// Save the updated PDF file
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Extract a particular image
XImage xImage = pdfDocument.getPages().get_Item(1).getResources().getImages().get_Item(1);
// Create stream object to save the output image
java.io.OutputStream output = new java.io.FileOutputStream("output.jpg");
// Save the output image
xImage.save(output);
output.close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF file
Document pdfDocument = new Document("input.pdf");
// Get the all images names from first page of PDF file
for (int i = 0; i < pdfDocument.getPages().get_Item(1).getResources().getImages().size(); i++) {
// Print the names of image file over console
System.out.println(pdfDocument.getPages().get_Item(1).getResources().getImages().getNames()[i]);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// read source PDF file
Document document = new Document("test4.pdf");
try /* JAVA: was using */
{
// iterate through all pages of PDF file
for (Page page : (Iterable<Page>) document.getPages()) {
// create Image Placement Absorber instance
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
page.accept(abs);
for (ImagePlacement ia : (Iterable<ImagePlacement>) abs.getImagePlacements()) {
/* ColorType */
int colorType = ia.getImage().getColorType();
switch (colorType) {
case ColorType.Grayscale:
System.out.println("Grayscale Image");
break;
case ColorType.Rgb:
System.out.println("Colored Image");
break;
}
}
}
} catch (Exception ex) {
System.out.println("Error reading file = " + document.getFileName());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Replace a particular image
pdfDocument.getPages().get_Item(1).getResources().getImages().replace(1, new java.io.FileInputStream(new java.io.File("apose.png")));
// Save the updated PDF file
pdfDocument.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String myDir = "pathTodir";
File fileIn = new File(myDir + "image.jpg");
FileInputStream in = new FileInputStream(fileIn);
File fileOut = new File(myDir + "image.pdf");
FileOutputStream out = new FileOutputStream(fileOut);
// Test PDF creation
Document doc = new Document();
Page page = doc.getPages().add();
Image image1 = new Image();
image1.setImageStream(in);
image1.setFixHeight(page.getMediaBox().getHeight() / 4);
image1.setFixWidth(page.getMediaBox().getWidth() / 2);
page.getParagraphs().add(image1);
page.getPageInfo().getMargin().setLeft(5);
page.getPageInfo().getMargin().setRight(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setBottom(0);
doc.save(out);
// Internal image resolution change
doc = new Document(myDir + "image.pdf");
XImageCollection images = doc.getPages().get_Item(1).getResources().getImages();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
images.get_Item(1).save(baos, 10, 10);// define horizontal and vertical
// resolutions
images.get_Item(1).replace(new ByteArrayInputStream(baos.toByteArray()));
doc.save(myDir + "imageWithNewResolution.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document document = new Document("input.pdf");
// Create link
Page page = document.getPages().get_Item(1);
// Create Link annotation object
LinkAnnotation link = new LinkAnnotation(page, new Rectangle(100, 100, 300, 300));
// Create border object for LinkAnnotation
Border border = new Border(link);
// Set the border width value as 0
border.setWidth(0);
// Set the border for LinkAnnotation
link.setBorder(border);
// Specify the link type as remote URI
link.setAction(new GoToURIAction("www.aspose.com"));
// Add link annotation to annotations collection of first page of PDF file
page.getAnnotations().add(link);
// Create Free Text annotation
FreeTextAnnotation textAnnotation = new FreeTextAnnotation(document.getPages().get_Item(1), new Rectangle(100, 100, 300, 300), new DefaultAppearance(FontRepository.findFont("Arial"), 10, java.awt.Color.BLUE));
// String to be added as Free text
textAnnotation.setContents("Link to Aspose website");
// Set the border for Free Text Annotation
textAnnotation.setBorder(border);
// Add FreeText annotation to annotations collection of first page of Document
document.getPages().get_Item(1).getAnnotations().add(textAnnotation);
// Save updated document
document.save("Annotation_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document document = new Document("update_Service_Work_Order.pdf");
// Extract actions
Page page = document.getPages().get_Item(1);
AnnotationSelector selector = new AnnotationSelector(new LinkAnnotation(page, Rectangle.getTrivial()));
// page.accept(selector);
List list = selector.getSelected();
// Iterate through individual item inside list
if (list.size() == 0)
System.out.println("No Hyperlinks found..");
else {
// Loop through all the bookmarks
for (LinkAnnotation annot : (Iterable<LinkAnnotation>) list) {
// Print the destination URL
System.out.println("<br />Destination: " + ((GoToURIAction) annot.getAction()).getURI() + "<br />");
}
}// end else
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document document = new Document("Input.pdf");
// Remove document open action
document.setOpenAction(null);
// Save updated document
document.save("Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document("input_color.pdf");
OperatorCollection contents = doc.getPages().get_Item(1).getContents();
System.out.println("Values of RGB color operators in the pdf document");
for (int j = 1; j <= contents.size(); j++) {
Operator oper = contents.get_Item(j);
if (oper instanceof Operator.SetRGBColor || oper instanceof Operator.SetRGBColorStroke)
try {
// Converting RGB to CMYK color
System.out.println(oper.toString());
double[] rgbFloatArray = new double[] { Double.valueOf(oper.getParameters().get(0).toString()), Double.valueOf(oper.getParameters().get(1).toString()), Double.valueOf(oper.getParameters().get(2).toString()), };
double[] cmyk = new double[4];
if (oper instanceof Operator.SetRGBColor) {
((Operator.SetRGBColor) oper).getCMYKColor(rgbFloatArray, cmyk);
contents.set_Item(j, new Operator.SetCMYKColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]));
} else if (oper instanceof Operator.SetRGBColorStroke) {
((Operator.SetRGBColorStroke) oper).getCMYKColor(rgbFloatArray, cmyk);
contents.set_Item(j, new Operator.SetCMYKColorStroke(cmyk[0], cmyk[1], cmyk[2], cmyk[3]));
} else
throw new java.lang.Throwable("Unsupported command");
} catch (Throwable e) {
e.printStackTrace();
}
}
doc.save("input_colorout.pdf");
// Testing the result
System.out.println("Values of converted CMYK color operators in the result pdf document");
doc = new Document("input_colorout.pdf");
contents = doc.getPages().get_Item(1).getContents();
for (int j = 1; j <= contents.size(); j++) {
Operator oper = contents.get_Item(j);
if (oper instanceof Operator.SetCMYKColor || oper instanceof Operator.SetCMYKColorStroke) {
System.out.println(oper.toString());
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Get version information
System.out.printf("\n Product :- " + BuildVersionInfo.PRODUCT);
System.out.printf("\n File Version :- " + BuildVersionInfo.FILE_VERSION);
System.out.printf("\n Assembly Version : {0}",BuildVersionInfo.ASSEMBLY_VERSION);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
int alpha = 10;
int green = 0;
int red = 100;
int blue = 0;
// create Color object using Alpha RGB
Color alphaColor = Color.fromArgb(alpha, red, green, blue); // provide alpha channel
// instantiate Document object
Document document = new Document();
// add page to pages collection of PDF file
Page page = document.getPages().add();
// create Graph object with certain dimensions
Graph graph = new Graph(300, 400);
// set border for Drawing object
graph.setBorder(new BorderInfo(BorderSide.All, Color.getBlack()));
// add graph object to paragraphs collection of Page instance
page.getParagraphs().add(graph);
// create Rectangle object with certain dimensions
Rectangle rectangle = new Rectangle(0, 0, 100, 50);
// create graphInfo object for Rectangle instance
GraphInfo graphInfo = rectangle.getGraphInfo();
// set color information for GraphInfo instance
graphInfo.setColor(Color.getRed());
// set fill color for GraphInfo
graphInfo.setFillColor(alphaColor);
// add rectangle shape to shapes collection of graph object
graph.getShapes().add(rectangle);
// save PDF file
document.save("TransparentColor.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF file
Document doc = new Document("input.htm");
Document.OptimizationOptions opt = new Document.OptimizationOptions();
opt.setRemoveUnusedObjects(false);
opt.setLinkDuplcateStreams(false);
opt.setRemoveUnusedStreams(false);
// Enable image compression
opt.setCompressImages(true);
// Set the quality of images in PDF file
opt.setImageQuality(10);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Load source PDF file
com.aspose.pdf.Document doc = new Document("source.pdf");
// Optimize the file size by removing unused objects
com.aspose.pdf.Document.OptimizationOptions opt = new Document.OptimizationOptions();
opt.setRemoveUnusedObjects(true);
opt.setRemoveUnusedStreams(true);
opt.setLinkDuplcateStreams(true);
doc.optimizeResources(opt);
// Save the updated file
doc.save("optimized.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
String myDir = "";
// Create a new Document object
Document doc = new Document();
// Add a new page to document object
Page page = doc.getPages().add();
// Create BackgroundArtifact object
BackgroundArtifact background = new BackgroundArtifact();
// Specify the image for backgroundartifact object
background.setBackgroundImage(new FileInputStream(myDir + "logo.png"));
// Add backgroundartifact to artifacts collection of page
page.getArtifacts().add(background);
// Save the document
doc.save(myDir + "BackGround.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document("Input.pdf");
int pageCount = doc.getPages().size();
for (int i = 1; i <= pageCount; i++) {
Rectangle r = doc.getPages().get_Item(i).getMediaBox();
double newHeight = r.getWidth();
double newWidth = r.getHeight();
double newLLX = r.getLLX();
// We must to move page upper in order to compensate changing page size
// (lower edge of the page is 0,0 and information is usually placed from the top of the page.
//That's why we move lover edge upper on difference between old and new height.
double newLLY = r.getLLY() + (r.getHeight() - newHeight);
doc.getPages().get_Item(i).setMediaBox(new Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight));
// Sometimes we also need to set CropBox (if it was set in original
// file)
doc.getPages().get_Item(i).setCropBox(new Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight));
// Setting Rotation angle of page
doc.getPages().get_Item(i).setRotate(Rotation.on90);
}
doc.save("Output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Rectangle r = doc.getPages().get_Item(0).getMediaBox();
// New height the same
double newHeight = r.getHeight();
// New width is expanded proportionally to make orientation landscape
// (we assume that previous orientation is portrait)
double newWidth = r.getHeight() * r.getHeight() / r.getWidth();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open the target document
Document pdfDocument1 = new Document("input1.pdf");
// Open the source document
Document pdfDocument2 = new Document("input2.pdf");
// Add the pages of the source document to the target document
pdfDocument1.getPages().add(pdfDocument2.getPages());
// Save the concatenated output file (the target document)
pdfDocument1.save("Concatenate_output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument1 = new Document("Mobile Software.pdf");
// Delete a page
pdfDocument1.getPages().delete(3);
// Save the new PDF file
pdfDocument1.save("Updated_document.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open source PDF file
Document pdfDocument = new Document("input.pdf");
// Iterate through all the page of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++) {
// Get the color type information for particular PDF page
int pageColorType = pdfDocument.getPages().get_Item(pageCount).getColorType();
switch (pageColorType) {
case 2:
System.out.println("Page # -" + pageCount + " is Black and white..");
break;
case 1:
System.out.println("Page # -" + pageCount + " is Gray Scale...");
break;
case 0:
System.out.println("Page # -" + pageCount + " is RGB..");
break;
case 3:
System.out.println("Page # -" + pageCount + " Color is undefined..");
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Get page count
System.out.printf("Page Count :- " + pdfDocument.getPages().size());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument = new Document("input.pdf");
// Get the page collection
PageCollection pageCollection = pdfDocument.getPages();
// Get a specific page
Page pdfPage = pageCollection.get_Item(1);
// Get the page properties
System.out.printf("\n ArtBox : Height = " + pdfPage.getArtBox().getHeight() + ", Width = " + pdfPage.getArtBox().getWidth() + ", LLX = " + pdfPage.getArtBox().getLLX() + ", LLY = " + pdfPage.getArtBox().getLLY() + ", URX = " + pdfPage.getArtBox().getURX() + ", URY = " + pdfPage.getArtBox().getURY());
System.out.printf("\n BleedBox : Height = " + pdfPage.getBleedBox().getHeight() + ", Width = " + pdfPage.getBleedBox().getWidth() + ", LLX = " + pdfPage.getBleedBox().getLLX() + ", LLY = " + pdfPage.getBleedBox().getLLY() + ", URX = " + pdfPage.getBleedBox().getURX() + ", URY = " + pdfPage.getBleedBox().getURY());
System.out.printf("\n CropBox : Height = " + pdfPage.getCropBox().getHeight() + ", Width = " + pdfPage.getCropBox().getWidth() + ", LLX = " + pdfPage.getCropBox().getLLX() + ", LLY = " + pdfPage.getCropBox().getLLY() + ", URX = " + pdfPage.getCropBox().getURX() + ", URY = " + pdfPage.getCropBox().getURY());
System.out.printf("\n MediaBox : Height = " + pdfPage.getMediaBox().getHeight() + ", Width = " + pdfPage.getMediaBox().getWidth() + ", LLX = " + pdfPage.getMediaBox().getLLX() + ", LLY = " + pdfPage.getMediaBox().getLLY() + ", URX = " + pdfPage.getMediaBox().getURX() + ", URY = " + pdfPage.getMediaBox().getURY());
System.out.printf("\n TrimBox : Height = " + pdfPage.getTrimBox().getHeight() + ", Width = " + pdfPage.getTrimBox().getWidth() + ", LLX = " + pdfPage.getTrimBox().getLLX() + ", LLY = " + pdfPage.getTrimBox().getLLY() + ", URX = " + pdfPage.getTrimBox().getURX() + ", URY = " + pdfPage.getTrimBox().getURY());
System.out.printf("\n Rect : Height = " + pdfPage.getRect().getHeight() + ", Width = " + pdfPage.getRect().getWidth() + ", LLX = " + pdfPage.getRect().getLLX() + ", LLY = " + pdfPage.getRect().getLLY() + ", URX = " + pdfPage.getRect().getURX() + ", URY = " + pdfPage.getRect().getURY());
System.out.printf("\n Page Number :- " + pdfPage.getNumber());
System.out.printf("\n Rotate :-" + pdfPage.getRotate());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open the first document
Document pdfDocument1 = new Document("Mobile Software.pdf");
// Get the page at a particular index of the Page Collection
Page pdfPage = pdfDocument1.getPages().get_Item(3);
// Create a new Document object
Document newDocument = new Document();
// Add the page to the Pages collection of new document object
newDocument.getPages().add(pdfPage);
// Save the new file
newDocument.save("page_" + pdfPage.getNumber() + ".pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument1 = new Document("intput.pdf");
// Insert an empty page into a PDF
pdfDocument1.getPages().insert(2);
// Save the output file
pdfDocument1.save("output.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument1 = new Document("input.pdf");
// Loop through the pages
for (int pdfPage = 1; pdfPage <= pdfDocument1.getPages().size(); pdfPage++) {
// Create a new Document object
Document newDocument = new Document();
// Get the page at a given index of the Page Collection
newDocument.getPages().add(pdfDocument1.getPages().get_Item(pdfPage));
// Save the new PDF file
newDocument.save("page_" + pdfPage + ".pdf");
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open a document
Document pdfDocument1 = new Document("input.pdf");
// Get the page collection
PageCollection pageCollection = pdfDocument1.getPages();
// Get a particular page
Page pdfPage = pageCollection.get_Item(1);
// Set the page size as A4 (11.7 x 8.3 in). In Aspose.Pdf, 1 inch = 72 points
// so A4 dimensions in points is (842.4, 597.6).
pdfPage.setPageSize(597.6, 842.4);
// Save the new PDF
pdfDocument1.save("Updated_document.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Instantiate Document object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document("testFile.pdf");
if (doc.getMetadata().contains("pdfaid:part"))
doc.getMetadata().removeItem("pdfaid:part");
if (doc.getMetadata().contains("dc:format"))
doc.getMetadata().removeItem("dc:format");
// Save updated document
doc.save("output.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment