Skip to content

Aspose.Pdf Java for Jython Examples #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Plugins/Aspose-Pdf-Java-for-Jython/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Aspose.Pdf Java for Jython

Aspose.Pdf Java for Jython is a project that demonstrates / provides the Aspose.Pdf for Java API usage examples in Jython.

## Download

* To download Aspose.Pdf for Java API to be used with these examples, Please navigate to [Aspose.Pdf for Java](http://www.aspose.com/community/files/72/java-components/aspose.pdf-for-java/)
* Place downloaded jar file into "lib" directory.
* Replace "your-lib" with the jar filename.

## Documentation

For most complete documentation of the project, check [Aspose.Pdf Java For Jython confluence wiki](http://www.aspose.com/docs/display/pdfjava/Aspose.Pdf+Java+for+Jython).

## Download Latest Versions?

* [Latest Releases on Codeplex](http://asposepdfjavajython.codeplex.com/releasesce)

## Clone Plugin SourceCodes?

This project is also hosted and maintained at CodePlex. To clone navigate to:

* [Aspose.Pdf Java for Jython on CodePlex - click here](https://asposepdfjavajython.codeplex.com/SourceControl/latest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Metadata-Version: 1.1
Name: aspose-pdf-java-for-jython
Version: 1.0.0
Summary: Aspose.Pdf Java for Jython is a project that demonstrates / provides the Aspose.Pdf for Java API usage examples in Jython.
Home-page: https://github.com/fahadadeel/Aspose_Pdf_Java/tree/master/Plugins/Aspose-Pdf-Java-for-Jython
Author: Fahad Adeel
Author-email: pdf@aspose.com
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
setup.py
aspose_pdf_java_for_jython.egg-info/PKG-INFO
aspose_pdf_java_for_jython.egg-info/SOURCES.txt
aspose_pdf_java_for_jython.egg-info/dependency_links.txt
aspose_pdf_java_for_jython.egg-info/top_level.txt
asposepdf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asposepdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from asposepdf import Settings
from com.aspose.pdf import Document

class PdfToDoc:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentConversion/PdfToDoc/'

# Open the target document
pdf = Document(dataDir + 'input1.pdf')

# Save the concatenated output file (the target document)
pdf.save(dataDir + "output.doc")

print "Document has been converted successfully"

if __name__ == '__main__':
PdfToDoc()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from com.aspose.pdf import ExcelSaveOptions

class PdfToExcel:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentConversion/PdfToExcel/'

# Open the target document
pdf = Document(dataDir + 'input1.pdf')

# Instantiate ExcelSave Option object
excelsave = ExcelSaveOptions()

# Save the output to XLS format
pdf.save(dataDir + "Converted_Excel.xls", excelsave)

print "Document has been converted successfully"

if __name__ == '__main__':
PdfToExcel()
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from com.aspose.pdf import SvgSaveOptions

class PdfToSvg:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentConversion/PdfToSvg/'

# Open the target document
pdf = Document(dataDir + 'input1.pdf');

# instantiate an object of SvgSaveOptions
save_options = SvgSaveOptions();

# do not compress SVG image to Zip archive
save_options.CompressOutputToZipArchive = False;

# Save the output to XLS format
pdf.save(dataDir + "Output.svg", save_options);

print "Document has been converted successfully"

if __name__ == '__main__':
PdfToSvg()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from com.aspose.pdf import SvgLoadOptions

class SvgToPdf:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentConversion/SvgToPdf/'

# Instantiate LoadOption object using SVG load option
options = SvgLoadOptions()

# Create document object
pdf = Document(dataDir + 'Example.svg', options)

# Save the output to XLS format
pdf.save(dataDir + "SVG.pdf")

print "Document has been converted successfully"

if __name__ == '__main__':
SvgToPdf()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from com.aspose.pdf import JavascriptAction

class AddJavascript:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentObject/AddJavascript/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

# Adding JavaScript at Document Level
# Instantiate JavascriptAction with desried JavaScript statement
javaScript = 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(JavascriptAction("app.alert('page 2 is opened')"))
doc.getPages().get_Item(2).getActions().setOnClose(JavascriptAction("app.alert('page 2 is closed')"))

# Save PDF Document
doc.save(dataDir + "JavaScript-Added.pdf")

print "Added JavaScript Successfully, please check the output file."

if __name__ == '__main__':
AddJavascript()
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from asposepdf import Settings
from com.aspose.pdf import Document

class GetDocumentWindow:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentObject/GetDocumentWindow/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

# Get different document properties
# Position of document's window - Default: false
print "CenterWindow :- "
print doc.getCenterWindow()

# Predominant reading order; determine the position of page
# when displayed side by side - Default: L2R
print "Direction :- "
print doc.getDirection()

# Whether window's title bar should display document title.
# If false, title bar displays PDF file name - Default: false
print "DisplayDocTitle :- "
print doc.getDisplayDocTitle()

#Whether to resize the document's window to fit the size of
#first displayed page - Default: false
print "FitWindow :- "
print doc.getFitWindow()

# Whether to hide menu bar of the viewer application - Default: false
print "HideMenuBar :-"
print doc.getHideMenubar()

# Whether to hide tool bar of the viewer application - Default: false
print "HideToolBar :-"
print doc.getHideToolBar()

# Whether to hide UI elements like scroll bars
# and leaving only the page contents displayed - Default: false
print "HideWindowUI :-"
print doc.getHideWindowUI()

# The document's page mode. How to display document on exiting full-screen mode.
print "NonFullScreenPageMode :-"
print doc.getNonFullScreenPageMode()

# The page layout i.e. single page, one column
print "PageLayout :-"
print doc.getPageLayout()

#How the document should display when opened.
print "pageMode :-"
print doc.getPageMode()

if __name__ == '__main__':
GetDocumentWindow()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from asposepdf import Settings
from com.aspose.pdf import Document

class GetPdfFileInfo:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentObject/GetPdfFileInfo/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

# Get document information
doc_info = doc.getInfo()

# Show document information
print "Author:"
print doc_info.getAuthor()
print "Creation Date:"
print doc_info.getCreationDate()
print "Keywords:"
print doc_info.getKeywords()
print "Modify Date:"
print doc_info.getModDate()
print "Subject:"
print doc_info.getSubject()
print "Title:"
print doc_info.getTitle()

if __name__ == '__main__':
GetPdfFileInfo()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from asposepdf import Settings
from com.aspose.pdf import Document

class GetXMPMetadata:

def __init__(self):
dataDir = Settings.dataDir + 'WorkingWithDocumentObject/GetXMPMetadata/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

# Get properties
print "xmp:CreateDate: "
print doc.getMetadata().get_Item("xmp:CreateDate")
print "xmp:Nickname: "
print doc.getMetadata().get_Item("xmp:Nickname")
print "xmp:CustomProperty: "
print doc.getMetadata().get_Item("xmp:CustomProperty")

if __name__ == '__main__':
GetXMPMetadata()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from com.aspose.pdf.Document import OptimizationOptions

class Optimize:

def __init__(self):
self.optimize_web()

def optimize_web(dataDir):

dataDir = Settings.dataDir + 'WorkingWithDocumentObject/Optimize/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

# Optimize for web
doc.optimize()

#Save output document
doc.save(dataDir + "Optimized_Web.pdf")

print "Optimized PDF for the Web, please check output file."

if __name__ == '__main__':
Optimize()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from com.aspose.pdf import JavascriptAction

class SetExpiration:

def __init__(self):
self.optimize_web()

def optimize_web(dataDir):

dataDir = Settings.dataDir + 'WorkingWithDocumentObject/SetExpiration/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

javascript = JavascriptAction(
"var year=2014;" "var month=4;" "today = new Date();"
"today = new Date(today.getFullYear(), today.getMonth());"
"expiry = new Date(year, month);"
"if (today.getTime() > expiry.getTime())"
"app.alert('The file is expired. You need a new one.');"
)

doc.setOpenAction(javascript)

# save update document with information
doc.save(dataDir + "set_expiration.pdf")

print "Update document information, please check output file."

if __name__ == '__main__':
SetExpiration()
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from asposepdf import Settings
from com.aspose.pdf import Document
from java.util import Date


class SetPdfFileInfo:

def __init__(self):

dataDir = Settings.dataDir + 'WorkingWithDocumentObject/SetPdfFileInfo/'

# Open a pdf document.
doc = Document(dataDir + "input1.pdf")

# Get document information
doc_info = doc.getInfo()

doc_info.setAuthor("Aspose.Pdf for java")
doc_info.setCreationDate(Date())
doc_info.setKeywords("Aspose.Pdf, DOM, API")
doc_info.setModDate(Date())
doc_info.setSubject("PDF Information")
doc_info.setTitle("Setting PDF Document Information")

# save update document with information
doc.save(dataDir + "Updated_Information.pdf")

print "Update document information, please check output file."

if __name__ == '__main__':
SetPdfFileInfo()
Loading