How to load a document that contains fundamental syntax errors.
In the WPF PDF Viewer, documents containing minor syntax errors can be successfully opened using the Open and Repair feature provided by the PdfLoadedDocument object.
Steps to Load a PDF that contains fundamental syntax errors
Step 1: In the button click event handler, create an OpenFileDialog object that allows users to select only PDF files.
var dialog = new OpenFileDialog
{
Filter = "PDF files (*.pdf)|*.pdf",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
};
if (dialog.ShowDialog() == true)
{
LoadPdfFile(dialog.FileName);
}
Step 2: Open the selected PDF document from the OpenFileDialog using the OpenAndRepair
overloads of the PdfLoadedDocument. To address the basic syntax error, pass true
to the OpenAndRepair
parameter of the overload.
//Repair the PDF document with basic syntax errors
pdfDocument = new PdfLoadedDocument(new FileStream(value, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true);
pdfViewer.Load(pdfDocument);
A complete working sample to handle the document with basic syntax errors can be downloaded from GitHub.
Conclusion
I hope you enjoyed learning about how to load a document that contains fundamental syntax errors. In the WPF PDF Viewer Control.
You can refer to our WPF PDF Viewer page to learn about its other groundbreaking features and documentation, as well as how to quickly get started with configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarification, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!