asposepdfjava 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +21 -0
  4. data/README.md +31 -0
  5. data/Rakefile +2 -0
  6. data/asposepdfjava.gemspec +27 -0
  7. data/config/aspose.yml +5 -0
  8. data/data/Example.svg +69 -0
  9. data/data/index.html +5 -0
  10. data/data/input.pdf +0 -0
  11. data/data/input1.pdf +0 -0
  12. data/lib/asposepdfjava.rb +71 -0
  13. data/lib/asposepdfjava/Converter/convertpagestoimages.rb +21 -0
  14. data/lib/asposepdfjava/Converter/htmltopdf.rb +18 -0
  15. data/lib/asposepdfjava/Converter/pdftodoc.rb +16 -0
  16. data/lib/asposepdfjava/Converter/pdftoexcel.rb +19 -0
  17. data/lib/asposepdfjava/Converter/pdftosvg.rb +22 -0
  18. data/lib/asposepdfjava/Converter/svgtopdf.rb +19 -0
  19. data/lib/asposepdfjava/Document/addjavascript.rb +27 -0
  20. data/lib/asposepdfjava/Document/addlayers.rb +40 -0
  21. data/lib/asposepdfjava/Document/addtoc.rb +56 -0
  22. data/lib/asposepdfjava/Document/getdocumentwindow.rb +46 -0
  23. data/lib/asposepdfjava/Document/getpdffileinfo.rb +22 -0
  24. data/lib/asposepdfjava/Document/getxmpmetadata.rb +16 -0
  25. data/lib/asposepdfjava/Document/optimize.rb +47 -0
  26. data/lib/asposepdfjava/Document/removemetadata.rb +24 -0
  27. data/lib/asposepdfjava/Document/setdocumentwindow .rb +49 -0
  28. data/lib/asposepdfjava/Document/setdocumentwindow.rb +49 -0
  29. data/lib/asposepdfjava/Document/setexpiration.rb +26 -0
  30. data/lib/asposepdfjava/Document/setpdffileinfo.rb +26 -0
  31. data/lib/asposepdfjava/Pages/concatenatepdffiles.rb +22 -0
  32. data/lib/asposepdfjava/Pages/deletepage.rb +19 -0
  33. data/lib/asposepdfjava/Pages/getnumberofpages.rb +14 -0
  34. data/lib/asposepdfjava/Pages/getpage.rb +25 -0
  35. data/lib/asposepdfjava/Pages/getpageproperties.rb +27 -0
  36. data/lib/asposepdfjava/Pages/insertemptypage.rb +19 -0
  37. data/lib/asposepdfjava/Pages/insertemptypageatendoffile.rb +19 -0
  38. data/lib/asposepdfjava/Pages/splitallpages.rb +29 -0
  39. data/lib/asposepdfjava/Pages/updatepagedimensions.rb +26 -0
  40. data/lib/asposepdfjava/Text/addhtml.rb +33 -0
  41. data/lib/asposepdfjava/Text/addtext.rb +39 -0
  42. data/lib/asposepdfjava/Text/extracttextfromallpages.rb +34 -0
  43. data/lib/asposepdfjava/Text/replacetextallpages.rb +39 -0
  44. data/lib/asposepdfjava/asposepdf.rb +5 -0
  45. data/lib/asposepdfjava/converter.rb +6 -0
  46. data/lib/asposepdfjava/document.rb +11 -0
  47. data/lib/asposepdfjava/helloworld.rb +21 -0
  48. data/lib/asposepdfjava/pages.rb +9 -0
  49. data/lib/asposepdfjava/text.rb +4 -0
  50. data/lib/asposepdfjava/version.rb +3 -0
  51. data/samples/test.rb +8 -0
  52. metadata +150 -0
@@ -0,0 +1,56 @@
1
+ module Asposepdfjava
2
+ module AddToc
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Get access to first page of PDF file
11
+ toc_page = doc.getPages().insert(1)
12
+
13
+ # Create object to represent TOC information
14
+ toc_info = Rjb::import('com.aspose.pdf.TocInfo').new
15
+ title = Rjb::import('com.aspose.pdf.TextFragment').new("Table Of Contents")
16
+ title.getTextState().setFontSize(20)
17
+ #title.getTextState().setFontStyle(Rjb::import('com.aspose.pdf.FontStyles.Bold'))
18
+
19
+ # Set the title for TOC
20
+ toc_info.setTitle(title)
21
+ toc_page.setTocInfo(toc_info)
22
+
23
+ # Create string objects which will be used as TOC elements
24
+ titles = Array["First page", "Second page"]
25
+
26
+ i = 0
27
+ while i < 2
28
+ # Create Heading object
29
+ heading2 = Rjb::import('com.aspose.pdf.Heading').new(1)
30
+
31
+ segment2 = Rjb::import('com.aspose.pdf.TextSegment').new
32
+ heading2.setTocPage(toc_page)
33
+ heading2.getSegments().add(segment2)
34
+
35
+ # Specify the destination page for heading object
36
+ heading2.setDestinationPage(doc.getPages().get_Item(i + 2))
37
+
38
+ # Destination page
39
+ heading2.setTop(doc.getPages().get_Item(i + 2).getRect().getHeight())
40
+
41
+ # Destination coordinate
42
+ segment2.setText(titles[i])
43
+
44
+ # Add heading to page containing TOC
45
+ toc_page.getParagraphs().add(heading2)
46
+
47
+ i +=1
48
+ end
49
+
50
+ # Save PDF Document
51
+ doc.save(data_dir + "TOC.pdf")
52
+
53
+ puts "Added TOC Successfully, please check the output file."
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,46 @@
1
+ module Asposepdfjava
2
+ module GetDocumentWindow
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Get different document properties
11
+ # Position of document's window - Default: false
12
+ puts "CenterWindow :- " + doc.getCenterWindow().to_s
13
+
14
+ # Predominant reading order; determine the position of page
15
+ # when displayed side by side - Default: L2R
16
+ puts "Direction :- " + doc.getDirection().to_s
17
+
18
+ # Whether window's title bar should display document title.
19
+ # If false, title bar displays PDF file name - Default: false
20
+ puts "DisplayDocTitle :- " + doc.getDisplayDocTitle().to_s
21
+
22
+ #Whether to resize the document's window to fit the size of
23
+ #first displayed page - Default: false
24
+ puts "FitWindow :- " + doc.getFitWindow().to_s
25
+
26
+ # Whether to hide menu bar of the viewer application - Default: false
27
+ puts "HideMenuBar :-" + doc.getHideMenubar().to_s
28
+
29
+ # Whether to hide tool bar of the viewer application - Default: false
30
+ puts "HideToolBar :-" + doc.getHideToolBar().to_s
31
+
32
+ # Whether to hide UI elements like scroll bars
33
+ # and leaving only the page contents displayed - Default: false
34
+ puts "HideWindowUI :-" + doc.getHideWindowUI().to_s
35
+
36
+ # The document's page mode. How to display document on exiting full-screen mode.
37
+ puts "NonFullScreenPageMode :-" + doc.getNonFullScreenPageMode().to_s
38
+
39
+ # The page layout i.e. single page, one column
40
+ puts "PageLayout :-" + doc.getPageLayout().to_s
41
+
42
+ #How the document should display when opened.
43
+ puts "pageMode :-" + doc.getPageMode().to_s
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module Asposepdfjava
2
+ module GetPdfFileInfo
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Get document information
11
+ doc_info = doc.getInfo()
12
+
13
+ # Show document information
14
+ puts "Author:-" + doc_info.getAuthor().to_s
15
+ puts "Creation Date:-" + doc_info.getCreationDate().to_string
16
+ puts "Keywords:-" + doc_info.getKeywords().to_s
17
+ puts "Modify Date:-" + doc_info.getModDate().to_string
18
+ puts "Subject:-" + doc_info.getSubject().to_s
19
+ puts "Title:-" + doc_info.getTitle().to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Asposepdfjava
2
+ module GetXMPMetadata
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Get properties
11
+ puts "xmp:CreateDate: " + doc.getMetadata().get_Item("xmp:CreateDate").to_s
12
+ puts "xmp:Nickname: " + doc.getMetadata().get_Item("xmp:Nickname").to_s
13
+ puts "xmp:CustomProperty: " + doc.getMetadata().get_Item("xmp:CustomProperty").to_s
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module Asposepdfjava
2
+ module Optimize
3
+ def initialize()
4
+ # Optimize document for the web
5
+ #optimize_web()
6
+
7
+ # Optimize document for the web
8
+ optimize_filesize()
9
+ end
10
+
11
+ def optimize_web()
12
+ # The path to the documents directory.
13
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
14
+
15
+ # Open a pdf document.
16
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
17
+
18
+ # Optimize for web
19
+ doc.optimize()
20
+
21
+ #Save output document
22
+ doc.save(data_dir + "Optimized_Web.pdf")
23
+
24
+ puts "Optimized PDF for the Web, please check output file."
25
+ end
26
+
27
+ def optimize_filesize()
28
+ # The path to the documents directory.
29
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
30
+
31
+ # Open a pdf document.
32
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
33
+
34
+ # Optimize the file size by removing unused objects
35
+ opt = Rjb::import('aspose.document.OptimizationOptions').new
36
+ opt.setRemoveUnusedObjects(true)
37
+ opt.setRemoveUnusedStreams(true)
38
+ opt.setLinkDuplcateStreams(true)
39
+ doc.optimizeResources(opt)
40
+
41
+ # Save output document
42
+ doc.save(data_dir + "Optimized_Filesize.pdf")
43
+
44
+ puts "Optimized PDF Filesize, please check output file."
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ module Asposepdfjava
2
+ module RemoveMetadata
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ if doc.getMetadata().contains("pdfaid:part")
11
+ doc.getMetadata().removeItem("pdfaid:part")
12
+ end
13
+
14
+ if doc.getMetadata().contains("dc:format")
15
+ doc.getMetadata().removeItem("dc:format")
16
+ end
17
+
18
+ # save update document with new information
19
+ doc.save(data_dir + "Remove_Metadata.pdf")
20
+
21
+ puts "Removed metadata successfully, please check output file."
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ module Asposepdfjava
2
+ module SetDocumentWindow
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Set different document properties
11
+ # Position of document's window - Default: false
12
+ doc.setCenterWindow(true)
13
+
14
+ # Predominant reading order; determine the position of page
15
+ # when displayed side by side - Default: L2R
16
+ #doc.setDirection(Rjb::import('com.aspose.pdf.Direction.L2R'))
17
+
18
+ # Whether window's title bar should display document title.
19
+ # If false, title bar displays PDF file name - Default: false
20
+ doc.setDisplayDocTitle(true)
21
+
22
+ # Whether to resize the document's window to fit the size of
23
+ # first displayed page - Default: false
24
+ doc.setFitWindow(true)
25
+
26
+ # Whether to hide menu bar of the viewer application - Default: false
27
+ doc.setHideMenubar(true)
28
+
29
+ # Whether to hide tool bar of the viewer application - Default: false
30
+ doc.setHideToolBar(true)
31
+
32
+ # Whether to hide UI elements like scroll bars
33
+ # and leaving only the page contents displayed - Default: false
34
+ doc.setHideWindowUI(true)
35
+
36
+ # The document's page mode. How to display document on exiting full-screen mode.
37
+ doc.setNonFullScreenPageMode(Rjb::import('com.aspose.pdf.PageMode.UseOC'))
38
+
39
+ # The page layout i.e. single page, one column
40
+ doc.setPageLayout(Rjb::import('com.aspose.pdf.PageLayout.TwoColumnLeft'))
41
+
42
+ #How the document should display when opened.
43
+ doc.setPageMode()
44
+
45
+ # Save updated PDF file
46
+ doc.save(data_dir + "Set Document Window.pdf")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ module Asposepdfjava
2
+ module SetDocumentWindow
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Set different document properties
11
+ # Position of document's window - Default: false
12
+ doc.setCenterWindow(true)
13
+
14
+ # Predominant reading order; determine the position of page
15
+ # when displayed side by side - Default: L2R
16
+ doc.setDirection(Rjb::import('com.aspose.pdf.Direction.R2L'))
17
+
18
+ # Whether window's title bar should display document title.
19
+ # If false, title bar displays PDF file name - Default: false
20
+ doc.setDisplayDocTitle(true)
21
+
22
+ # Whether to resize the document's window to fit the size of
23
+ # first displayed page - Default: false
24
+ doc.setFitWindow(true)
25
+
26
+ # Whether to hide menu bar of the viewer application - Default: false
27
+ doc.setHideMenubar(true)
28
+
29
+ # Whether to hide tool bar of the viewer application - Default: false
30
+ doc.setHideToolBar(true)
31
+
32
+ # Whether to hide UI elements like scroll bars
33
+ # and leaving only the page contents displayed - Default: false
34
+ doc.setHideWindowUI(true)
35
+
36
+ # The document's page mode. How to display document on exiting full-screen mode.
37
+ doc.setNonFullScreenPageMode(Rjb::import('com.aspose.pdf.PageMode.UseOC'))
38
+
39
+ # The page layout i.e. single page, one column
40
+ doc.setPageLayout(Rjb::import('com.aspose.pdf.PageLayout.TwoColumnLeft'))
41
+
42
+ #How the document should display when opened.
43
+ doc.setPageMode()
44
+
45
+ # Save updated PDF file
46
+ doc.save("Set Document Window.pdf")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ module Asposepdfjava
2
+ module SetExpiration
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ javascript = Rjb::import('com.aspose.pdf.JavascriptAction').new(
11
+ "var year=2014;
12
+ var month=4;
13
+ today = new Date();
14
+ today = new Date(today.getFullYear(), today.getMonth());
15
+ expiry = new Date(year, month);
16
+ if (today.getTime() > expiry.getTime())
17
+ app.alert('The file is expired. You need a new one.');")
18
+ doc.setOpenAction(javascript)
19
+
20
+ # save update document with new information
21
+ doc.save(data_dir + "set_expiration.pdf")
22
+
23
+ puts "Update document information, please check output file."
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Asposepdfjava
2
+ module SetPdfFileInfo
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open a pdf document.
8
+ doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
9
+
10
+ # Get document information
11
+ doc_info = doc.getInfo()
12
+
13
+ doc_info.setAuthor("Aspose.Pdf for java")
14
+ doc_info.setCreationDate(Rjb::import('java.util.Date').new)
15
+ doc_info.setKeywords("Aspose.Pdf, DOM, API")
16
+ doc_info.setModDate(Rjb::import('java.util.Date').new)
17
+ doc_info.setSubject("PDF Information")
18
+ doc_info.setTitle("Setting PDF Document Information")
19
+
20
+ # save update document with new information
21
+ doc.save(data_dir + "Updated_Information.pdf")
22
+
23
+ puts "Update document information, please check output file."
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module Asposepdfjava
2
+ module ConcatenatePdfFiles
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open the target document
8
+ pdf1 = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input1.pdf')
9
+
10
+ # Open the source document
11
+ pdf2 = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input2.pdf')
12
+
13
+ # Add the pages of the source document to the target document
14
+ pdf1.getPages().add(pdf2.getPages())
15
+
16
+ # Save the concatenated output file (the target document)
17
+ pdf1.save(data_dir+ "Concatenate_output.pdf")
18
+
19
+ puts "New document has been saved, please check the output file"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Asposepdfjava
2
+ module DeletePage
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open the target document
8
+ pdf = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input1.pdf')
9
+
10
+ # delete a particular page
11
+ pdf.getPages().delete(2)
12
+
13
+ # save the newly generated PDF file
14
+ pdf.save(data_dir + "output.pdf")
15
+
16
+ puts "Page deleted successfully!"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Asposepdfjava
2
+ module GetNumberOfPages
3
+ def initialize()
4
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
5
+
6
+ # Create PDF document
7
+ pdf = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input1.pdf')
8
+
9
+ page_count = pdf.getPages().size()
10
+
11
+ puts "Page Count:" + page_count.to_s
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module Asposepdfjava
2
+ module GetPage
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
6
+
7
+ # Open the target document
8
+ pdf = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input1.pdf')
9
+
10
+ # get the page at particular index of Page Collection
11
+ pdf_page = pdf.getPages().get_Item(1)
12
+
13
+ # create a new Document object
14
+ new_document = Rjb::import('com.aspose.pdf.Document').new
15
+
16
+ # add page to pages collection of new document object
17
+ new_document.getPages().add(pdf_page)
18
+
19
+ # save the newly generated PDF file
20
+ new_document.save(data_dir + "output.pdf")
21
+
22
+ puts "Process completed successfully!"
23
+ end
24
+ end
25
+ end