Java add multiple image watermarks to Word document
We have demonstrated how to use Spire.Doc for Java to add multiple text watermarks to word document. This article will show you how to add multiple image watermarks to the Word document with the help of Spire.Doc for Java.
import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.spire.doc.HeaderFooter; import com.spire.doc.Section; import com.spire.doc.documents.Paragraph; import com.spire.doc.documents.TextWrappingStyle; import com.spire.doc.fields.DocPicture; public class WordImageWatermark { public static void main(String[] args) throws Exception { //Load the sample file Document doc=new Document(); doc.loadFromFile("Sample.docx"); //Load the image DocPicture picture = new DocPicture(doc); picture.loadImage("Logo.png"); //Set the text wrapping style picture.setTextWrappingStyle(TextWrappingStyle.Behind); for (int n = 0; n < doc.getSections().getCount(); n++) { Section section = doc.getSections().get(n); //Get the head of section HeaderFooter header = section.getHeadersFooters().getHeader(); Paragraph paragrapg1; if(header.getParagraphs().getCount()>0){ paragrapg1=header.getParagraphs().get(0); }else { //Add the header to the paragraph paragrapg1 = header.addParagraph(); } for (int p = 0; p < 3; p++) { for (int q = 0; q < 2; q++) { //copy the image and add it to many places picture = (DocPicture)picture.deepClone(); picture.setVerticalPosition(100 + 200 * p); picture.setHorizontalPosition(50 + 210 * q); paragrapg1.getChildObjects().add(picture); } } } //Save the document to file doc.saveToFile("Result.docx", FileFormat.Docx_2013); } }
Output:
Get Coordinates of Images in PDF in Java
This article shows you how to get x and y coordinates of images in a PDF page by using Spire.PDF for Java.
import com.spire.pdf.exporting.PdfImageInfo; import java.awt.geom.Rectangle2D; public class GetCoordinateOfImage { public static void main(String[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a PDF file doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Images.pdf"); //Get the first worksheet PdfPageBase page = doc.getPages().get(0); //Get the image information of the page PdfImageInfo[] imageInfo = page.getImagesInfo(); //Loop through the image information for (int i = 0; i < imageInfo.length; i++) { //Get the bounds property of a specific image Rectangle2D rect = imageInfo[i].getBounds(); //Get the x and y coordinates System.out.println(String.format("The coordinate of image %d:(%f, %f)", i+1, rect.getX(), rect.getY())); } } }
Java: Remove Annotations from PDF Documents
PDF annotations are notes or markers added to documents, which are great for making comments, giving explanations, giving feedback, etc. Co-creators of documents often communicate with annotations. However, when the issues associated with the annotations have been dealt with or the document has been finalized, it is necessary to remove the annotations to make the document more concise and professional. This article shows how to delete PDF annotations programmatically using Spire.PDF for Java.
- Remove the Specified Annotation
- Remove All Annotations from a Page
- Remove All Annotations from a PDF Document
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.pdf</artifactId> <version>10.3.4</version> </dependency> </dependencies>
Remove the Specified Annotation
Annotations are page-level document elements. Therefore, deleting an annotation requires getting the page where the annotation is located first, and then you can use the PdfPageBase.getAnnotationsWidget().removeAt() method to delete the annotation. The detailed steps are as follows.
- Create a PdfDocument instance.
- Load a PDF document using PdfDocument.loadFromFile() method.
- Get the first page using PdfDocument.getPages().get() method.
- Remove the first annotation from this page using PdfPageBase.getAnnotationsWidget().removeAt() method.
- Save the document using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; public class RemoveAnnotation { public static void main(String[] args) { //Create an object of PdfDocument PdfDocument pdf = new PdfDocument(); //Load a PDF document pdf.loadFromFile("C:/Annotations.pdf"); //Get the first page PdfPageBase page = pdf.getPages().get(0); //Remove the first annotation page.getAnnotationsWidget().removeAt(0); //Save the document pdf.saveToFile("RemoveOneAnnotation.pdf"); } }
Remove All Annotations from a Page
Spire.PDF for Java also provides PdfPageBase.getAnnotationsWidget().clear() method to remove all annotations in the specified page. The detailed steps are as follows.
- Create a PdfDocument instance.
- Load a PDF document using PdfDocument.loadFromFile() method.
- Get the first page using PdfDocument.getPages().get() method.
- Remove all annotations from the page using PdfPageBase.getAnnotationsWidget().clear() method.
- Save the document using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; public class RemoveAllAnnotationPage { public static void main(String[] args) { //Create an object of PdfDocument PdfDocument pdf = new PdfDocument(); //Load a PDF document pdf.loadFromFile("C:/Annotations.pdf"); //Get the first page PdfPageBase page = pdf.getPages().get(0); //Remove all annotations in the page page.getAnnotationsWidget().clear(); //Save the document pdf.saveToFile("RemoveAnnotationsPage.pdf"); } }
Remove All Annotations from a PDF Document
To remove all annotations from a PDF document, we need to loop through all pages in the document and delete all annotations from each page. The detailed steps are as follows.
- Create a PdfDocument instance.
- Load a PDF document using PdfDocument.loadFromFile() method.
- Loop through all pages to delete annotations.
- Delete annotations in each page using PdfPageBase.getAnnotationsWidget().clear() method.
- Save the document using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; public class RemoveAllAnnotations { public static void main(String[] args) { //Create an object of PdfDocument PdfDocument pdf = new PdfDocument(); //Load a PDF document pdf.loadFromFile("C:/Users/Sirion/Desktop/Annotations.pdf"); //Loop through the pages in the document for (PdfPageBase page : (Iterable) pdf.getPages()) { //Remove annotations in each page page.getAnnotationsWidget().clear(); } //Save the document pdf.saveToFile("RemoveAllAnnotations.pdf"); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Insert table to Text Box in Word in Java
We have demonstrated how to insert text and image to textbox in a Word document by using Spire.Doc for Java. This article will demonstrate how to insert table to textbox in Word.
import com.spire.doc.*; import com.spire.doc.documents.*; import com.spire.doc.fields.*; import java.awt.*; public class insertTableIntoTextBox { public static void main(String[] args) throws Exception{ //Create a new document; add a section and paragraph Document doc = new Document(); Section section = doc.addSection(); Paragraph paragraph = section.addParagraph(); //Add a textbox to the paragraph TextBox textbox = paragraph.appendTextBox(380, 100); //Set the position of the textbox textbox.getFormat().setHorizontalOrigin(HorizontalOrigin.Page); textbox.getFormat().setHorizontalPosition(140); textbox.getFormat().setVerticalOrigin(VerticalOrigin.Page); textbox.getFormat().setVerticalPosition(50); //Insert table to the textbox Table table = textbox.getBody().addTable(true); //Specify the number of rows and columns of the table table.resetCells(4, 4); //Define the data String[][] data = new String[][] { {"Name", "Age", "Gender", "ID"}, {"John", "28", "Male", "0023"}, {"Steve", "30", "Male", "0024"}, {"Lucy", "26", "female", "0025"} }; //Add data to the table for (int i = 0; i < 4; i++) { TableRow dataRow = table.getRows().get(i); dataRow.getCells().get(i).setWidth(70); dataRow.setHeight(22); dataRow.setHeightType(TableRowHeightType.Exactly); for (int j = 0; j < 4; j++) { TextRange tableRange = table.getRows().get(i).getCells().get(j).addParagraph().appendText(data[i][j]); tableRange.getCharacterFormat().setFontName("Arial"); tableRange.getCharacterFormat().setFontSize(11f); tableRange.getOwnerParagraph().getFormat().setHorizontalAlignment(HorizontalAlignment.Center); tableRange.getCharacterFormat().setBold(true); } } //Set the background color for the first row TableRow row = table.getRows().get(0); for (int z = 0; z < row.getCells().getCount(); z++) { row.getCells().get(z).getCellFormat().setBackColor(new Color(176,224,238)); } //Apply style to the table table.applyStyle(DefaultTableStyle.Table_Grid_5); //Save the document String output = "output/insertTableIntoTextBox.docx"; doc.saveToFile(output, FileFormat.Docx_2013); } }
The effective screenshot after insert table to Textbox in Word:
Add Line Numbers to a PDF in C#/VB.NET
This article demonstrates how to add line numbers before chunks of text in a PDF page by using Spire.PDF for .NET.
Below is a screenshot of the input document.
using Spire.Pdf; using Spire.Pdf.General.Find; using Spire.Pdf.Graphics; using System.Drawing; namespace AddLineNumber { class Program { static void Main(string[] args) { //Create a PdfDocument of instance PdfDocument doc = new PdfDocument(); //Load a PDF document doc.LoadFromFile(@"G:\360MoveData\Users\Administrator\Desktop\sample.pdf"); //Get the first page PdfPageBase page = doc.Pages[0]; //Find the spcific text in the fisrt line PdfTextFind topLine = page.FindText("C# (pronounced See Sharp)", TextFindParameter.None).Finds[0]; //Get the line height float lineHeight = topLine.Bounds.Height; //Get the Y coordinate of the selected text float y = topLine.Bounds.Y; //Find the spcific text in the second line PdfTextFind secondLine = page.FindText("language. C#", TextFindParameter.None).Finds[0]; //Calculate the line spacing float lineSpacing = secondLine.Bounds.Top - topLine.Bounds.Bottom; //Find the specific text in the last line PdfTextFind bottomLine = page.FindText("allocation of objects", TextFindParameter.None).Finds[0]; //Get the height of the chunks float height = bottomLine.Bounds.Bottom; //Create a font PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 11f); int i = 1; while (y < height) { //Draw line number before a specific line of text page.Canvas.DrawString(i.ToString(), font, PdfBrushes.Black, new PointF(15, y)); y += lineHeight + lineSpacing; i++; } //Save the document doc.SaveToFile("result.pdf"); } } }
Imports Spire.Pdf Imports Spire.Pdf.General.Find Imports Spire.Pdf.Graphics Imports System.Drawing Namespace AddLineNumber Class Program Shared Sub Main(ByVal args() As String) 'Create a PdfDocument of instance Dim doc As PdfDocument = New PdfDocument() 'Load a PDF document doc.LoadFromFile("G:\360MoveData\Users\Administrator\Desktop\sample.pdf") 'Get the first page Dim page As PdfPageBase = doc.Pages(0) 'Find the spcific text in the fisrt line Dim topLine As PdfTextFind = page.FindText("C# (pronounced See Sharp)",TextFindParameter.None).Finds(0) 'Get the line height Dim lineHeight As single = topLine.Bounds.Height 'Get the Y coordinate of the selected text Dim y As single = topLine.Bounds.Y 'Find the spcific text in the second line Dim secondLine As PdfTextFind = page.FindText("language. C#",TextFindParameter.None).Finds(0) 'Calculate the line spacing Dim lineSpacing As single = secondLine.Bounds.Top - topLine.Bounds.Bottom 'Find the specific text in the last line Dim bottomLine As PdfTextFind = page.FindText("allocation of objects",TextFindParameter.None).Finds(0) 'Get the height of the chunks Dim height As single = bottomLine.Bounds.Bottom 'Create a font Dim font As PdfFont = New PdfFont(PdfFontFamily.TimesRoman,11f) Dim i As Integer = 1 While y < height 'Draw line number before a specific line of text page.Canvas.DrawString(i.ToString(),font,PdfBrushes.Black,New PointF(15,y)) y += lineHeight + lineSpacing i = i + 1 End While 'Save the document doc.SaveToFile("result.pdf") End Sub End Class End Namespace
Output
Get the differences by comparing two Word documents in C#/VB.NET
We have introduced how to compare two Word documents in C# and VB.NET. From Spire.Doc V8.12.14, it supports to get the differences between two Word documents in a structure list. This article will show you how to use Spire.Doc to get the differences by comparing two Word documents.
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using Spire.Doc.Formatting.Revisions; using System; namespace GetWordDifferences { class Program { static void Main(string[] args) { //Load the first Word document Document doc1 = new Document(); doc1.LoadFromFile("Sample1.docx"); //Load the second Word document Document doc2 = new Document(); doc2.LoadFromFile("Sample2.docx"); //Compare the two Word documents doc1.Compare(doc2, "Author"); foreach (Section sec in doc1.Sections) { foreach (DocumentObject docItem in sec.Body.ChildObjects) { if (docItem is Paragraph) { Paragraph para = docItem as Paragraph; if (para.IsInsertRevision) { EditRevision insRevison = para.InsertRevision; EditRevisionType insType = insRevison.Type; string insAuthor = insRevison.Author; DateTime insDateTime = insRevison.DateTime; } else if (para.IsDeleteRevision) { EditRevision delRevison = para.DeleteRevision; EditRevisionType delType = delRevison.Type; string delAuthor = delRevison.Author; DateTime delDateTime = delRevison.DateTime; } foreach (ParagraphBase paraItem in para.ChildObjects) { if (paraItem.IsInsertRevision) { EditRevision insRevison = paraItem.InsertRevision; EditRevisionType insType = insRevison.Type; string insAuthor = insRevison.Author; DateTime insDateTime = insRevison.DateTime; } else if (paraItem.IsDeleteRevision) { EditRevision delRevison = paraItem.DeleteRevision; EditRevisionType delType = delRevison.Type; string delAuthor = delRevison.Author; DateTime delDateTime = delRevison.DateTime; } } } } } //Get the difference about revisions DifferRevisions differRevisions = new DifferRevisions(doc1); var insetRevisionsList = differRevisions.InsertRevisions; var deletRevisionsList = differRevisions.DeleteRevisions; } } }
Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Imports Spire.Doc.Formatting.Revisions Imports System Namespace GetWordDifferences Class Program Private Shared Sub Main(ByVal args() As String) 'Load the first Word document Dim doc1 As Document = New Document doc1.LoadFromFile("Sample1.docx") 'Load the second Word document Dim doc2 As Document = New Document doc2.LoadFromFile("Sample2.docx") 'Compare the two Word documents doc1.Compare(doc2, "Author") For Each sec As Section In doc1.Sections For Each docItem As DocumentObject In sec.Body.ChildObjects If (TypeOf docItem Is Paragraph) Then Dim para As Paragraph = CType(docItem,Paragraph) If para.IsInsertRevision Then Dim insRevison As EditRevision = para.InsertRevision Dim insType As EditRevisionType = insRevison.Type Dim insAuthor As String = insRevison.Author Dim insDateTime As DateTime = insRevison.DateTime ElseIf para.IsDeleteRevision Then Dim delRevison As EditRevision = para.DeleteRevision Dim delType As EditRevisionType = delRevison.Type Dim delAuthor As String = delRevison.Author Dim delDateTime As DateTime = delRevison.DateTime End If For Each paraItem As ParagraphBase In para.ChildObjects If paraItem.IsInsertRevision Then Dim insRevison As EditRevision = paraItem.InsertRevision Dim insType As EditRevisionType = insRevison.Type Dim insAuthor As String = insRevison.Author Dim insDateTime As DateTime = insRevison.DateTime ElseIf paraItem.IsDeleteRevision Then Dim delRevison As EditRevision = paraItem.DeleteRevision Dim delType As EditRevisionType = delRevison.Type Dim delAuthor As String = delRevison.Author Dim delDateTime As DateTime = delRevison.DateTime End If Next End If Next Next 'Get the difference about revisions Dim differRevisions As DifferRevisions = New DifferRevisions(doc1) Dim insetRevisionsList = differRevisions.InsertRevisions Dim deletRevisionsList = differRevisions.DeleteRevisions End Sub End Class End Namespace
Hide or display layers in PDF in Java
This article will demonstrate how to hide and display Layers in a PDF document using Spire.PDF for Java.
Hide all layers:
import com.spire.pdf.*; import com.spire.pdf.graphics.layer.*; public class invisibleAllPdfLayers { public static void main(String[] args) { //Load the sample document PdfDocument doc = new PdfDocument(); doc.loadFromFile("layerSample.pdf"); for (int i = 0; i < doc.getLayers().getCount(); i++) { //Show all the Pdf layers //doc.getLayers().get(i).setVisibility(PdfVisibility.On); //Set all the Pdf layers invisible doc.getLayers().get(i).setVisibility(PdfVisibility.Off); } //Save to document to file doc.saveToFile("output/invisibleAllPdfLayers.pdf", FileFormat.PDF); } }
Hide some of the PDF layers:
import com.spire.pdf.*; import com.spire.pdf.graphics.layer.*; public class invisibleParticularPdfLayers { public static void main(String[] args) { //Load the sample document PdfDocument doc = new PdfDocument(); doc.loadFromFile("layerSample.pdf"); //Hide the first layer by index doc.getLayers().get(0).setVisibility(PdfVisibility.Off); //Hide the layer by name with blue line1 for (int i = 0; i < doc.getLayers().getCount(); i++) { if("blue line1".equals(doc.getLayers().get(i).getName())){ doc.getLayers().get(i).setVisibility(PdfVisibility.Off); } } //Save to document to file doc.saveToFile("output/invisiblePaticularPdfLayers.pdf", FileFormat.PDF); } }
Java expand and collapse the bookmarks for PDF
This article will demonstrate how to expand or collapse the bookmarks when viewing the PDF files.
Expand all bookmarks on PDF
import com.spire.pdf.PdfDocument; public class expandBookmarks { public static void main(String[] args) { PdfDocument doc = new PdfDocument(); doc.loadFromFile("Sample.pdf"); //Set true to expand all bookmarks; set false to collapse all bookmarks doc.getViewerPreferences().setBookMarkExpandOrCollapse(true); doc.saveToFile("output/expandAllBookmarks_out.pdf"); doc.close(); } }
Output:
Expand specific bookmarks on PDF
import com.spire.pdf.PdfDocument; import com.spire.pdf.bookmarks.*; public class expandSpecificBookmarks { public static void main(String[] args) { PdfDocument doc = new PdfDocument(); doc.loadFromFile("Sample.pdf"); //Set BookMarkExpandOrCollapse as "true" for the first bookmarks doc.getBookmarks().get(0).setExpandBookmark(true); //Set BookMarkExpandOrCollapse as "false" for the first level of the second bookmarks PdfBookmarkCollection pdfBookmark = doc.getBookmarks().get(1); pdfBookmark.get(0).setExpandBookmark(false); doc.saveToFile("output/expandSpecificBookmarks_out.pdf"); doc.close(); } }
Only expand the first bookmarks
Java: Split a Worksheet into Several Excel Files
Splitting a worksheet can be beneficial when you have a large amount of data and want to organize it into separate files for easier management and sharing. By using this approach, you can organize and distribute your data in a more organized and structured manner. In this tutorial, we will demonstrate how to split a worksheet into multiple Excel documents by using Spire.XLS for Java.
Install Spire.XLS for Java
First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.xls</artifactId> <version>14.3.2</version> </dependency> </dependencies>
Split a Worksheet into Several Excel Files
Spire.XLS for Java provides powerful features that enable us to achieve this task efficiently. The specific steps are as follows.
- Create a Workbook object.
- Load a sample Excel file using Workbook.loadFromFile() method.
- Get the specific sheet using Workbook.getWorksheets().get() method.
- Get the header row and cell ranges using Worksheet.getCellRange() method.
- Create a new workbook and copy the header row and range 1 to the new workbook using Worksheet.copy(CellRange sourceRange, Worksheet worksheet, int destRow, int destColumn, boolean copyStyle, boolean updateRerence) method.
- Copy the column width from the original workbook to the new workbook using Workbook.getWorksheets().get(0).setColumnWidth() method.
- Save the new workbook to an Excel file using Workbook.saveToFile() method.
- Repeat the above operation to copy the header row and range 2 to another new workbook, and save it to another Excel file.
- Java
import com.spire.xls.CellRange; import com.spire.xls.ExcelVersion; import com.spire.xls.Workbook; import com.spire.xls.Worksheet; public class SplitWorksheet { public static void main(String[] args) { //Create a Workbook object to load the original Excel document Workbook bookOriginal = new Workbook(); bookOriginal.loadFromFile("C:\\Users\\Administrator\\Desktop\\Emplyees.xlsx"); //Get the first worksheet Worksheet sheet = bookOriginal.getWorksheets().get(0); //Get the header row CellRange headerRow = sheet.getCellRange(1, 1, 1, 5); //Get two cell ranges CellRange range1 = sheet.getCellRange(2, 1, 6, 5); CellRange range2 = sheet.getCellRange(7, 1, 11, 5); //Create a new workbook Workbook newBook1 = new Workbook(); //Copy the header row and range 1 to the new workbook sheet.copy(headerRow, newBook1.getWorksheets().get(0), 1, 1, true, false); sheet.copy(range1, newBook1.getWorksheets().get(0), 2, 1, true, false); //Copy the column width from the original workbook to the new workbook for (int i = 0; i < sheet.getLastColumn(); i++) { newBook1.getWorksheets().get(0).setColumnWidth(i + 1, sheet.getColumnWidth(i + 1)); } //Save the new workbook to an Excel file newBook1.saveToFile("Sales.xlsx", ExcelVersion.Version2016); //Create another new workbook Workbook newBook2 = new Workbook(); //Copy the header row and range 2 to the new workbook sheet.copy(headerRow, newBook2.getWorksheets().get(0), 1, 1, true, false); sheet.copy(range2, newBook2.getWorksheets().get(0), 2, 1, true, false); //Copy the column width from the original workbook to another new workbook for (int i = 0; i < sheet.getLastColumn(); i++) { newBook2.getWorksheets().get(0).setColumnWidth(i + 1, sheet.getColumnWidth(i + 1)); } //Save it to another new Excel file newBook2.saveToFile("Technicians.xlsx", ExcelVersion.Version2016); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Java set the viewer preference and zoom factor for PDF
This article will demonstrate how to set the zoom factor/percentage (such as default, 100 percent or any other zoom factors as required) and the viewer preference by using Spire.PDF for Java in Java applications.
Set the zoom factor
import com.spire.pdf.*; import com.spire.pdf.actions.*; import com.spire.pdf.general.*; import java.awt.geom.*; public class setZoomFactor { public static void main(String[] args) { //Load the sample document PdfDocument doc = new PdfDocument(); doc.loadFromFile("Sample.pdf"); //Get the first page of PDF PdfPageBase page = doc.getPages().get(0); //Set pdf destination PdfDestination dest = new PdfDestination(page); dest.setMode(PdfDestinationMode.Location); dest.setLocation(new Point2D.Float(-40f, -40f)); //Set zoom factor dest.setZoom(0.8f); //Set action PdfGoToAction gotoAction = new PdfGoToAction(dest); doc.setAfterOpenAction(gotoAction); //Save pdf document String output = "output/setZoomFactor.pdf"; doc.saveToFile(output); } }
Output:
Set the viewer preference
import com.spire.pdf.*; public class viewerPreference { public static void main(String[] args) { //Load the sample document PdfDocument doc = new PdfDocument(); doc.loadFromFile("Sample.pdf"); //Set viewer reference doc.getViewerPreferences().setCenterWindow(true); doc.getViewerPreferences().setDisplayTitle(false); doc.getViewerPreferences().setFitWindow(false); doc.getViewerPreferences().setHideMenubar(true); doc.getViewerPreferences().setHideToolbar(true); doc.getViewerPreferences().setPageLayout(PdfPageLayout.Two_Column_Left); //Save pdf document String output = "output/viewerPreference.pdf"; doc.saveToFile(output); } }
Output: