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.
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");
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();
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.
foreach(var page in pdfDocument.Pages)
{
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));
}
Now we will open a PDF document, check if it contains at least two pages and if yes remove the second page.
if (pdfDocument.Pages.Count > 1)
pdfDocument.Pages.RemoveAt(1); // remove second page
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");
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.
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;
Try PDFPrinting.NET demo for free!