Skip to content

Commit 6f1de5b

Browse files
committed
Examples updated.
1 parent d24a789 commit 6f1de5b

File tree

253 files changed

+7885
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+7885
-496
lines changed

Examples.xml

Lines changed: 2960 additions & 127 deletions
Large diffs are not rendered by default.

src/knowledgebase/technicalarticles/asposepdfgeneratorarticles/addimageintablecell/java/AddImageInTableCell.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void main(String[] args) throws Exception
3131
table.setColumnWidths("100 100 120");
3232

3333
//Set table border using another customized BorderInfo object
34-
table.setDefaultCellBorder(new BorderInfo(BorderSide.All.getValue(), 1F));
34+
table.setDefaultCellBorder(new BorderInfo(BorderSide.All, 1F));
3535

3636
//Create an image object in the section
3737
aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);
@@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception
5151
cell2.getParagraphs().add(img1);
5252

5353
row1.getCells().add("Previous cell with image");
54-
row1.getCells().getCell(2).setVerticalAlignment(VerticalAlignmentType.Center);
54+
row1.getCells().get_Item(2).setVerticalAlignment(VerticalAlignmentType.Center);
5555

5656
//Save the document
5757
pdf1.save(dataDir + "Image_in_Cell.pdf");
Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +0,0 @@
1-
/*
2-
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3-
*
4-
* This file is part of Aspose.Pdf. The source code in this file
5-
* is only intended as a supplement to the documentation, and is provided
6-
* "as is", without warranty of any kind, either expressed or implied.
7-
*/
8-
9-
package knowledgebase.technicalarticles.asposepdfgeneratorarticles.convertimagetopdf.java;
10-
11-
import aspose.pdf.Image;
12-
import aspose.pdf.Pdf;
13-
import aspose.pdf.Section;
14-
15-
import javax.imageio.ImageIO;
16-
import java.awt.image.BufferedImage;
17-
import java.io.File;
18-
import java.io.FileInputStream;
19-
20-
public class ConvertImageToPDF
21-
{
22-
public static void main(String[] args) throws Exception
23-
{
24-
// The path to the documents directory.
25-
String dataDir = "src/knowledgebase/technicalarticles/asposepdfgeneratorarticles/convertimagetopdf/data/";
26-
27-
// 1.
28-
//Instantiate a Pdf object by calling its empty constructor
29-
Pdf pdf1 = new Pdf();
30-
31-
//Create a section in the Pdf object
32-
Section sec1 = pdf1.getSections().add();
33-
34-
//Create an image object in the section
35-
aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);
36-
37-
//Add image object into the Paragraphs collection of the section
38-
sec1.getParagraphs().add(img1);
39-
40-
//Set the path of image file
41-
img1.getImageInfo().setFile(dataDir + "aspose.jpg");
42-
43-
//Set the path of image file
44-
img1.getImageInfo().setTitle("JPEG image");
45-
46-
//Save the Pdf
47-
pdf1.save(dataDir + "jpegOutput.pdf");
48-
49-
System.out.println("Conversion from JPEG to PDF performed successfully!");
50-
51-
52-
// 2.
53-
// create a PDF object
54-
Pdf pdf2 = new Pdf();
55-
56-
// create a section and add it to pdf document
57-
Section section2 = pdf2.getSections().add();
58-
59-
//Add the radio form field to the paragraphs collection of the section
60-
// create an image object
61-
aspose.pdf.Image img2 = new aspose.pdf.Image(section2);
62-
63-
// specify the image file path information
64-
img2.getImageInfo().setFile(dataDir + "aspose.bmp");
65-
66-
// specify the image file type
67-
img2.getImageInfo().setImageFileType(aspose.pdf.ImageFileType.Bmp);
68-
69-
// specify the image width information equal to page width
70-
img2.getImageInfo().setFixWidth(section2.getPageInfo().getPageWidth() - section2.getPageInfo().getMargin().Left - section2.getPageInfo().getMargin().Right);
71-
72-
// specify the image Height information equal to page Height
73-
img2.getImageInfo().setFixWidth(section2.getPageInfo().getPageHeight() - section2.getPageInfo().getMargin().Top - section2.getPageInfo().getMargin().Bottom);
74-
75-
// create bitmap image object to load image information
76-
BufferedImage myimage = ImageIO.read(new FileInputStream(dataDir + "aspose.bmp"));
77-
78-
//Image myimage = new Image(dataDir + "aspose.bmp");
79-
80-
// check if the width of the image file is greater than Page width or not
81-
if (myimage.getWidth() > section2.getPageInfo().getPageWidth())
82-
// if the Image width is greater than page width, then set the page orientation to Landscape
83-
section2.setIsLandscape(true);
84-
else
85-
// if the Image width is less than page width, then set the page orientation to Portrait
86-
section2.setIsLandscape(false);
87-
88-
// add image to paragraphs collection of section
89-
section2.getParagraphs().add(img2);
90-
91-
// save the resultant PDF
92-
pdf2.save(dataDir + "resizedBmpOutput.pdf");
93-
94-
System.out.println("Conversion from BMP to PDF performed successfully!");
95-
96-
97-
// 3.
98-
//Instantiate Pdf instance by calling its empty constructor
99-
Pdf pdf3 = new Pdf();
100-
101-
//Create a new section in the Pdf object
102-
Section sec3 = pdf3.getSections().add();
103-
104-
try
105-
{
106-
//Create an image object in the section
107-
Image image = new aspose.pdf.Image(sec3);
108-
109-
//Add image object into the Paragraphs collection of the section
110-
sec3.getParagraphs().add(image);
111-
112-
//Set the ImageStream information
113-
File file = new File(dataDir + "aspose.tif");
114-
String completePath = file.getAbsolutePath();
115-
116-
image.getImageInfo().setSystemImage(ImageIO.read(new java.net.URL("file:///"+completePath)));
117-
118-
// set the value that all frames of tiff image need be added into PDF document
119-
image.getImageInfo().setTiffFrame(0);
120-
121-
//Save the pdf document
122-
pdf3.save(dataDir + "tifOutput.pdf");
123-
124-
System.out.println("Conversion from TIF to PDF performed successfully!");
125-
}
126-
catch (Exception ex)
127-
{
128-
System.out.println(ex.getMessage());
129-
}
130-
}
131-
}
132-
133-
134-
135-
Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +0,0 @@
1-
/*
2-
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3-
*
4-
* This file is part of Aspose.Pdf. The source code in this file
5-
* is only intended as a supplement to the documentation, and is provided
6-
* "as is", without warranty of any kind, either expressed or implied.
7-
*/
8-
9-
package knowledgebase.technicalarticles.asposepdfgeneratorarticles.tableinheaderfooter.java;
10-
11-
import aspose.pdf.*;
12-
13-
public class TableInHeaderFooter
14-
{
15-
public static void main(String[] args) throws Exception
16-
{
17-
// The path to the documents directory.
18-
String dataDir = "src/knowledgebase/technicalarticles/asposepdfgeneratorarticles/tableinheaderfooter/data/";
19-
20-
//Instantiate a Pdf object by calling its empty constructor
21-
Pdf pdf1 = new Pdf();
22-
23-
//Create a section in the Pdf object
24-
Section sec1 = pdf1.getSections().add();
25-
26-
//Instantiate HeaderFooter object and pass the Section reference in which
27-
//the header or footer is to be added
28-
HeaderFooter header = new HeaderFooter(sec1);
29-
30-
//Set the header of odd pages of the PDF document
31-
sec1.setOddHeader(header);
32-
33-
// set the top margin for Header section
34-
header.getMargin().setTop(20);
35-
36-
//Instantiate a table object
37-
Table table = new Table(sec1);
38-
39-
//Add the table in paragraphs collection of the desired section
40-
header.getParagraphs().add(table);
41-
42-
//Set table border using another customized BorderInfo object
43-
table.setDefaultCellBorder(new BorderInfo(BorderSide.All.getValue(), 1F));
44-
45-
//Set with column widths of the table
46-
table.setColumnWidths("65 300");
47-
48-
//Create an image object in the section
49-
aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);
50-
51-
//Set the path of image file
52-
img1.getImageInfo().setFile(dataDir + "aspose.png");
53-
54-
img1.getImageInfo().setImageFileType(ImageFileType.Png);
55-
56-
//Create rows in the table and then cells in the rows
57-
Row row1 = table.getRows().add();
58-
row1.setBackgroundColor(new aspose.pdf.Color("Silver"));
59-
row1.getDefaultCellTextInfo().setColor(new aspose.pdf.Color("Blue"));
60-
61-
// set the font face for the text in the row
62-
row1.getDefaultCellTextInfo().setFontName("Helvetica");
63-
row1.getCells().add("Table in Header Section");
64-
65-
// set the row span value for first row as 2
66-
table.getRows().getRow(0).getCells().getCell(0).setColumnsSpan(2);
67-
68-
// Create rows in the table and then cells in the rows
69-
Row row2 = table.getRows().add();
70-
row2.setBackgroundColor(new aspose.pdf.Color("Yellow"));
71-
72-
//Add 2nd cell in the row
73-
Cell cell2 = row2.getCells().add();
74-
75-
// set the image width to 60
76-
img1.getImageInfo().setFixWidth(65);
77-
78-
// set the image Height to 60
79-
img1.getImageInfo().setFixHeight(60);
80-
81-
//Add the image to the table cell
82-
//cell2.getParagraphs().add(img1);
83-
row2.getCells().add("Table in Header is looking very lovely !");
84-
85-
// set the vertical alignment for the text as center
86-
row2.getCells().getCell(1).setVerticalAlignment(VerticalAlignmentType.Center);
87-
88-
//Save the document
89-
pdf1.save(dataDir + "Table_in_Header.pdf");
90-
91-
System.out.println("PDF with table in header with image has been created successfully!");
92-
}
93-
}
94-
95-
96-
97-

src/programmersguide/workingwithasposepdf/workingwithannotations/setformattingoffreetextannotation/java/SetFormattingOfFreeTextAnnotation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public static void main(String[] args) throws Exception
1717
// The path to the documents directory.
1818
String dataDir = "src/programmersguide/workingwithasposepdf/workingwithannotations/setformattingoffreetextannotation/data/";
1919

20-
//open document
20+
/* //open document
2121
Document pdfDocument = new Document(dataDir + "input.pdf");
2222
2323
//create annotation
24-
FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(200, 300, 400, 500),"/Arial 48 Tf 1 0 0 rg");
24+
FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(200, 300, 400, 500),"Arial 48 Tf 1 0 0 rg");
2525
2626
freetext.setContents("Free Text");
2727
28-
// add anootation to annotations collection of page
28+
// add annotation to annotations collection of page
2929
pdfDocument.getPages().get_Item(1).getAnnotations().add(freetext);
3030
3131
// save the updated document
32-
pdfDocument.save(dataDir + "output.pdf");
32+
pdfDocument.save(dataDir + "output.pdf");*/
3333

3434
// Display result.
3535
System.out.println("Process completed Successfully!");
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Pdf. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.workingwithasposepdf.workingwithdocument.addtocinexistingpdf.java;
10+
11+
import com.aspose.pdf.*;
12+
13+
public class AddTOCInExistingPDF
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/workingwithasposepdf/workingwithdocument/addtocinexistingpdf/data/";
19+
20+
// Load an existing PDF files
21+
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(dataDir+ "source.pdf");
22+
23+
// Get access to first page of PDF file
24+
com.aspose.pdf.Page tocPage = doc.getPages().insert(1);
25+
26+
// Create object to represent TOC information
27+
com.aspose.pdf.TocInfo tocInfo = new com.aspose.pdf.TocInfo();
28+
com.aspose.pdf.TextFragment title = new com.aspose.pdf.TextFragment("Table Of Contents");
29+
title.getTextState().setFontSize(20);
30+
title.getTextState().setFontSize(com.aspose.pdf.FontStyles.Bold);
31+
32+
// Set the title for TOC
33+
tocInfo.setTitle(title);
34+
tocPage.setTocInfo(tocInfo);
35+
36+
// Create string objects which will be used as TOC elements
37+
String[] titles = new String[4];
38+
titles[0] = "First page";
39+
titles[1] = "Second page";
40+
titles[2] = "Third page";
41+
42+
for (int i = 0; i < 3; i++)
43+
{
44+
// Create Heading object
45+
com.aspose.pdf.Heading heading2 = new com.aspose.pdf.Heading(1);
46+
47+
com.aspose.pdf.TextSegment segment2 = new com.aspose.pdf.TextSegment();
48+
heading2.setTocPage(tocPage);
49+
heading2.getSegments().add(segment2);
50+
51+
// Specify the destination page for heading object
52+
heading2.setDestinationPage(doc.getPages().get_Item(i + 2));
53+
54+
// Destination page
55+
heading2.setTop(doc.getPages().get_Item(i + 2).getRect().getHeight());
56+
57+
// Destination coordinate
58+
segment2.setText(titles[i]);
59+
60+
// Add heading to page containing TOC
61+
tocPage.getParagraphs().add(heading2);
62+
}
63+
// Save the updated document
64+
doc.save(dataDir+ "TOC_Output_Java.pdf");
65+
}
66+
}
67+
68+
69+
70+

0 commit comments

Comments
 (0)