Reads an existing document.

 

   

Syntax
 

[C#]
virtual void Read(string path)
virtual void Read(byte[] data)
virtual void Read(string path, string password)
virtual void Read(byte[] data, string password)

[Visual Basic]
Sub Read(ByVal path As String)
Sub Read(ByVal data() As Byte)

Sub Read(ByVal path As String, ByVal password As String)
Sub Read(ByVal data() As Byte, ByVal password As String)

Throws Exceptions may throw Exception()

 

   

Params
 
Name Description
path

The file path to the PDF, OpenOffice.org or SVG document.

data

The source PDF data.

password

Any password needed to open the document.

 

   

Notes
 

Use this method to read a file into a document object. Any existing document content will be discarded.

You can specify a PDF as a file path or by passing in the raw PDF data. Raw data must be held as an array of bytes. You can open encrypted PDF documents if you supply a valid password.

If OpenOffice.org is installed you can pass this method a file path to any OpenOffice.org compatible document. This means you can read file types like Microsoft Word (.doc), Microsoft Excel (.xls), Rich Text Format (.rtf), WordPerfect (.wpd), Lotus 1-2-3 (.wk1) and AutoCAD (.dxf).

You can pass this method a file path to an SVG or SVGZ document for conversion to PDF. ABCpdf supports a subset of SVG based around the SVG Tiny specification. For details see the SVG Support section of the documentation.

After the read operation is complete the Page property will contain the ID of the first page in the document.

The Rect and MediaBox properties will reflect the size of the first page in the document.

ABCpdf .NET operates an intelligent just-in-time object loading scheme which ensures that only those objects that are required are loaded into memory. This means that if you are modifying large documents then server load will be kept to a minimum. The original PDF document must be available for as long as the Document object is being used.

As a result you cannot read, modify and overwrite a PDF file. You will need to save your PDF to another location and then swap the two files round.

Object deletion requires that all references to an object are removed. There is no way of doing this without checking each object in the document. So object deletion requires that every object in the document is loaded and for large documents this may place a significant load on the server.

Reading encrypted documents places a greater load on the server because - like object deletion - it requires that every object in the document be loaded.

Please note that you are legally bound to respect the permissions present in existing PDF documents. For details please see the Legal Requirement Section.

The Read method may be used to read eForm FDF documents as well as PDF documents. Most PDF operations will not work on FDF documents but you can query field values using the GetInfo methods to return Unicode strings.

Modifying Documents. ABCpdf will allow you to open, modify and save PDF documents.

ABCpdf will allow you to draw on top of PDF documents or add or delete pages or modify document data. However because of the way that PDF documents are structured it's unlikely that you'll be able to edit existing content.

So if there are blank spaces which you can draw your entries into that will work. Indeed you might want to draw a white box over existing content and then draw on that.

However you shouldn't expect to be able to edit and re-flow text that is already in your PDF.

 

   

Example
 

The following illustrates how one might add a large red number to every page of a PDF document.

[C#]
Doc theDoc = new Doc();
theDoc.Read(Server.MapPath("../mypics/sample.pdf"));
theDoc.FontSize = 500;
theDoc.Color.String = "255 0 0";
theDoc.HPos = 0.5;
theDoc.VPos = 0.3;
int theCount = theDoc.PageCount;
for (int i = 1; i <= theCount; i++) {
  theDoc.PageNumber = i;
  theDoc.AddText(i.ToString());
}
theDoc.Save(Server.MapPath("docread.pdf"));
theDoc.Clear();

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Read(Server.MapPath("../mypics/sample.pdf"))
theDoc.FontSize = 500
theDoc.Color.String = "255 0 0"
theDoc.HPos = 0.5
theDoc.VPos = 0.3
Dim theCount As Integer = theDoc.PageCount
Dim i As Integer
For i = 1 To theCount
  theDoc.PageNumber = i
  theDoc.AddText(i.ToString())
Next
theDoc.Save(Server.MapPath("docread.pdf"))
theDoc.Clear()


docsave.pdf - [Page 1]

docsave.pdf - [Page 2]

docsave.pdf - [Page 3]

docsave.pdf - [Page 4]