Skip to content
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
2 changes: 1 addition & 1 deletion Examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>19.3</version>
<version>19.4</version>
</dependency>
<dependency>
<groupId>javax.media.jai</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package com.aspose.pdf.examples.AsposePdfExamples.DocumentConversion;

import com.aspose.pdf.*;
import com.aspose.pdf.taggedpdf.TaggedPdfFigureElement;
import com.aspose.pdf.tagged.ITaggedContent;
import com.aspose.pdf.tagged.logicalstructure.elements.IllustrationElement;
import com.aspose.pdf.tagged.logicalstructure.elements.bls.HeaderElement;
import com.aspose.pdf.tagged.logicalstructure.elements.bls.ParagraphElement;

public class CreatePDFwithTaggedImage {
public static void main(String[] args) {
// Initialize new PDF Document
Document doc = new Document();

Page page1 = doc.getPages().add();
// Create image
Image image = new Image();
// Assign image file
image.setFile("aspose-logo.jpg");
// ExStart:CreatePDFWithTaggedImage
Document document = new Document();
ITaggedContent taggedContent = document.getTaggedContent();

// Create BBox element
Rectangle BBox = new Rectangle(30, 70, 300, 720);
// Create tagged figure element
TaggedPdfFigureElement figureElement = new TaggedPdfFigureElement(doc, image, BBox);
Rectangle BBox1 = new Rectangle(550, 570, 300, 720);
TaggedPdfFigureElement figureElement1 = new TaggedPdfFigureElement(doc, image, BBox1);
// Add tagged figure element into content
page1.getContents().add((Iterable<Operator>) figureElement);
page1.getContents().add((Iterable<Operator>) figureElement1);
// Save PDF Document
doc.save("PDFwithTaggedImage_out.pdf");
taggedContent.setTitle("CreatePDFwithTaggedImage");
taggedContent.setLanguage("en-US");

IllustrationElement figure1 = taggedContent.createFigureElement();
taggedContent.getRootElement().appendChild(figure1);
figure1.setAlternativeText("Aspose Logo");
figure1.setTitle("Image 1");
figure1.setTag("Fig");
// Add image with resolution 300 DPI (by default)
figure1.setImage("aspose-logo.jpg");
// Save PDF Document
document.save("PDFwithTaggedImage.pdf");
// ExEnd:CreatePDFWithTaggedImage
}

}
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
package com.aspose.pdf.examples.AsposePdfExamples.DocumentConversion;

import com.aspose.pdf.Document;
import com.aspose.pdf.EpubLoadOptions;
import com.aspose.pdf.Operator;
import com.aspose.pdf.taggedpdf.TaggedPdfBlockLevelTextElement;
import com.aspose.pdf.tagged.ITaggedContent;
import com.aspose.pdf.tagged.logicalstructure.elements.bls.HeaderElement;
import com.aspose.pdf.tagged.logicalstructure.elements.bls.ParagraphElement;


public class CreatePDFwithTaggedText {
public static void main(String[] args) {
// 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 Pdf Document
Document document = new Document();
// Get Content for work with TaggedPdf
ITaggedContent taggedContent = document.getTaggedContent();

// Create TextState and configure it
com.aspose.pdf.TextState ts = new com.aspose.pdf.TextState();
ts.setFont(com.aspose.pdf.FontRepository.findFont("Arial"));
// Set Title and Language for Documnet
taggedContent.setTitle("Tagged Pdf Document");
taggedContent.setLanguage("en-US");

// Creating tagged text element
// Supported tags P, H,H1-H6
TaggedPdfBlockLevelTextElement textElement1 = new TaggedPdfBlockLevelTextElement(doc, "P", "text", ts);
TaggedPdfBlockLevelTextElement textElement2 = new TaggedPdfBlockLevelTextElement(doc, "P", "test1", ts);
TaggedPdfBlockLevelTextElement textElement3 = new TaggedPdfBlockLevelTextElement(doc, "P", "test2", ts);
TaggedPdfBlockLevelTextElement textElement4 = new TaggedPdfBlockLevelTextElement(doc, "P", "test3", ts);
TaggedPdfBlockLevelTextElement textElement5 = new TaggedPdfBlockLevelTextElement(doc, "P", "test4", ts);
TaggedPdfBlockLevelTextElement textElement6 = new TaggedPdfBlockLevelTextElement(doc, "P", "test5", ts);
TaggedPdfBlockLevelTextElement textElement7 = new TaggedPdfBlockLevelTextElement(doc, "P", "test6", ts);
TaggedPdfBlockLevelTextElement textElement8 = new TaggedPdfBlockLevelTextElement(doc, "P", "test7", ts);
// Create Text Block-Level Structure Elements
HeaderElement headerElement = taggedContent.createHeaderElement();
headerElement.setActualText("Heading 1");
ParagraphElement paragraphElement1 = taggedContent.createParagraphElement();
paragraphElement1.setActualText("test1");
ParagraphElement paragraphElement2 = taggedContent.createParagraphElement();
paragraphElement2.setActualText("test 2");
ParagraphElement paragraphElement3 = taggedContent.createParagraphElement();
paragraphElement3.setActualText("test 3");
ParagraphElement paragraphElement4 = taggedContent.createParagraphElement();
paragraphElement4.setActualText("test 4");
ParagraphElement paragraphElement5 = taggedContent.createParagraphElement();
paragraphElement5.setActualText("test 5");
ParagraphElement paragraphElement6 = taggedContent.createParagraphElement();
paragraphElement6.setActualText("test 6");
ParagraphElement paragraphElement7 = taggedContent.createParagraphElement();
paragraphElement7.setActualText("test 7");

// Add tagged text element to content
page1.getContents().add((Iterable<Operator>) textElement1);
page1.getContents().add((Iterable<Operator>) textElement2);
page1.getContents().add((Iterable<Operator>) textElement3);
page1.getContents().add((Iterable<Operator>) textElement4);
page1.getContents().add((Iterable<Operator>) textElement5);
page1.getContents().add((Iterable<Operator>) textElement6);
page1.getContents().add((Iterable<Operator>) textElement7);
page1.getContents().add((Iterable<Operator>) textElement8);
// Save PDF Document
doc.save("PDFwithTaggedText_out.pdf");
// Save PDF Document
document.save( "PDFwithTaggedText.pdf");
// ExEnd:CreatePDFwithTaggedImage
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.aspose.pdf.examples.AsposePdfExamples.Text;

import com.aspose.pdf.Document;
import com.aspose.pdf.HtmlFragment;
import com.aspose.pdf.Page;

public class AddHTMLOrderedListIntoDocuments {
public static void main(String[] args) {
// ExStart:AddHTMLOrderedListIntoDocuments
// Instantiate Document object
Document doc = new Document();
// Instantiate HtmlFragment object with corresponding HTML fragment
HtmlFragment t = new HtmlFragment("`<body style='line-height: 100px;'><ul><li>First</li><li>Second</li><li>Third</li><li>Fourth</li><li>Fifth</li></ul>Text after the list.<br/>Next line<br/>Last line</body>`");
// Add Page in Pages Collection
Page page = doc.getPages().add();
// Add HtmlFragment inside page
page.getParagraphs().add(t);
// Save resultant PDF file
doc.save("AddHTMLOrderedListIntoDocuments_out.pdf");
// ExEnd:AddHTMLOrderedListIntoDocuments
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.aspose.pdf.examples.AsposePdfExamples.Text;

import com.aspose.pdf.Document;
import com.aspose.pdf.HtmlFragment;
import com.aspose.pdf.Page;
import com.aspose.pdf.TextState;

public class AddHTMLUsingDOMAndOverwrite {
public static void main(String[] args) {
// ExStart:AddHTMLUsingDOMAndOverwrite
// Instantiate Document object
Document doc = new Document();
// Add a page to pages collection of PDF file
Page page = doc.getPages().add();
// Instantiate HtmlFragment with HTML contnets
HtmlFragment title = new HtmlFragment("<p style='font-family: Verdana'><b><i>Table contains text</i></b></p>");
//Font-family from 'Verdana' will be reset to 'Arial'
title.setTextState(new TextState("Arial"));
title.setTextState(new TextState(20));
// Set bottom margin information
title.getMargin().setBottom(10);
// Set top margin information
title.getMargin().setTop(400);
// Add HTML Fragment to paragraphs collection of page
page.getParagraphs().add(title);
// Save PDF file
doc.save("AddHTMLUsingDOMAndOverwrite_out.pdf");
// ExEnd:AddHTMLUsingDOMAndOverwrite
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.aspose.pdf.examples.AsposePdfExamples.Text;

import com.aspose.pdf.*;

public class UseLatexScript {
public static void main(String[] args) {
// ExStart:UseLatexScript
// Create a new Document Object
Document doc = new Document();
// Add Page in Pages Collection
Page page = doc.getPages().add();
// Create a Table
Table table = new Table();
// Add a row into Table
Row row = table.getRows().add();
// Add Cell with Latex Script to add methematical expressions/formulae
String latexText1 = "$123456789+\\sqrt{1}+\\int_a^b f(x)dx$";
Cell cell = row.getCells().add();
MarginInfo marginInfo = new MarginInfo();
marginInfo.setLeft(20);
marginInfo.setRight(20);
marginInfo.setTop(20);
marginInfo.setBottom(20);
cell.setMargin(marginInfo);
// Second LatexFragment constructor bool parameter provides LaTeX paragraph indents elimination.
LatexFragment ltext1 = new LatexFragment(latexText1, true);
cell.getParagraphs().add(ltext1);
// Add table inside page
page.getParagraphs().add(table);
// Save the document
doc.save("LatextScriptInPdf_out.pdf");
// ExEnd:UseLatexScript
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.aspose.pdf.examples.AsposePdfFacades.SecurityAndSignatures;

import com.aspose.pdf.PKCS7;
import com.aspose.pdf.SignatureCustomAppearance;
import com.aspose.pdf.facades.PdfFileSignature;

import java.awt.*;
import java.util.Date;

public class ChangeLanguageInDigitalSignText {
public static void main(String[] args) {
// ExStart:ChangeLanguageInDigitalSignText
// Path to Directory
String dataDir = "PathToDir";
// create PdfFileSignature object and bind input PDF files
String inPfxFile = dataDir + "certificate.pfx";
String inFile = dataDir + "input.pdf";
String outFile = dataDir + "output.pdf";
PdfFileSignature pdfSign = new PdfFileSignature();
pdfSign.bindPdf(inFile);
//create a rectangle for signature location
Rectangle rect = new Rectangle(310, 45, 200, 50);

//create any of the three signature types
PKCS7 pkcs = new PKCS7(inPfxFile, "12345");
pkcs.setReason("Pruebas Firma");
pkcs.setContactInfo("Contacto Pruebas");
pkcs.setLocation("Población (Provincia)");
pkcs.setDate(new Date());
SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance();
signatureCustomAppearance.setDateSignedAtLabel("Fecha");
signatureCustomAppearance.setDigitalSignedLabel("Digitalmente firmado por");
signatureCustomAppearance.setReasonLabel("Razón");
signatureCustomAppearance.setLocationLabel("Localización");
signatureCustomAppearance.setFontFamilyName("Arial");
signatureCustomAppearance.setFontSize(10d);
signatureCustomAppearance.setDateTimeFormat("yyyy.MM.dd HH:mm:ss");
pkcs.setCustomAppearance(signatureCustomAppearance);
// sign the PDF file
pdfSign.sign(1, true, rect, pkcs);
//save output PDF file
pdfSign.save(outFile);

// ExEnd:ChangeLanguageInDigitalSignText
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.aspose.pdf.examples.AsposePdfFacades.SecurityAndSignatures;

import com.aspose.pdf.PKCS1;
import com.aspose.pdf.facades.PdfFileSignature;

import java.awt.*;
import java.io.IOException;

public class SuppressLocationAndReason {
public static void main(String[] args) {
// ExStart:SuppressLocationAndReason
// The path to the documents directory.
String dataDir = "PathToDir";
String inPfxFile = dataDir + "certificate.pfx";
String inFile = dataDir + "input.pdf";
String outFile = dataDir + "output.pdf";
PdfFileSignature pdfSign = new PdfFileSignature();

pdfSign.bindPdf(inFile);
//create a rectangle for signature location
Rectangle rect = new Rectangle(100, 100, 200, 100);

//create any of the three signature types
PKCS1 signature = new PKCS1(inPfxFile, "12345");
// sign the PDF file
pdfSign.sign(1, "", "Contact", "", true, rect, signature);
//save output PDF file
pdfSign.save(outFile);
// ExEnd:SuppressLocationAndReason
}
}