PSPDFKit 1.12 for Windows
Today we’re shipping PSPDFKit 1.12 for Windows. This release features a model only Document Editor, API for accessing glyph positions, the ability to index password protected documents, cloudy borders for annotations and more.
Document Editor
This version of PSPDFKit for Windows introduces the model only Document Editor. This allows various methods of editing, merging, splitting, and rearranging documents in code.
The following example code demonstrates how to delete the second page from a document:
// Load a document as per usual. Note that it must not be loaded into a `PdfView`. var source = DocumentSource.CreateFromStorageFile(file); var doc = await Document.OpenDocumentAsync(source); // Create a new editing job var job = new PSPDFKit.Document.Editor.Job(doc); // Remove the second page by index await job.RemovePagesAsync(new[] { 1 }); // Produce a new document from that job in temporary storage var newStorageFile = await Editor.NewStorageFileFromJobAsync(job);
And this example demonstrates how to create a new document by appending a page from one document to another.
// Given two documents PSPDFKit.Pdf.Document documentOne; PSPDFKit.Pdf.Document documentTwo; // Create a new editing job with the first document as the source var job = new PSPDFKit.Document.Editor.Job(documentOne); // Create a new page from the first page of the second document var newPage = NewPage.FromPage(documentTwo, 0); // Append it to the end of the first document var numPages = await documentOne.GetTotalPageCountAsync(); await job.AddPageAtIndexAsync(newPage, numPages); // Produce a new document from that job in temporary storage var newStorageFile = await Editor.NewStorageFileFromJobAsync(job);
See the Catalog example and Document Editor guide for more in depth examples and explanations.
Text Parse / Glyph Positions
As part of PSPDFKit for Windows 1.12 we have extended the text extraction capabilities to include the ability to get individual character information like content, position, size and more.
var textParser = document.GetTextParserAsync(0); var glyphs = textParser.GetGlyphsAsync();
The new ability to get glyph information is now part of the new TextParser
class which can be obtained from Pdf.Document
on a per page basis. The new TextParser
also means we have deprecated Document.TextForPageIndexAsync
in favor of TextParser.GetTextAsync
. The former will be removed completely in a future version of the SDK.
Indexing Password Protected Documents
When indexing documents from a folder for Full Text Search, sometimes we’ll come across a password protected document. Prior to PSPDFKit for Windows 1.12 this would be ignored, but now it’s possible to unlock these documents for indexing.
We achieve this by implementing an event handler which is fired every time a new password protected document is found. This way, it’s possible to provide PSPDFKit for Windows the required password. The following example shows how to achieve this:
private Library _library; internal async void Initialize(PdfView pdfView) { _library = await Library.OpenLibraryAsync("catalog"); _library.OnPasswordRequested += Library_OnPasswordRequested; } private void Library_OnPasswordRequested(Library sender, PasswordRequest passwordRequest) { if (passwordRequest.Uid.Contains("Password.pdf")) { passwordRequest.Password = "test123"; break; } // It is essential to signal completion via the deferral. passwordRequest.Deferral.Complete(); }
PasswordRequest
will always have the Uid populated with the path being indexed (note the full path will be assigned a unique id, but the filename will remain). Check against this string to determine which document is requiring a password and populate Password
member of PasswordRequest
in order to unlock the document. Please ensure the Deferral
is completed as per the last line of Library_OnPasswordRequested
, otherwise, the index will fail and throw an exception.
Cloudy Borders
We’ve added support for the BorderStyle
cloudy
. We’ve also added the property CloudyBorderIntensity
to the Ellipse
, Rectangle
and Polygon
shape annotations.
Cloudy borders can help visually distinguish an annotation from any underlying diagrams containing lots of horizontal and vertical lines.
Final Notes
Along with all the new features, this release also includes a number of bug fixes and some minor improvements. For a complete list of changes, see the changelog.