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 Standarad from the "netstandard2.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 Standard Library Project

Step 2: Create a .NET Standard library project in your Visual Studio.

How to Mannually Add Spire.Doc as Dependency in a .NET Standard Library Project

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

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

How to Mannually Add Spire.Doc as Dependency in a .NET Standard Library Project

Step 4: Install the other three packages in your project via the NuGet Package Manager. They are SkiaSharp, 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".

How to Mannually Add Spire.Doc as Dependency in a .NET Standard Library Project

Step 5: Now that you've added all the dependences successfully, you can start to write your own .NET Standard library that is capable of creating and processing Word documents.

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

namespace SpireDocStandard
{
    public class Class1
    {
        public void CreateWord()
        {
            //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("Hello World");

            //Save to file
            doc.SaveToFile("Output.docx", FileFormat.Docx2013);
        }  
    }
}
Thursday, 17 October 2019 09:30

Add Data Labels to Chart in PowerPoint in Java

This article demonstrates how to add data labels to a chart and set the appearance (border style and fill style) for the data labels in PowerPoint using Spire.Presentation for Java. Note some chart types like Surface3D, Surface3DNoColor, Contour and ContourNoColor do not support data labels.

Below screenshot shows the original chart before adding data labels:

Add Data Labels to Chart in PowerPoint in Java

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.charts.entity.ChartDataLabel;
import com.spire.presentation.charts.entity.ChartSeriesDataFormat;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;

public class AddDataLabelsToChart {
    public static void main(String[] args) throws Exception {
        //Load the PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("Chart.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);
        //Get the chart in the slide
        IChart chart = (IChart)slide.getShapes().get(0);

        //Loop through the series in the chart
        for (ChartSeriesDataFormat series:(Iterable)chart.getSeries()
             ) {
            //Add data labels for the data points in each series
            for(int i = 0; i < 4; i++){
                ChartDataLabel dataLabel = series.getDataLabels().add();
                //Show label value
                dataLabel.setLabelValueVisible(true);
                //Show series name
                dataLabel.setSeriesNameVisible(true);
                //Set border line style
                dataLabel.getLine().setFillType(FillFormatType.SOLID);
                dataLabel.getLine().getSolidFillColor().setColor(Color.RED);
                //Set fill style
                dataLabel.getFill().setFillType(FillFormatType.SOLID);
                dataLabel.getFill().getSolidColor().setColor(Color.YELLOW);
            }
        }

        //Save the resultant document
        ppt.saveToFile("DataLabels.pptx", FileFormat.PPTX_2013);
    }
}

Output:

Add Data Labels to Chart in PowerPoint in Java

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

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#

Page 2 of 113