EDITOR FEATURES

Here you can find a quick overview and test of the PDFPrinting.NET Editor module. For more details, please visit our quick start guide or check out the reference documentation.


  • Edit text and fonts
  • Add comments and markup
  • Insert and delete PDF pages
  • Rotate and move pages
  • Set PDF security permission
  • Fill in a PDF form
  • Extract a document page
  • Export PDF to other formats
  • Modify color space

LIST OF FEATURES


CREATE NEW PDF DOCUMENT

This example will demonstrate how you can easily create a new PDF document and add some text and images to it.

PdfDocument pdfDocument = new PdfDocument();
var page = pdfDocument.AddPage();
page.Size = PdfEdit.PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("How deep is the rabbit hole?", new XFont("Ariel", 10), XBrushes.Blue, new PointF(100, 100));
XImage image = XImage.FromFile(@"c:\images2\w3c_home.jpg");
gfx.DrawImage(image, new Point(300, 300));
gfx.Dispose();
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

ADD PAGES TO EXISTING PDF DOCUMENT

Here we will take an existing PDF document and append additional pages to it. The newly appended pages will not contain any content.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
var newPage = pdfDocument.AddPage();
var newPage2 = pdfDocument.AddPage();
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

EDIT EXISTING PDF DOCUMENT

In this case, we take an existing document and insert a watermark on every page. This example uses a text message as the watermark, but you can just as easily insert an image.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
foreach(var page in pdfDocument.Pages)
{
	XGraphics gfx = XGraphics.FromPdfPage(page);
	gfx.DrawString("Lets pretend this is a watermark message...", new XFont(this.Font.FontFamily.Name, 10),
                                                                    XBrushes.Red,  new PointF(50, 50));
	XImage image = XImage.FromFile(@"c:\images\w3c_home.bmp");
	gfx.DrawImage(image, new Point(150, 150));
	gfx.Dispose();
}
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

REMOVE PAGES FROM PDF DOCUMENT

Now we will open a PDF document, check if it contains at least two pages and if yes remove the second page.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
if (pdfDocument.Pages.Count > 1)
	pdfDocument.Pages.RemoveAt(1); // remove second page
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

EXTRACT PAGES FROM PDF DOCUMENT

Let's try now to extract every second page from an existing document. This code would create a new document which would contain every second page from the original document. The original document would stay unharmed.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Import);
PdfDocument newPdfDocument = new PdfDocument();
for (int i = 0; i < pdfDocument.Pages.Count; i++)            
	if ((i + 1) % 2 == 0)
		newPdfDocument.AddPage(pdfDocument.Pages[i]);
newPdfDocument.SetLicenseInfo("companyName", "licenseKey");
newPdfDocument.Save(@"c:\test\test2.pdf");

USING PRINTERSETTINGS IN PRINTING

Let's try now to extract every second page from an existing document. This code would create a new document which would contain every second page from the original document. The original document would stay unharmed.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
pdfDocument.SecuritySettings.PdfDocumentEncryptionAlgorithm = new EncryptionAlgorithmInfo();
pdfDocument.SecuritySettings.PdfDocumentEncryptionAlgorithm.Type = PdfDocumentSecurityLevel.AES_256;
// user access permissions
pdfDocument.SecuritySettings.OwnerPassword = "ownerPass";
pdfDocument.SecuritySettings.UserPassword = "userPass";
pdfDocument.SecuritySettings.PermitAccessibilityExtractContent = true;
pdfDocument.SecuritySettings.PermitAnnotations = true;
pdfDocument.SecuritySettings.PermitAssembleDocument = true;
pdfDocument.SecuritySettings.PermitExtractContent = true;
pdfDocument.SecuritySettings.PermitFormsFill = false;
pdfDocument.SecuritySettings.PermitFullQualityPrint = false;
pdfDocument.SecuritySettings.PermitModifyDocument = true;
pdfDocument.SecuritySettings.PermitPrint = true;
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");        

FILL IN A PDF FORM

Now let's fill in text fields of a PDF form. Changes will be saved into a separate document and the original document will stay unmodified.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
var  textField = (pdfDocument.AcroForm.Fields["FieldSubjectType"] as PdfTextField);  // get field by name or index
if (!textField.ReadOnly)
	textField.Text = "Top Secret";
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test2.pdf");       

CREATE NEW PDF DOCUMENT

This example will demonstrate how you can easily create a new PDF document and add some text and images to it.

PdfDocument pdfDocument = new PdfDocument();
var page = pdfDocument.AddPage();
page.Size = PdfEdit.PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("How deep is the rabbit hole?", new XFont("Ariel", 10), XBrushes.Blue, new PointF(100, 100));
XImage image = XImage.FromFile(@"c:\images2\w3c_home.jpg");
gfx.DrawImage(image, new Point(300, 300));
gfx.Dispose();
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

ADD PAGES TO EXISTING PDF DOCUMENT

Here we will take an existing PDF document and append additional pages to it. The newly appended pages will not contain any content.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
var newPage = pdfDocument.AddPage();
var newPage2 = pdfDocument.AddPage();
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

EDIT EXISTING PDF DOCUMENT

In this case, we take an existing document and insert a watermark on every page. This example uses a text message as the watermark, but you can just as easily insert an image.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
foreach(var page in pdfDocument.Pages)
{
	XGraphics gfx = XGraphics.FromPdfPage(page);
	gfx.DrawString("Lets pretend this is a watermark message...", new XFont(this.Font.FontFamily.Name, 10),
                                                                    XBrushes.Red,  new PointF(50, 50));
	XImage image = XImage.FromFile(@"c:\images\w3c_home.bmp");
	gfx.DrawImage(image, new Point(150, 150));
	gfx.Dispose();
}
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

REMOVE PAGES FROM PDF DOCUMENT

Now we will open a PDF document, check if it contains at least two pages and if yes remove the second page.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
if (pdfDocument.Pages.Count > 1)
	pdfDocument.Pages.RemoveAt(1); // remove second page
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");

EXTRACT PAGES FROM PDF DOCUMENT

Let's try now to extract every second page from an existing document. This code would create a new document which would contain every second page from the original document. The original document would stay unharmed.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Import);
PdfDocument newPdfDocument = new PdfDocument();
for (int i = 0; i < pdfDocument.Pages.Count; i++)
	if ((i + 1) % 2 == 0)
		newPdfDocument.AddPage(pdfDocument.Pages[i]);
newPdfDocument.SetLicenseInfo("companyName", "licenseKey");
newPdfDocument.Save(@"c:\test\test2.pdf");

PROTECT PDF DOCUMENT AND SET USER ACCESS PERMISSIONS

Let's now open an existing document, encrypt it with AES256, change the user access permission and secure it with a username and password. As you can see from the code we, for example, disabled full quality prints and form fills.

vPdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
pdfDocument.SecuritySettings.PdfDocumentEncryptionAlgorithm = new EncryptionAlgorithmInfo();
pdfDocument.SecuritySettings.PdfDocumentEncryptionAlgorithm.Type = PdfDocumentSecurityLevel.AES_256;
// user access permissions
pdfDocument.SecuritySettings.OwnerPassword = "ownerPass";
pdfDocument.SecuritySettings.UserPassword = "userPass";
pdfDocument.SecuritySettings.PermitAccessibilityExtractContent = true;
pdfDocument.SecuritySettings.PermitAnnotations = true;
pdfDocument.SecuritySettings.PermitAssembleDocument = true;
pdfDocument.SecuritySettings.PermitExtractContent = true;
pdfDocument.SecuritySettings.PermitFormsFill = false;
pdfDocument.SecuritySettings.PermitFullQualityPrint = false;
pdfDocument.SecuritySettings.PermitModifyDocument = true;
pdfDocument.SecuritySettings.PermitPrint = true;
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test.pdf");
fill regularFill in a PDF form

FILL IN A PDF FORM

Now let's fill in text fields of a PDF form. Changes will be saved into a separate document and the original document will stay unmodified.

PdfDocument pdfDocument = PdfReader.Open(@"c:\test\test.pdf", PdfDocumentOpenMode.Modify);
var  textField = (pdfDocument.AcroForm.Fields["FieldSubjectType"] as PdfTextField);  // get field by name or index
if (!textField.ReadOnly)
	textField.Text = "Top Secret";
pdfDocument.SetLicenseInfo("companyName", "licenseKey");
pdfDocument.Save(@"c:\test\test2.pdf");