Last active
September 2, 2020 16:10
-
-
Save aspose-com-gists/282750bc23ba43d2659ba38470239283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gists for Aspose.PDF for Java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.setFontSize(20); | |
annot.setOverlayText("REDACTED"); | |
annot.setTextAlignment(HorizontalAlignment.Center); | |
annot.setRepeat(true); | |
doc.getPages().get_Item(1).getAnnotations().add(annot); | |
doc.save("Redaction_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "DocumentConversion\\" ; | |
// Initialize HTMLLoadSave Options | |
HtmlLoadOptions options = new HtmlLoadOptions(); | |
// Set Render to single page property | |
options.setRenderToSinglePage(true); | |
// Load document | |
Document doc = new Document(datadir + "HTMLToPDF.html", options); | |
// Save | |
doc.save(datadir + "RenderContentToSamePage.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "DocumentConversion\\" ; | |
// Set input file path | |
String inFile = dataDir + "HTMLSVG.html"; | |
// Set output file path | |
String outFile = dataDir + "RenderHTMLwithSVGData.pdf"; | |
// Initialize HtmlLoadOptions | |
HtmlLoadOptions options = new HtmlLoadOptions(inFile); | |
// Initialize Document object | |
Document pdfDocument = new Document(inFile, options); | |
// save | |
pdfDocument.save(outFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = Utils.getSharedDataDir(ConvertPDFFileIntoXPSFormat.class) + "DocumentConversion/"; | |
// load PDF document | |
Document doc = new Document(dataDir + "Input.pdf"); | |
// instantiate an object of SvgSaveOptions | |
XpsSaveOptions saveOptions = new XpsSaveOptions(); | |
// Allow text selectable in output XPS | |
saveOptions.setSaveTransparentTexts(true); | |
// save the output in XPS files | |
doc.save(dataDir + "KeepingTextSelectableInConvertedXPS_out.xps", saveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "DocumentConversion\\"; | |
HtmlSaveOptions htmlOptions = new HtmlSaveOptions(); | |
htmlOptions.setExplicitListOfSavedPages(new int[] { 1 }); | |
htmlOptions.setFixedLayout(true); | |
htmlOptions.setCompressSvgGraphicsIfAny(false); | |
htmlOptions.SaveTransparentTexts=true; | |
htmlOptions.SaveShadowedTextsAsTransparentTexts=true; | |
htmlOptions.ExcludeFontNameList= (new String[] { "ArialMT", "SymbolMT" }); | |
//htmlOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.DontSave; | |
htmlOptions.setDefaultFontName("Comic Sans MS"); | |
htmlOptions.setUseZOrder(true); | |
htmlOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss; | |
htmlOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.NoEmbedding; | |
htmlOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground; | |
htmlOptions.setSplitIntoPages(false); | |
Document pdfDocument = new Document(dataDir + "PDFJAVA-39123.pdf"); | |
pdfDocument.save(dataDir + "output_out.html", htmlOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String path = "pathTodir"; | |
// Open Pdf Document | |
Document document = new Document( path +"StructureElements.pdf"); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Access to root element(s) | |
ElementList elementList = taggedContent.getStructTreeRootElement().getChildElements(); | |
for (Element element : elementList) | |
{ | |
if (element instanceof StructureElement) | |
{ | |
StructureElement structureElement = (StructureElement)element; | |
// Get properties | |
String title = structureElement.getTitle(); | |
String language = structureElement.getLanguage(); | |
String actualText = structureElement.getActualText(); | |
String expansionText = structureElement.getExpansionText(); | |
String alternativeText = structureElement.getAlternativeText(); | |
} | |
} | |
// Access to children elements of first element in root element | |
elementList = taggedContent.getRootElement().getChildElements().get_Item(1).getChildElements(); | |
for (Element element : elementList) | |
{ | |
if (element instanceof StructureElement) | |
{ | |
StructureElement structureElement = (StructureElement)element; | |
// Set properties | |
structureElement.setTitle("title"); | |
structureElement.setLanguage("fr-FR"); | |
structureElement.setActualText("actual text"); | |
structureElement.setExpansionText("exp"); | |
structureElement.setAlternativeText("alt"); | |
} | |
} | |
// Save Tagged Pdf Document | |
document.save( path +"AccessChildrenElements.pdf"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Create Grouping Elements | |
PartElement partElement = taggedContent.createPartElement(); | |
ArtElement artElement = taggedContent.createArtElement(); | |
SectElement sectElement = taggedContent.createSectElement(); | |
DivElement divElement = taggedContent.createDivElement(); | |
BlockQuoteElement blockQuoteElement = taggedContent.createBlockQuoteElement(); | |
CaptionElement captionElement = taggedContent.createCaptionElement(); | |
TOCElement tocElement = taggedContent.createTOCElement(); | |
TOCIElement tociElement = taggedContent.createTOCIElement(); | |
IndexElement indexElement = taggedContent.createIndexElement(); | |
NonStructElement nonStructElement = taggedContent.createNonStructElement(); | |
PrivateElement privateElement = taggedContent.createPrivateElement(); | |
// Create Text Block-Level Structure Elements | |
ParagraphElement paragraphElement = taggedContent.createParagraphElement(); | |
HeaderElement headerElement = taggedContent.createHeaderElement(); | |
HeaderElement h1Element = taggedContent.createHeaderElement(1); | |
// Create Text Inline-Level Structure Elements | |
SpanElement spanElement = taggedContent.createSpanElement(); | |
QuoteElement quoteElement = taggedContent.createQuoteElement(); | |
NoteElement noteElement = taggedContent.createNoteElement(); | |
// Create Illustration Structure Elements | |
FigureElement figureElement = taggedContent.createFigureElement(); | |
FormulaElement formulaElement = taggedContent.createFormulaElement(); | |
// Methods are under development | |
ListElement listElement = taggedContent.createListElement(); | |
TableElement tableElement = taggedContent.createTableElement(); | |
ReferenceElement referenceElement = taggedContent.createReferenceElement(); | |
BibEntryElement bibEntryElement = taggedContent.createBibEntryElement(); | |
CodeElement codeElement = taggedContent.createCodeElement(); | |
LinkElement linkElement = taggedContent.createLinkElement(); | |
AnnotElement annotElement = taggedContent.createAnnotElement(); | |
RubyElement rubyElement = taggedContent.createRubyElement(); | |
WarichuElement warichuElement = taggedContent.createWarichuElement(); | |
FormElement formElement = taggedContent.createFormElement(); | |
// Save Tagged Pdf Document | |
document.save(path + "StructureElements.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Get root structure element (Document) | |
StructureElement rootElement = taggedContent.getRootElement(); | |
// Create Logical Structure | |
SectElement sect1 = taggedContent.createSectElement(); | |
rootElement.appendChild(sect1); | |
SectElement sect2 = taggedContent.createSectElement(); | |
rootElement.appendChild(sect2); | |
DivElement div11 = taggedContent.createDivElement(); | |
sect1.appendChild(div11); | |
DivElement div12 = taggedContent.createDivElement(); | |
sect1.appendChild(div12); | |
ArtElement art21 = taggedContent.createArtElement(); | |
sect2.appendChild(art21); | |
ArtElement art22 = taggedContent.createArtElement(); | |
sect2.appendChild(art22); | |
DivElement div211 = taggedContent.createDivElement(); | |
art21.appendChild(div211); | |
DivElement div212 = taggedContent.createDivElement(); | |
art21.appendChild(div212); | |
DivElement div221 = taggedContent.createDivElement(); | |
art22.appendChild(div221); | |
DivElement div222 = taggedContent.createDivElement(); | |
art22.appendChild(div222); | |
SectElement sect3 = taggedContent.createSectElement(); | |
rootElement.appendChild(sect3); | |
DivElement div31 = taggedContent.createDivElement(); | |
sect3.appendChild(div31); | |
// Save Tagged Pdf Document | |
document.save(path + "StructureElementsTree.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Create Logical Structure Elements | |
SectElement sect = taggedContent.createSectElement(); | |
taggedContent.getRootElement().appendChild(sect); | |
ParagraphElement p1 = taggedContent.createParagraphElement(); | |
ParagraphElement p2 = taggedContent.createParagraphElement(); | |
ParagraphElement p3 = taggedContent.createParagraphElement(); | |
ParagraphElement p4 = taggedContent.createParagraphElement(); | |
p1.setText("P1. "); | |
p2.setText("P2. "); | |
p3.setText("P3. "); | |
p4.setText("P4. "); | |
p1.setTag("P1"); | |
p2.setTag("Para"); | |
p3.setTag("Para"); | |
p4.setTag("Paragraph"); | |
sect.appendChild(p1); | |
sect.appendChild(p2); | |
sect.appendChild(p3); | |
sect.appendChild(p4); | |
SpanElement span1 = taggedContent.createSpanElement(); | |
SpanElement span2 = taggedContent.createSpanElement(); | |
SpanElement span3 = taggedContent.createSpanElement(); | |
SpanElement span4 = taggedContent.createSpanElement(); | |
span1.setText("Span 1."); | |
span2.setText("Span 2."); | |
span3.setText("Span 3."); | |
span4.setText("Span 4."); | |
span1.setTag("SPAN"); | |
span2.setTag("Sp"); | |
span3.setTag("Sp"); | |
span4.setTag("TheSpan"); | |
p1.appendChild(span1); | |
p2.appendChild(span2); | |
p3.appendChild(span3); | |
p4.appendChild(span4); | |
// Save Tagged Pdf Document | |
document.save(path + "CustomTag.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
// Initialize document object | |
Document document = new Document(); | |
//Add page | |
Page page = document.getPages().add(); | |
// Add text to new page | |
page.getParagraphs().add(new TextFragment("Hello World!")); | |
// Save updated PDF | |
document.save("HelloWorld_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Under Development | |
IllustrationElement figure1 = taggedContent.createFigureElement(); | |
taggedContent.getRootElement().appendChild(figure1); | |
figure1.setActualText("Figure One"); | |
figure1.setTitle("Image 1"); | |
figure1.setTag("Fig1"); | |
figure1.setImage("image.png"); | |
// Save Tagged Pdf Document | |
document.save(path + "IllustrationStructureElements.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Get Root Structure Element | |
StructureElement rootElement = taggedContent.getRootElement(); | |
HeaderElement h1 = taggedContent.createHeaderElement(1); | |
HeaderElement h2 = taggedContent.createHeaderElement(2); | |
HeaderElement h3 = taggedContent.createHeaderElement(3); | |
HeaderElement h4 = taggedContent.createHeaderElement(4); | |
HeaderElement h5 = taggedContent.createHeaderElement(5); | |
HeaderElement h6 = taggedContent.createHeaderElement(6); | |
rootElement.appendChild(h1); | |
rootElement.appendChild(h2); | |
rootElement.appendChild(h3); | |
rootElement.appendChild(h4); | |
rootElement.appendChild(h5); | |
rootElement.appendChild(h6); | |
SpanElement spanH11 = taggedContent.createSpanElement(); | |
spanH11.setText("H1. "); | |
h1.appendChild(spanH11); | |
SpanElement spanH12 = taggedContent.createSpanElement(); | |
spanH12.setText("Level 1 Header"); | |
h1.appendChild(spanH12); | |
SpanElement spanH21 = taggedContent.createSpanElement(); | |
spanH21.setText("H2. "); | |
h2.appendChild(spanH21); | |
SpanElement spanH22 = taggedContent.createSpanElement(); | |
spanH22.setText("Level 2 Header"); | |
h2.appendChild(spanH22); | |
SpanElement spanH31 = taggedContent.createSpanElement(); | |
spanH31.setText("H3. "); | |
h3.appendChild(spanH31); | |
SpanElement spanH32 = taggedContent.createSpanElement(); | |
spanH32.setText("Level 3 Header"); | |
h3.appendChild(spanH32); | |
SpanElement spanH41 = taggedContent.createSpanElement(); | |
spanH41.setText("H4. "); | |
h4.appendChild(spanH41); | |
SpanElement spanH42 = taggedContent.createSpanElement(); | |
spanH42.setText("Level 4 Header"); | |
h4.appendChild(spanH42); | |
SpanElement spanH51 = taggedContent.createSpanElement(); | |
spanH51.setText("H5. "); | |
h5.appendChild(spanH51); | |
SpanElement spanH52 = taggedContent.createSpanElement(); | |
spanH52.setText("Level 5 Header"); | |
h5.appendChild(spanH52); | |
SpanElement spanH61 = taggedContent.createSpanElement(); | |
spanH61.setText("H6. "); | |
h6.appendChild(spanH61); | |
SpanElement spanH62 = taggedContent.createSpanElement(); | |
spanH62.setText("Level 6 Header"); | |
h6.appendChild(spanH62); | |
ParagraphElement p = taggedContent.createParagraphElement(); | |
p.setText("P. "); | |
rootElement.appendChild(p); | |
SpanElement span1 = taggedContent.createSpanElement(); | |
span1.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "); | |
p.appendChild(span1); | |
SpanElement span2 = taggedContent.createSpanElement(); | |
span2.setText("Aenean nec lectus ac sem faucibus imperdiet. "); | |
p.appendChild(span2); | |
SpanElement span3 = taggedContent.createSpanElement(); | |
span3.setText("Sed ut erat ac magna ullamcorper hendrerit. "); | |
p.appendChild(span3); | |
SpanElement span4 = taggedContent.createSpanElement(); | |
span4.setText("Cras pellentesque libero semper, gravida magna sed, luctus leo. "); | |
p.appendChild(span4); | |
SpanElement span5 = taggedContent.createSpanElement(); | |
span5.setText("Fusce lectus odio, laoreet nec ullamcorper ut, molestie eu elit. "); | |
p.appendChild(span5); | |
SpanElement span6 = taggedContent.createSpanElement(); | |
span6.setText("Interdum et malesuada fames ac ante ipsum primis in faucibus. "); | |
p.appendChild(span6); | |
SpanElement span7 = taggedContent.createSpanElement(); | |
span7.setText("Aliquam lacinia sit amet elit ac consectetur. Donec cursus condimentum ligula, vitae volutpat sem tristique eget. "); | |
p.appendChild(span7); | |
SpanElement span8 = taggedContent.createSpanElement(); | |
span8.setText("Nulla in consectetur massa. Vestibulum vitae lobortis ante. Nulla ullamcorper pellentesque justo rhoncus accumsan. "); | |
p.appendChild(span8); | |
SpanElement span9 = taggedContent.createSpanElement(); | |
span9.setText("Mauris ornare eu odio non lacinia. Aliquam massa leo, rhoncus ac iaculis eget, tempus et magna. Sed non consectetur elit. "); | |
p.appendChild(span9); | |
SpanElement span10 = taggedContent.createSpanElement(); | |
span10.setText("Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus."); | |
p.appendChild(span10); | |
// Save Tagged Pdf Document | |
document.save(path + "InlineStructureElements.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
// Load source PDF file | |
String dataDir = Utils.getSharedDataDir(OptimizePDFFileSize.class) + "Document/"; | |
Document doc = new Document(dataDir + "Aspose_End-User-License-Agreement_2017-01-09.pdf"); | |
com.aspose.pdf.optimization.OptimizationOptions opt = new com.aspose.pdf.optimization.OptimizationOptions(); | |
opt.setRemoveUnusedObjects(false); | |
opt.setLinkDuplcateStreams(false); | |
opt.setRemoveUnusedStreams(false); | |
// Enable image compression | |
// Set the quality of images in PDF file | |
opt.getImageCompressionOptions().setCompressImages(true); | |
opt.getImageCompressionOptions().setImageQuality(10); | |
doc.optimizeResources(opt); | |
// Save the updated file | |
doc.save(dataDir + "compressingPDFWithImages_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = Utils.getSharedDataDir(OptimizePDFFileSize.class) + "Document/"; | |
// Open document | |
Document pdfDocument = new Document(dataDir + "Aspose_End-User-License-Agreement_2017-01-09.pdf"); | |
// Set RemoveUsedObject option | |
OptimizationOptions optimizeOptions = new OptimizationOptions(); | |
optimizeOptions.setRemoveUnusedObjects(true); | |
optimizeOptions.setSubsetFonts(true); | |
// Optimize PDF document using OptimizationOptions | |
pdfDocument.optimizeResources(optimizeOptions); | |
// Save updated document | |
pdfDocument.save(dataDir + "removeUnnecessaryObjects_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Properties StructTreeRootElement and RootElement are used for access to | |
// StructTreeRoot object of pdf document and to root structure element (Document structure element). | |
StructTreeRootElement structTreeRootElement = taggedContent.getStructTreeRootElement(); | |
StructureElement rootElement = taggedContent.getRootElement(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Create Structure Elements | |
StructureElement rootElement = taggedContent.getRootElement(); | |
SectElement sect = taggedContent.createSectElement(); | |
rootElement.appendChild(sect); | |
HeaderElement h1 = taggedContent.createHeaderElement(1); | |
sect.appendChild(h1); | |
h1.setText("The Header"); | |
h1.setTitle("Title"); | |
h1.setLanguage("en-US"); | |
h1.setAlternativeText("Alternative Text"); | |
h1.setExpansionText("Expansion Text"); | |
h1.setActualText("Actual Text"); | |
// Save Tagged Pdf Document | |
document.save(path + "StructureElementsProperties.pdf"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
ParagraphElement p = taggedContent.createParagraphElement(); | |
taggedContent.getRootElement().appendChild(p); | |
// Under Development | |
p.getStructureTextState().setFontSize(18F); | |
p.getStructureTextState().setForegroundColor(Color.getRed()); | |
p.getStructureTextState().setFontStyle(FontStyles.Italic); | |
p.setText("Red italic text."); | |
// Save Tagged Pdf Document | |
document.save(path + "StyleTextStructure.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// | |
// Work with Tagged Pdf content | |
// | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Simple Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Save Tagged Pdf Document | |
document.save(path + "TaggedPDFContent.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Get Root Structure Element | |
StructureElement rootElement = taggedContent.getRootElement(); | |
HeaderElement h1 = taggedContent.createHeaderElement(1); | |
HeaderElement h2 = taggedContent.createHeaderElement(2); | |
HeaderElement h3 = taggedContent.createHeaderElement(3); | |
HeaderElement h4 = taggedContent.createHeaderElement(4); | |
HeaderElement h5 = taggedContent.createHeaderElement(5); | |
HeaderElement h6 = taggedContent.createHeaderElement(6); | |
h1.setText("H1. Header of Level 1"); | |
h2.setText("H2. Header of Level 2"); | |
h3.setText("H3. Header of Level 3"); | |
h4.setText("H4. Header of Level 4"); | |
h5.setText("H5. Header of Level 5"); | |
h6.setText("H6. Header of Level 6"); | |
rootElement.appendChild(h1); | |
rootElement.appendChild(h2); | |
rootElement.appendChild(h3); | |
rootElement.appendChild(h4); | |
rootElement.appendChild(h5); | |
rootElement.appendChild(h6); | |
ParagraphElement p = taggedContent.createParagraphElement(); | |
p.setText("P. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nec lectus ac sem faucibus imperdiet. Sed ut erat ac magna ullamcorper hendrerit. Cras pellentesque libero semper, gravida magna sed, luctus leo. Fusce lectus odio, laoreet nec ullamcorper ut, molestie eu elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam lacinia sit amet elit ac consectetur. Donec cursus condimentum ligula, vitae volutpat sem tristique eget. Nulla in consectetur massa. Vestibulum vitae lobortis ante. Nulla ullamcorper pellentesque justo rhoncus accumsan. Mauris ornare eu odio non lacinia. Aliquam massa leo, rhoncus ac iaculis eget, tempus et magna. Sed non consectetur elit. Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus."); | |
rootElement.appendChild(p); | |
// Save Tagged Pdf Document | |
document.save(path + "TextBlockStructureElements.pdf"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = "pathTodir"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Get Root Structure Elements | |
StructureElement rootElement = taggedContent.getRootElement(); | |
ParagraphElement p = taggedContent.createParagraphElement(); | |
// Set Text to Text Structure Element | |
p.setText("Paragraph."); | |
rootElement.appendChild(p); | |
// Save Tagged Pdf Document | |
document.save(path + "TextStructureElement.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = com.aspose.pdf.examples.Utils.getSharedDataDir(AddImage.class) + "Images/"; | |
// Load image into stream | |
java.io.FileInputStream imageStream = new java.io.FileInputStream(new java.io.File(dataDir + "0002.dcm")); | |
Document pdfDocument = new Document(); | |
pdfDocument.getPages().add(); | |
com.aspose.pdf.Image image = new com.aspose.pdf.Image(); | |
image.setFileType(ImageFileType.Dicom); | |
image.setImageStream(imageStream); | |
pdfDocument.getPages().get_Item(1).getParagraphs().add(image); | |
// Save output as PDF format | |
pdfDocument.save(dataDir + "PdfWithDicomImage_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = Utils.getSharedDataDir(AddImageStampAsBackgroundInFloatingBox.class) + "Stamps-Watermarks/"; | |
// Instantiate Document object | |
Document doc = new Document(); | |
// Add page to PDF document | |
com.aspose.pdf.Page page = doc.getPages().add(); | |
// Create FloatingBox object | |
FloatingBox aBox = new FloatingBox(200, 100); | |
// Set left position for FloatingBox | |
aBox.setLeft(40); | |
// Set Top position for FloatingBox | |
aBox.setTop(80); | |
// Set the Horizontal alignment for FloatingBox | |
aBox.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center); | |
// Add text fragment to paragraphs collection of FloatingBox | |
aBox.getParagraphs().add(new TextFragment("main text")); | |
// Set border for FloatingBox | |
aBox.setBorder(new BorderInfo(BorderSide.All, com.aspose.pdf.Color.getRed())); | |
// Add background image | |
aBox.setBackgroundImage( new Image()); | |
aBox.getBackgroundImage().setFile(dataDir +"aspose-logo.jpg"); | |
// Set background color for FloatingBox | |
aBox.setBackgroundColor(com.aspose.pdf.Color.getYellow()); | |
// Add FloatingBox to paragraphs collection of page object | |
page.getParagraphs().add(aBox); | |
// Save the PDF document | |
doc.save(dataDir + "AddImageStampAsBackgroundInFloatingBox_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = Utils.getSharedDataDir(ExtractTextFromStampAnnotation.class) + "Stamps-Watermarks/"; | |
Document doc = new Document(dataDir+"test.pdf"); | |
Annotation item = doc.getPages().get_Item(1).getAnnotations().get_Item(3); | |
if (item instanceof StampAnnotation ) { | |
StampAnnotation annot = (StampAnnotation) item; | |
TextAbsorber ta = new TextAbsorber(); | |
XForm ap = annot.getNormalAppearance(); | |
ta.visit(ap); | |
System.out.println(ta.getText()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = Utils.getSharedDataDir(HideSpannedCellBorder.class) + "WorkingWithTables/"; | |
Document doc = new Document(); | |
com.aspose.pdf.Page page = doc.getPages().add(); | |
//Instantiate a table object that will be nested inside outerTable that will break | |
//inside the same page | |
com.aspose.pdf.Table mytable = new com.aspose.pdf.Table(); | |
mytable.setBroken(TableBroken.Vertical); | |
mytable.setDefaultCellBorder(new BorderInfo(BorderSide.All)); | |
mytable.setRepeatingColumnsCount(2); | |
page.getParagraphs().add(mytable); | |
//Add header Row | |
com.aspose.pdf.Row row = mytable.getRows().add(); | |
Cell cell = row.getCells().add("header 1"); | |
cell.setColSpan(2); | |
cell.setBackgroundColor(Color.getLightGray()); | |
Cell header3 = row.getCells().add("header 3"); | |
Cell cell2 = row.getCells().add("header 4"); | |
cell2.setColSpan(2); | |
cell2.setBackgroundColor(Color.getLightBlue()); | |
row.getCells().add("header 6"); | |
Cell cell3 = row.getCells().add("header 7"); | |
cell3.setColSpan(2); | |
cell3.setBackgroundColor(Color.getLightGreen()); | |
Cell cell4 = row.getCells().add("header 9"); | |
cell4.setColSpan(3); | |
cell4.setBackgroundColor(Color.getLightCoral()); | |
row.getCells().add("header 12"); | |
row.getCells().add("header 13"); | |
row.getCells().add("header 14"); | |
row.getCells().add("header 15"); | |
row.getCells().add("header 16"); | |
row.getCells().add("header 17"); | |
for (int rowCounter = 0; rowCounter < 1; rowCounter++) | |
{ | |
//Create rows in the table and then cells in the rows | |
com.aspose.pdf.Row row1 = mytable.getRows().add(); | |
row1.getCells().add("col "+rowCounter+", 1"); | |
row1.getCells().add("col "+rowCounter+", 2"); | |
row1.getCells().add("col "+rowCounter+", 3"); | |
row1.getCells().add("col "+rowCounter+", 4"); | |
row1.getCells().add("col "+rowCounter+", 5"); | |
row1.getCells().add("col "+rowCounter+", 6"); | |
row1.getCells().add("col "+rowCounter+", 7"); | |
row1.getCells().add("col "+rowCounter+", 8"); | |
row1.getCells().add("col "+rowCounter+", 9"); | |
row1.getCells().add("col "+rowCounter+", 10"); | |
row1.getCells().add("col "+rowCounter+", 11"); | |
row1.getCells().add("col "+rowCounter+", 12"); | |
row1.getCells().add("col "+rowCounter+", 13"); | |
row1.getCells().add("col "+rowCounter+", 14"); | |
row1.getCells().add("col "+rowCounter+", 15"); | |
row1.getCells().add("col "+rowCounter+", 16"); | |
row1.getCells().add("col "+rowCounter+", 17"); | |
} | |
doc.save(dataDir + "3_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "TaggedPDFs\\"; | |
String outFile = dataDir + "AddStructureElementIntoElement_Output.pdf"; | |
String logFile = dataDir + "46144_log.xml"; | |
// Creation document and getting Tagged Pdf Content | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Setting Title and Nature Language for document | |
taggedContent.setTitle("Text Elements Example"); | |
taggedContent.setLanguage("en-US"); | |
// Getting Root structure element (Document structure element) | |
StructureElement rootElement = taggedContent.getRootElement(); | |
ParagraphElement p1 = taggedContent.createParagraphElement(); | |
rootElement.appendChild(p1); | |
SpanElement span11 = taggedContent.createSpanElement(); | |
span11.setText("Span_11"); | |
SpanElement span12 = taggedContent.createSpanElement(); | |
span12.setText(" and Span_12."); | |
p1.setText("Paragraph with "); | |
p1.appendChild(span11); | |
p1.appendChild(span12); | |
ParagraphElement p2 = taggedContent.createParagraphElement(); | |
rootElement.appendChild(p2); | |
SpanElement span21 = taggedContent.createSpanElement(); | |
span21.setText("Span_21"); | |
SpanElement span22 = taggedContent.createSpanElement(); | |
span22.setText("Span_22."); | |
p2.appendChild(span21); | |
p2.setText(" and "); | |
p2.appendChild(span22); | |
ParagraphElement p3 = taggedContent.createParagraphElement(); | |
rootElement.appendChild(p3); | |
SpanElement span31 = taggedContent.createSpanElement(); | |
span31.setText("Span_31"); | |
SpanElement span32 = taggedContent.createSpanElement(); | |
span32.setText(" and Span_32"); | |
p3.appendChild(span31); | |
p3.appendChild(span32); | |
p3.setText("."); | |
ParagraphElement p4 = taggedContent.createParagraphElement(); | |
rootElement.appendChild(p4); | |
SpanElement span41 = taggedContent.createSpanElement(); | |
SpanElement span411 = taggedContent.createSpanElement(); | |
span411.setText("Span_411, "); | |
span41.setText("Span_41, "); | |
span41.appendChild(span411); | |
SpanElement span42 = taggedContent.createSpanElement(); | |
SpanElement span421 = taggedContent.createSpanElement(); | |
span421.setText("Span 421 and "); | |
span42.appendChild(span421); | |
span42.setText("Span_42"); | |
p4.appendChild(span41); | |
p4.appendChild(span42); | |
p4.setText("."); | |
// Save Tagged Pdf Document | |
document.save(outFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "TaggedPDFs\\"; | |
String outFile = dataDir + "CreateNoteStructureElement.pdf"; | |
String logFile = dataDir + "45929_log.xml"; | |
// Create Pdf Document | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
taggedContent.setTitle("Sample of Note Elements"); | |
taggedContent.setLanguage("en-US"); | |
// Add Paragraph Element | |
ParagraphElement paragraph = taggedContent.createParagraphElement(); | |
taggedContent.getRootElement().appendChild(paragraph); | |
// Add NoteElement | |
NoteElement note1 = taggedContent.createNoteElement(); | |
paragraph.appendChild(note1); | |
note1.setText("Note with auto generate ID. "); | |
// Add NoteElement | |
NoteElement note2 = taggedContent.createNoteElement(); | |
paragraph.appendChild(note2); | |
note2.setText("Note with ID = 'note_002'. "); | |
note2.setId("note_002"); | |
// Add NoteElement | |
NoteElement note3 = taggedContent.createNoteElement(); | |
paragraph.appendChild(note3); | |
note3.setText("Note with ID = 'note_003'. "); | |
note3.setId("note_003"); | |
// Save Tagged Pdf Document | |
document.save(outFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "TaggedPDFs\\"; | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
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(dataDir + "aspose-logo.jpg"); | |
// Save PDF Document | |
document.save(dataDir + "PDFwithTaggedImage.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "TaggedPDFs\\"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// 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"); | |
// Save PDF Document | |
document.save( dataDir + "PDFwithTaggedText.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Document | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Create Grouping Elements | |
PartElement partElement = taggedContent.createPartElement(); | |
ArtElement artElement = taggedContent.createArtElement(); | |
SectElement sectElement = taggedContent.createSectElement(); | |
DivElement divElement = taggedContent.createDivElement(); | |
BlockQuoteElement blockQuoteElement = taggedContent.createBlockQuoteElement(); | |
CaptionElement captionElement = taggedContent.createCaptionElement(); | |
TOCElement tocElement = taggedContent.createTOCElement(); | |
TOCIElement tociElement = taggedContent.createTOCIElement(); | |
IndexElement indexElement = taggedContent.createIndexElement(); | |
NonStructElement nonStructElement = taggedContent.createNonStructElement(); | |
PrivateElement privateElement = taggedContent.createPrivateElement(); | |
// Create Text Block-Level Structure Elements | |
ParagraphElement paragraphElement = taggedContent.createParagraphElement(); | |
HeaderElement headerElement = taggedContent.createHeaderElement(); | |
HeaderElement h1Element = taggedContent.createHeaderElement(1); | |
// Create Text Inline-Level Structure Elements | |
SpanElement spanElement = taggedContent.createSpanElement(); | |
QuoteElement quoteElement = taggedContent.createQuoteElement(); | |
NoteElement noteElement = taggedContent.createNoteElement(); | |
// Create Illustration Structure Elements | |
FigureElement figureElement = taggedContent.createFigureElement(); | |
FormulaElement formulaElement3 = taggedContent.createFormulaElement(); | |
// Methods are under development | |
ListElement listElement = taggedContent.createListElement(); | |
TableElement tableElement = taggedContent.createTableElement(); | |
ReferenceElement referenceElement = taggedContent.createReferenceElement(); | |
BibEntryElement bibEntryElement = taggedContent.createBibEntryElement(); | |
CodeElement codeElement = taggedContent.createCodeElement(); | |
LinkElement linkElement = taggedContent.createLinkElement(); | |
AnnotElement annotElement = taggedContent.createAnnotElement(); | |
RubyElement rubyElement = taggedContent.createRubyElement(); | |
WarichuElement warichuElement = taggedContent.createWarichuElement(); | |
FormElement formElement = taggedContent.createFormElement(); | |
// Save Tagged Pdf Document | |
document.save(path + "StructureElements_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet | |
taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Get root structure element (Document) | |
StructureElement rootElement = taggedContent.getRootElement(); | |
// Create Logical Structure | |
SectElement sect1 = taggedContent.createSectElement(); | |
rootElement.appendChild(sect1); | |
SectElement sect2 = taggedContent.createSectElement(); | |
rootElement.appendChild(sect2); | |
DivElement div11 = taggedContent.createDivElement(); | |
sect1.appendChild(div11); | |
DivElement div12 = taggedContent.createDivElement(); | |
sect1.appendChild(div12); | |
ArtElement art21 = taggedContent.createArtElement(); | |
sect2.appendChild(art21); | |
ArtElement art22 = taggedContent.createArtElement(); | |
sect2.appendChild(art22); | |
DivElement div211 = taggedContent.createDivElement(); | |
art21.appendChild(div211); | |
DivElement div212 = taggedContent.createDivElement(); | |
art21.appendChild(div212); | |
DivElement div221 = taggedContent.createDivElement(); | |
art22.appendChild(div221); | |
DivElement div222 = taggedContent.createDivElement(); | |
art22.appendChild(div222); | |
SectElement sect3 = taggedContent.createSectElement(); | |
rootElement.appendChild(sect3); | |
DivElement div31 = taggedContent.createDivElement(); | |
sect3.appendChild(div31); | |
// Save Tagged Pdf Document | |
document.save(path + "StructureElementsTree_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create document | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
taggedContent.setTitle("Example table"); | |
taggedContent.setLanguage("en-US"); | |
// Get root structure element | |
StructureElement rootElement = taggedContent.getRootElement(); | |
TableElement tableElement = taggedContent.createTableElement(); | |
rootElement.appendChild(tableElement); | |
tableElement.setBorder(new BorderInfo(BorderSide.All, 1.2F, Color.getDarkBlue())); | |
TableTHeadElement tableTHeadElement = tableElement.createTHead(); | |
TableTBodyElement tableTBodyElement = tableElement.createTBody(); | |
TableTFootElement tableTFootElement = tableElement.createTFoot(); | |
int rowCount = 50; | |
int colCount = 4; | |
int rowIndex; | |
int colIndex; | |
TableTRElement headTrElement = tableTHeadElement.createTR(); | |
headTrElement.setAlternativeText("Head Row"); | |
headTrElement.setBackgroundColor(Color.getLightGray()); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTHElement thElement = headTrElement.createTH(); | |
thElement.setText(String.format("Head %s", colIndex)); | |
thElement.setBackgroundColor(Color.getGreenYellow()); | |
thElement.setBorder(new BorderInfo(BorderSide.All, 4.0F, Color.getLightGray())); | |
thElement.setMargin(new MarginInfo(16.0, 2.0, 8.0, 2.0)); | |
thElement.setAlignment(HorizontalAlignment.Right); | |
} | |
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) | |
{ | |
TableTRElement trElement = tableTBodyElement.createTR(); | |
trElement.setAlternativeText(String.format("Row %s", rowIndex)); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
int colSpan = 1; | |
int rowSpan = 1; | |
if (colIndex == 1 && rowIndex == 1) | |
{ | |
colSpan = 2; | |
rowSpan = 2; | |
} | |
else if (colIndex == 2 && (rowIndex == 1 || rowIndex == 2)) | |
{ | |
continue; | |
} | |
else if (rowIndex == 2 && (colIndex == 1 || colIndex == 2)) | |
{ | |
continue; | |
} | |
TableTDElement tdElement = trElement.createTD(); | |
tdElement.setText(String.format("Cell [%s, %s]", rowIndex, colIndex)); | |
tdElement.setBackgroundColor(Color.getYellow()); | |
tdElement.setBorder(new BorderInfo(BorderSide.All, 4.0F, Color.getGray())); | |
tdElement.setMargin(new MarginInfo(8.0, 2.0, 8.0, 2.0)); | |
tdElement.setAlignment(HorizontalAlignment.Center); | |
TextState cellTextState = new TextState(); | |
cellTextState.setForegroundColor(Color.getDarkBlue()); | |
cellTextState.setFontSize(7.5F); | |
cellTextState.setFontStyle(FontStyles.Bold); | |
cellTextState.setFont(FontRepository.findFont("Arial")); | |
tdElement.setDefaultCellTextState(cellTextState); | |
tdElement.isWordWrapped(); | |
tdElement.setVerticalAlignment(VerticalAlignment.Center); | |
tdElement.setColSpan(colSpan); | |
tdElement.setRowSpan(rowSpan); | |
} | |
} | |
TableTRElement footTrElement = tableTFootElement.createTR(); | |
footTrElement.setAlternativeText("Foot Row"); | |
footTrElement.setBackgroundColor(Color.getLightSeaGreen()); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTDElement tdElement = footTrElement.createTD(); | |
tdElement.setText(String.format("Foot %s", colIndex)); | |
tdElement.setAlignment(HorizontalAlignment.Center); | |
tdElement.getStructureTextState().setFontSize(7F); | |
tdElement.getStructureTextState().setFontStyle(FontStyles.Bold); | |
} | |
StructureAttributes tableAttributes = tableElement.getAttributes().getAttributes(AttributeOwnerStandard.Table); | |
StructureAttribute summaryAttribute = new StructureAttribute(AttributeKey.Summary); | |
summaryAttribute.setStringValue("The summary text for table"); | |
tableAttributes.setAttribute(summaryAttribute); | |
// Save Tagged Pdf Document | |
document.save(path + "CreateTableElement.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Documnet taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
// Under Development | |
IllustrationElement figure1 = taggedContent.createFigureElement(); | |
taggedContent.getRootElement().appendChild(figure1); | |
figure1.setAlternativeText("Figure One"); | |
figure1.setTitle("Image 1"); | |
figure1.setTag("Fig1"); | |
figure1.setImage("image.png"); | |
// Save Tagged Pdf Document | |
document.save(path + "IllustrationStructureElements_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create document | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
taggedContent.setTitle("Example table cell style"); | |
taggedContent.setLanguage("en-US"); | |
// Get root structure element | |
StructureElement rootElement = taggedContent.getRootElement(); | |
// Create table structure element | |
TableElement tableElement = taggedContent.createTableElement(); | |
rootElement.appendChild(tableElement); | |
TableTHeadElement tableTHeadElement = tableElement.createTHead(); | |
TableTBodyElement tableTBodyElement = tableElement.createTBody(); | |
TableTFootElement tableTFootElement = tableElement.createTFoot(); | |
int rowCount = 4; | |
int colCount = 4; | |
int rowIndex; | |
int colIndex; | |
TableTRElement headTrElement = tableTHeadElement.createTR(); | |
headTrElement.setAlternativeText("Head Row"); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTHElement thElement = headTrElement.createTH(); | |
thElement.setText(String.format("Head %s", colIndex)); | |
thElement.setBackgroundColor(Color.getGreenYellow()); | |
thElement.setBorder(new BorderInfo(BorderSide.All, 4.0F, Color.getGray())); | |
thElement.setNoBorder(false); | |
thElement.setMargin(new MarginInfo(16.0, 2.0, 8.0, 2.0)); | |
thElement.setAlignment(HorizontalAlignment.Right); | |
} | |
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) | |
{ | |
TableTRElement trElement = tableTBodyElement.createTR(); | |
trElement.setAlternativeText(String.format("Row %s", rowIndex)); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
int colSpan = 1; | |
int rowSpan = 1; | |
if (colIndex == 1 && rowIndex == 1) | |
{ | |
colSpan = 2; | |
rowSpan = 2; | |
} | |
else if (colIndex == 2 && (rowIndex == 1 || rowIndex == 2)) | |
{ | |
continue; | |
} | |
else if (rowIndex == 2 && (colIndex == 1 || colIndex == 2)) | |
{ | |
continue; | |
} | |
TableTDElement tdElement = trElement.createTD(); | |
tdElement.setText(String.format("Cell [%s, %s]", rowIndex, colIndex)); | |
tdElement.setBackgroundColor(Color.getYellow()); | |
tdElement.setBorder(new BorderInfo(BorderSide.All, 4.0F, Color.getGray())); | |
tdElement.setNoBorder(false); | |
tdElement.setMargin(new MarginInfo(8.0, 2.0, 8.0, 2.0)); | |
tdElement.setAlignment(HorizontalAlignment.Center); | |
TextState cellTextState = new TextState(); | |
cellTextState.setForegroundColor(Color.getDarkBlue()); | |
cellTextState.setFontSize(7.5F); | |
cellTextState.setFontStyle(FontStyles.Bold); | |
cellTextState.setFont(FontRepository.findFont("Arial")); | |
tdElement.setDefaultCellTextState(cellTextState); | |
tdElement.setWordWrapped(false); | |
tdElement.setVerticalAlignment(VerticalAlignment.Center); | |
tdElement.setColSpan(colSpan); | |
tdElement.setRowSpan(rowSpan); | |
} | |
} | |
TableTRElement footTrElement = tableTFootElement.createTR(); | |
footTrElement.setAlternativeText("Foot Row"); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTDElement tdElement = footTrElement.createTD(); | |
tdElement.setText(String.format("Foot %s", colIndex)); | |
} | |
// Save Tagged Pdf Document | |
document.save(path + "StyleTableCell.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create document | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
taggedContent.setTitle("Example table style"); | |
taggedContent.setLanguage("en-US"); | |
// Get root structure element | |
StructureElement rootElement = taggedContent.getRootElement(); | |
// Create table structure element | |
TableElement tableElement = taggedContent.createTableElement(); | |
rootElement.appendChild(tableElement); | |
tableElement.setBackgroundColor(Color.getBeige()); | |
tableElement.setBorder(new BorderInfo(BorderSide.All, 0.80F, Color.getGray())); | |
tableElement.setAlignment(HorizontalAlignment.Center); | |
tableElement.setBroken(TableBroken.Vertical); | |
tableElement.setColumnAdjustment(ColumnAdjustment.AutoFitToWindow); | |
tableElement.setColumnWidths("80 80 80 80 80"); | |
tableElement.setDefaultCellBorder(new BorderInfo(BorderSide.All, 0.50F, Color.getDarkBlue())); | |
tableElement.setDefaultCellPadding(new MarginInfo(16.0, 2.0, 8.0, 2.0)); | |
tableElement.getDefaultCellTextState().setForegroundColor(Color.getDarkCyan()); | |
tableElement.getDefaultCellTextState().setFontSize(8F); | |
tableElement.setDefaultColumnWidth("70"); | |
tableElement.setBroken(false); | |
tableElement.setBordersIncluded(true); | |
tableElement.setLeft(0F); | |
tableElement.setTop(40F); | |
tableElement.setRepeatingColumnsCount(2); | |
tableElement.setRepeatingRowsCount(3); | |
TextState rowStyle = new TextState(); | |
rowStyle.setBackgroundColor(Color.getLightCoral()); | |
tableElement.setRepeatingRowsStyle(rowStyle); | |
TableTHeadElement tableTHeadElement = tableElement.createTHead(); | |
TableTBodyElement tableTBodyElement = tableElement.createTBody(); | |
TableTFootElement tableTFootElement = tableElement.createTFoot(); | |
int rowCount = 10; | |
int colCount = 5; | |
int rowIndex; | |
int colIndex; | |
TableTRElement headTrElement = tableTHeadElement.createTR(); | |
headTrElement.setAlternativeText("Head Row"); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTHElement thElement = headTrElement.createTH(); | |
thElement.setText(String.format("Head %s", colIndex)); | |
} | |
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) | |
{ | |
TableTRElement trElement = tableTBodyElement.createTR(); | |
trElement.setAlternativeText(String.format("Row %s", rowIndex)); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTDElement tdElement = trElement.createTD(); | |
tdElement.setText(String.format("Cell [%s, %s]", rowIndex, colIndex)); | |
} | |
} | |
TableTRElement footTrElement = tableTFootElement.createTR(); | |
footTrElement.setAlternativeText("Foot Row"); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTDElement tdElement = footTrElement.createTD(); | |
tdElement.setText(String.format("Foot %s", colIndex)); | |
} | |
// Save Tagged Pdf Document | |
document.save(path + "StyleTableElement.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create document | |
Document document = new Document(); | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
taggedContent.setTitle("Example table row style"); | |
taggedContent.setLanguage("en-US"); | |
// Get root structure element | |
StructureElement rootElement = taggedContent.getRootElement(); | |
// Create table structure element | |
TableElement tableElement = taggedContent.createTableElement(); | |
rootElement.appendChild(tableElement); | |
TableTHeadElement tableTHeadElement = tableElement.createTHead(); | |
TableTBodyElement tableTBodyElement = tableElement.createTBody(); | |
TableTFootElement tableTFootElement = tableElement.createTFoot(); | |
int rowCount = 7; | |
int colCount = 3; | |
int rowIndex; | |
int colIndex; | |
TableTRElement headTrElement = tableTHeadElement.createTR(); | |
headTrElement.setAlternativeText("Head Row"); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTHElement thElement = headTrElement.createTH(); | |
thElement.setText(String.format("Head %s", colIndex)); | |
} | |
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) | |
{ | |
TableTRElement trElement = tableTBodyElement.createTR(); | |
trElement.setAlternativeText(String.format("Row %s", rowIndex)); | |
trElement.setBackgroundColor(Color.getLightSeaGreen()); | |
trElement.setBorder(new BorderInfo(BorderSide.All, 0.75F, Color.getDarkGray())); | |
trElement.setDefaultCellBorder(new BorderInfo(BorderSide.All, 0.50F, Color.getBlue())); | |
trElement.setMinRowHeight(100.0); | |
trElement.setFixedRowHeight(120.0); | |
trElement.setRowBroken(true); | |
TextState cellTextState = new TextState(); | |
cellTextState.setForegroundColor(Color.getRed()); | |
trElement.setDefaultCellTextState(cellTextState); | |
trElement.setDefaultCellPadding(new MarginInfo(16.0, 2.0, 8.0, 2.0)); | |
trElement.setVerticalAlignment(VerticalAlignment.Bottom); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTDElement tdElement = trElement.createTD(); | |
tdElement.setText(String.format("Cell [{0}, {1}]", rowIndex, colIndex)); | |
} | |
} | |
TableTRElement footTrElement = tableTFootElement.createTR(); | |
footTrElement.setAlternativeText("Foot Row"); | |
for (colIndex = 0; colIndex < colCount; colIndex++) | |
{ | |
TableTDElement tdElement = footTrElement.createTD(); | |
tdElement.setText(String.format("Foot %s", colIndex)); | |
} | |
// Save Tagged Pdf Document | |
document.save(path + "StyleTableRow.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 path = Utils.getDataDir() + "TaggedPDFs\\"; | |
// Create Pdf Document | |
Document document = new Document(); | |
// Get Content for work with TaggedPdf | |
ITaggedContent taggedContent = document.getTaggedContent(); | |
// Set Title and Language for Document taggedContent.setTitle("Tagged Pdf Document"); | |
taggedContent.setLanguage("en-US"); | |
ParagraphElement p = taggedContent.createParagraphElement(); | |
taggedContent.getRootElement().appendChild(p); | |
// Under Development | |
p.getStructureTextState().setFontSize(18F); | |
p.getStructureTextState().setForegroundColor(Color.getRed()); | |
p.getStructureTextState().setFontStyle(FontStyles.Italic); | |
p.setText("Red italic text."); | |
// Save Tagged Pdf Document | |
document.save(path + "StyleTextStructure_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() + "TaggedPDFs\\"; | |
String inputFileName = dataDir + "StructureElements.pdf"; | |
String outputLogName = dataDir + "ua-1-log.xml"; | |
Document document = new Document(inputFileName); | |
boolean isValid = document.validate(outputLogName, PdfFormat.PDF_UA_1); | |
document.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
MemoryCleaner.clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
HtmlFragment html = new HtmlFragment("some text"); | |
html.setTextState(new TextState()); | |
html.setTextState(new TextState("Calibri")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
String dataDir = Utils.getSharedDataDir(UseLatexScript3.class) + "Text/"; | |
String s = | |
"\\usepackage{amsmath,amsthm}" + | |
"\\begin{document}" + | |
"\\begin{proof} The proof is a follows: " + | |
"\\begin{align}" + | |
"(x+y)^3&=(x+y)(x+y)^2" + | |
"(x+y)(x^2+2xy+y^2)\\\\" + | |
"&=x^3+3x^2y+3xy^3+x^3.\\qedhere" + | |
"\\end{align}" + | |
"\\end{proof}" + | |
"\\end{document}"; | |
Document doc = new Document(); | |
Page page = doc.getPages().add(); | |
LatexFragment latex = new LatexFragment(s); | |
page.getParagraphs().add(latex); | |
doc.save(dataDir + "Script_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-Java | |
// 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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"; | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment