Step 1: Download the latest version of Spire.PDF Pack from the link below, unzip it, and you'll get the DLL files for .NET Core in the "netcoreapp2.0" folder. If you already have this folder in your disk, go straight to step two.

How to Mannually Add Spire.PDF as Dependency in a .NET Core Application

Step 2: Create a .NET Core application in your Visual Studio.

How to Mannually Add Spire.PDF as Dependency in a .NET Core Application

Step 3: Add all DLL files under the "netcoreapp2.0" folder as dependencies in your project.

Right-click "Dependencies" – select "Add Reference" – click "Browse" – selcet all DLLs under "netcoreapp2.0" folder – click "Add".

How to Mannually Add Spire.PDF as Dependency in a .NET Core Application

Step 4: Install the other two packages in your project via the NuGet Package Manager. They are System.Drawing.Common and System.Text.Encoding.CodePages.

Right-click "Dependencies" – select "Manage NuGet Packages" – click "Browse" –type the package name – select the package from the search results – click "Install".

Note: If you fail to find these packages in the NuGet Package Manager, check if you have set the "nuget.org" as the "Package source".

How to Mannually Add Spire.PDF as Dependency in a .NET Core Application

Step 5: Now that you’ve added all the dependences successfully, you can start to code. The following code snippet gives you an exmaple of how to create a simple PDF document using Spire.PDF.

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace SpirePdfCore
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            //Add a page
            PdfPageBase page = doc.Pages.Add();

            //Draw text on the page at the specified position
            page.Canvas.DrawString("Hello World",
                                    new PdfFont(PdfFontFamily.Helvetica, 13f),
                                    new PdfSolidBrush(Color.Black),
                                    new PointF(50, 50));

            //Save the document
            doc.SaveToFile("Output.pdf");
        }
    }
}

This article will demonstrate how to merge and split table cells on word document in Java applications.

Merge Table cells:

import com.spire.doc.*;

public class MergeTableCell {
    public static void main(String[] args) throws Exception {

        String output = "output/MergeTableCells.docx";

        //Create a Document instance
        Document document = new Document();

        Section section = document.addSection();
        Table table = section.addTable(true);
        table.resetCells(4, 4);
        
        //how to merge cells horizontally
        table.applyHorizontalMerge(0, 0, 3);

        //how to merge cells vertically
        table.applyVerticalMerge(0, 2, 3);

        //save the document to file
        document.saveToFile(output, FileFormat.Docx);
    }
}

Java merge and split table cells on Word document

Split table cells:

import com.spire.doc.*;

public class SplitTableCell {
    public static void main(String[] args) throws Exception {

        String output = "output/SplitTableCells.docx";

        //Create a Document instance
        Document document = new Document();

        Section section = document.addSection();
        Table table = section.addTable(true);
        table.resetCells(4, 4);

        //split the cell
        table.getRows().get(3).getCells().get(3).splitCell(2, 2);

        //save the document to file
        document.saveToFile(output, FileFormat.Docx);
    }
}

Java merge and split table cells on Word document

Step 1: Download the latest version of Spire.Doc Pack from the link below, unzip it, and you'll get the DLL files for .NET Core in the “netcoreapp2.0” folder. If you already have this folder in your disk, go straight to step two.

How to Mannually Add Spire.Doc as Dependency in a .NET Core Application

Step 2: Create a .Net Core application in your Visual Studio.

How to Mannually Add Spire.Doc as Dependency in a .NET Core Application

Step 3: Add all DLL files under the "netcoreapp2.0" folder as dependencies in your project.

Right-click "Dependencies" – select "Add Reference" – click "Browse" – selcet all DLLs under "netcoreapp2.0" folder – click "Add".

How to Mannually Add Spire.Doc as Dependency in a .NET Core Application

Step 4: Install the other three packages in your project via the NuGet Package Manager. They are System.Drawing.Common, System.Text.Encoding.CodePages and System.Security.Cryptography.Xml.

Right-click "Dependencies" – select "Manage NuGet Packages" – click "Browse" –type the package name – select the package from the search results – click "Install".

Note: If you fail to find these packages in the NuGet Package Manager, check if you have set the "nuget.org" as the "Package source".

How to Mannually Add Spire.Doc as Dependency in a .NET Core Application

Step 5: Now that you've added all the dependences successfully, you can start to code. The following code snippet gives you an exmaple of how to create a simple Word document using Spire.Doc.

using Spire.Doc;
using Spire.Doc.Documents;

namespace SpireDocNetCore
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a document object
            Document doc = new Document();

            //Add a section
            Section section = doc.AddSection();

            //Add a paragrah
            Paragraph paragraph = section.AddParagraph();

            //Append text to the paragraph
            paragraph.AppendText("This article shows you how to mannually add Spire.Doc as dependency in a .NET Core application.");

            //Save to file
            doc.SaveToFile("Output.docx", FileFormat.Docx2013);
        }
    }
}
Saturday, 12 October 2019 09:41

Detect PDF Page Orientation in Java

Spire.PDF for Java supports detecting the orientation of a PDF page by comparing the value of page width and page height. This article shows how to use Spire.PDF for Java to accomplish this function.

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;

public class DetectPageOrientation {
    public static void main(String[] args){
        //Load PDF file
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("Fields.pdf");

        //Get the first page
        PdfPageBase page = pdf.getPages().get(0);

        //Compare the value of page width and height
        if (page.getSize().getWidth()> page.getSize().getHeight()){
            System.out.println("The page orientation is Landscape");
        }
        else{
            System.out.println("The page orientation is Portrait");
        }
    }
}

Output

Detect PDF Page Orientation in Java

Saturday, 12 October 2019 03:45

Auto Fit Text or Shape in PowerPoint in Java

This article demonstrates how to automatically shrink text to fit a shape or how to automatically resize a shape to fit text by using Spire.Presentation for Java.

import com.spire.presentation.*;

import java.awt.geom.Rectangle2D;

public class AutoFitTextOrShape {

    public static void main(String[] args) throws Exception {

        //create Presentation instance 
        Presentation presentation = new Presentation();

        //get the first slide 
        ISlide slide = presentation.getSlides().get(0);

        //add a shape to slide 
        IAutoShape textShape1 = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(50,50,200,80));

        //add text to shape
        textShape1.getTextFrame().setText("Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape.");

        //set the auto-fit type to normal, which means the text automatically shrinks to fit the shape when text overflows the shape
        textShape1.getTextFrame().setAutofitType(TextAutofitType.NORMAL);

        //add another shape to slide 
        IAutoShape textShape2 = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(350, 50, 200, 80));
        textShape2.getTextFrame().setText("Resize shape to fit text.");

        //set the auto-fit type to shape, which means the shape size automatically decreases or increases to fit text
        textShape2.getTextFrame().setAutofitType(TextAutofitType.SHAPE);

        //save to file 
        presentation.saveToFile("output/AutoFit.pptx", FileFormat.PPTX_2013);
    }
}

Auto Fit Text or Shape in PowerPoint in Java

This article will demonstrate how to create a mail merge template and then merge the text value to the template in Java application with the help of Spire.Doc.

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MailMerge {
    public static void main(String[] args) throws Exception {

        String output = "output/mailMerge.docx";

        //Create a Document instance
        Document document = new Document();

        //Add a section
        Section section = document.addSection();

        //Add 3 paragraphs to the section
        Paragraph para = section.addParagraph();
        Paragraph para2 = section.addParagraph();
        Paragraph para3 = section.addParagraph();

        //Add mail merge templates to each paragraph
        para.setText("Contact Name: ");
        para.appendField("Contact Name", FieldType.Field_Merge_Field);
        para2.setText("Phone: ");
        para2.appendField("Phone", FieldType.Field_Merge_Field);
        para3.setText("Date: ");
        para3.appendField("Date", FieldType.Field_Merge_Field);

        //Set the value for the mail merge template by the field name
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String[] filedNames = new String[]{"Contact Name", "Phone", "Date"};
        String[] filedValues = new String[]{"John Smith", "+1 (69) 123456", dateString};

        //Merge the specified value into template
        document.getMailMerge().execute(filedNames, filedValues);

        //save the document to file
        document.saveToFile(output, FileFormat.Docx);
    }
}

Effective screenshot for the mail merge:

Java create mail merge and merge text value on Word

Sunday, 29 September 2019 09:32

Spire.XLS Program Guide Content for Java

Spire.XLS for Java is a professional Java Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets without using Microsoft Office or Microsoft Excel.

Spire.XLS for Java supports both for the old Excel 97-2003 format (.xls) and for the new Excel 2007, Excel 2010, Excel 2013 and Excel 2016 (.xlsx, .xlsb, .xlsm), along with Open Office(.ods) format. Spire.XLS for Java offers a wide range of features of operating Excel worksheets on Java applications, such as create, read, edit, convert and print Excel worksheets, find and replace data, create charts, create auto filters, read and write hyperlinks, merge/unmerge cells and files, group/ungroup rows and columns, freeze/unfreeze Panes, encrypt/decrypt Excel workbooks etc.


Spire.PDF for Java empowers developers to read and extract value from a specific form field as well as read and extract values from all form fields. In this article, we'll see how to use Spire.PDF for Java to implement this function.

Below is the sample PDF document we used for demonstration:

Read and Extract Fillable Form Values in PDF in Java

Read and extract value from a specific form field

import com.spire.pdf.PdfDocument;
import com.spire.pdf.widget.PdfFormWidget;
import com.spire.pdf.widget.PdfTextBoxFieldWidget;

import java.io.FileWriter;
import java.io.IOException;


public class ReadSpeicificFormValue {
    public static void main(String[] args){
        //Load PDF document
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("fillFormFields.pdf");

        //Get form fields
        PdfFormWidget formWidget = (PdfFormWidget)pdf.getForm();

        //Get the textbox by index or by name
        PdfTextBoxFieldWidget textbox = ( PdfTextBoxFieldWidget)formWidget.getFieldsWidget().get(0);
        //PdfTextBoxFieldWidget textbox = ( PdfTextBoxFieldWidget)formWidget.getFieldsWidget().get("TextBox");

        //Get the text of the textbox
        String text = textbox.getText();

        try {
            //Write text into a .txt file
            FileWriter writer = new FileWriter("GetSpecificFieldValue.txt");
            writer.write(text);
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

        pdf.close();
    }
}

Read and Extract Fillable Form Values in PDF in Java

Read and extract values from all form fields

import com.spire.pdf.PdfDocument;
import com.spire.pdf.fields.PdfField;
import com.spire.pdf.widget.*;

import java.io.FileWriter;
import java.io.IOException;


public class ReadAllFormValues {
    public static void main(String[] args)
        //Load PDF document
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("fillFormFields.pdf");

        //Get form fields
        PdfFormWidget formWidget = (PdfFormWidget)pdf.getForm();

        StringBuilder sb = new StringBuilder();
        //Loop through the form field widget collection and extract the value of each field
        for (int i = 0; i < formWidget.getFieldsWidget().getCount(); i++)
        {
            PdfField field = (PdfField)formWidget.getFieldsWidget().getList().get(i);
            if (field instanceof PdfTextBoxFieldWidget)
            {
                PdfTextBoxFieldWidget textBoxField = (PdfTextBoxFieldWidget)field ;
                //Get text of textbox
                String text = textBoxField.getText();
                sb.append("The text in textbox is: " + text + "\r\n");
            }

            if (field instanceof PdfListBoxWidgetFieldWidget)
            {
                PdfListBoxWidgetFieldWidget listBoxField = (PdfListBoxWidgetFieldWidget)field;
                sb.append("Listbox items are: \r\n");
                //Get values of listbox
                PdfListWidgetItemCollection items = listBoxField.getValues();

                for (PdfListWidgetItem item : (Iterable<PdfListWidgetItem>) items)
                {
                    sb.append(item.getValue() + "\r\n");
                }
                //Get selected value
                String selectedValue = listBoxField.getSelectedValue();
                sb.append("The selected value in the listbox is: " + selectedValue + "\r\n");
            }

            if (field instanceof PdfComboBoxWidgetFieldWidget)
            {
                PdfComboBoxWidgetFieldWidget comBoxField = (PdfComboBoxWidgetFieldWidget)field ;
                sb.append("comBoxField items are: \r\n");
                //Get values of comboBox
                PdfListWidgetItemCollection items = comBoxField.getValues();

                for (PdfListWidgetItem item : (Iterable<PdfListWidgetItem>) items)
                {
                    sb.append(item.getValue() + "\r\n");
                }
                //Get selected value
                String selectedValue = comBoxField.getSelectedValue();
                sb.append("The selected value in the comBoxField is: " + selectedValue + "\r\n");
            }

            if (field instanceof PdfRadioButtonListFieldWidget)
            {
                PdfRadioButtonListFieldWidget radioBtnField = (PdfRadioButtonListFieldWidget)field;
                //Get value of radio button
                String value = radioBtnField.getValue();

                sb.append("The text in radioButtonField is: " + value + "\r\n");
            }

            if (field instanceof PdfCheckBoxWidgetFieldWidget)
            {
                PdfCheckBoxWidgetFieldWidget checkBoxField = (PdfCheckBoxWidgetFieldWidget)field;
                //Get the checked state of the checkbox
                boolean state = checkBoxField.getChecked();
                sb.append("Is the checkBox checked? " + state + "\r\n");
            }
        }

        try {
            //Write text into a .txt file
            FileWriter writer = new FileWriter("GetAllValues.txt");
            writer.write(sb.toString());
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

        pdf.close();
    }
}

Read and Extract Fillable Form Values in PDF in Java

Tuesday, 24 September 2019 03:38

Add a Logo to QR Code in C#

This article demonstrates how to add a logo or an image to a QR code using Spire.Barcode for .NET.

Note: This feature relies on a comemrcial license. If you want to test it, please contact sales for a temporary license.

using Spire.Barcode;
using Spire.License;
using System.Drawing;

namespace AddLogoToQR
{
    class Program
    {
        static void Main(string[] args)
        {
            //load license file
            Spire.License.LicenseProvider.SetLicenseFileFullPath("license.elic.xml");

            //create BarcodeSettings object
            BarcodeSettings settings = new BarcodeSettings();

            //specify barcode type, data, etc.
            settings.Type = BarCodeType.QRCode;
            settings.QRCodeECL = QRCodeECL.M;
            settings.ShowText = false;
            settings.X = 2.5f;
            string data = "www.e-iceblue.com";
            settings.Data = data;
            settings.Data2D = data;

            //add an image to QR code
            settings.QRCodeLogoImage = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png");

            //generate QR image based on the settings
            BarCodeGenerator generator = new BarCodeGenerator(settings);
            Image image = generator.GenerateImage();
            image.Save("QR.png", System.Drawing.Imaging.ImageFormat.Png);
        }
    }
}

Add a Logo to QR Code in C#

Monday, 23 September 2019 09:49

Find and replace text on PDF document in C#

Spire.PDF supports to find and replace the text in all the pages of PDF document. This article is going to show you how to replace text in the first page of PDF document in C#.

Step 1: Load the sample document file.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("SearchReplaceTemplate.pdf");

Step 2: Searched the text “Spire.PDF for .NET” from the first page of the sample document.

PdfPageBase page = doc.Pages[0];
PdfTextFindCollection collection = page.FindText("Spire.PDF for .NET", TextFindParameter.IgnoreCase);

Step 3: Use the new string “E-iceblue Spire.PDF” to replace the searched text and sent the font and color for the new string.

String newText = "E-iceblue Spire.PDF";
//Creates a brush
PdfBrush brush = new PdfSolidBrush(Color.DarkBlue);
//Defines a font
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Regular));

RectangleF rec;
foreach (PdfTextFind find in collection.Finds)
{
    // Gets the bound of the found text in page
    rec = find.Bounds;
    page.Canvas.DrawRectangle(PdfBrushes.White, rec);
    page.Canvas.DrawString(newText, font, brush, rec);

}

Step 4: Save the document to file.

doc.SaveToFile("ReplaceAllSearchedText_out.pdf");

Sample PDF document:

Find and replace text on PDF document in C#

Effective screenshot after replaced the searched text on PDF.

Find and replace text on PDF document in C#