C# API

Example

// Instantiate export client
ExportClient exportClient = new ExportClient("enter your export key here");

// Set export properties
exportClient.setSourceUrl("http://news.google.com");
exportClient.enableLinks(true);
exportClient.avoidImageBrake(true);
exportClient.setFormat(Constants.FORMAT_A4);
exportClient.setOrientation(Constants.ORIENTATION_PORTRAIT);
exportClient.setStandard(Constants.STANDARD_PDF);

// Use one of the following methods to export

// Export HTML to a local file
string errorMsg = exportClient.exportToFile("enter path to the PDF file");
// Export HTML and save the resultant file in the default download location
string errorMsg = exportClient.exportToAttachment(HttpContext.Current.Response);
// Export HTML and open the resultant file in the browser
string errorMsg = exportClient.exportInline(HttpContext.Current.Response);

if (errorMsg != null)
{
    // Handle error
}
                                                
Visit our Demo pages and see more sample code

Summary

namespace: RunPDF
Class ExportClient
Click here to view the source
Description:
The class is used to access RunPDF web service that lets you create PDF documents from WebPages or raw HTML markup in your applications.

Constructors

public ExportClient(string exportKey)
Description:
A constructor that initializes a newly created ExportClient object with the specified export key.
Parameters:
exportKey - The key is used for the request authentication. All accounts are assigned a unique export key. The key is available in the signup confirmation email and the Order Detail page.

public ExportClient(string exportKey, string serviceURL)
Description:
A constructor that initializes a newly created ExportClient object with the specified export key.
Parameters:
exportKey - The key is used for the request authentication. All accounts are assigned a unique export key. The key is available in the signup confirmation email and the Order Detail page.
serviceURL - The URL to RunPDF export web service.

Service Methods

public int export(Stream outputStream)
Description:
Base export method. Exports HTML content to PDF and copies the stream of the resultant document to the target OutputStream.
Parameters:
outputStream - The target OutputStream.
Returns:
Size of the resultant document stream.
Throws:
Exception - The exception is thrown in case of failure to execute. The exception message is set to a specific error code (see RunPDF.Constants.ERROR_CODE_MESSAGE_MAP).

public String exportToFile(string filePath)
Description:
Exports HTML content to the specified PDF file.
Parameters:
filePath - A path to the target file.
Returns:
null if export is successful, otherwise a message that corresponds to the code of the error (see RunPDF.Constants.ERROR_CODE_MESSAGE_MAP)

public String exportToAttachment(HttpResponse response)
Description:
Exports HTML content to PDF and saves the document to the disk.
Parameters:
response - Current HttpResponse.
Returns:
null if export is successful, otherwise a message that corresponds to the code of the error (see RunPDF.Constants.ERROR_CODE_MESSAGE_MAP)

public String exportInline(HttpResponse response)
Description:
Exports HTML content to PDF and opens the document in the browser.
Parameters:
response - Current HttpResponse.
Returns:
null if export is successful, otherwise a message that corresponds to the code of the error (see RunPDF.Constants.ERROR_CODE_MESSAGE_MAP)

Other Methods

public void setSourceUrl(string sourceUrl)
Description:
Sets source web page URL to convert.
Parameters:
sourceUrl - URL of the target web page.
Note:
Ether source Url or source HTML is required.

public void setSourceUrl(string sourceUrl, string sourceUrl2)
Description:
Sets primary and secondary source web page URLs to convert.
Parameters:
sourceUrl - URL of the target web page.
sourceUrl2 - URL of the secondary target web page.

public void setSourceHtml(string sourceHtml)
Description:
Sets HTML source string.
Parameters:
sourceHtml - HTML string to convert.
Note:
Ether source Url or source HTML is required.

public void setMediaTypePrint(boolean value)
Description:
Sets if to present the document on print media style.
Parameters:
value - Boolean value. Default is false.

public void SetSinglePage(boolean value)
Description:
Sets if to render the whole HTML content into a single PDF page.
Parameters:
value - Boolean value. Default is false.

public void setAuthentication(string username, string password)
Description:
Sets username and password credentials for NTLM authentication.
Parameters:
username - The username credential.
password - The password credential.
Note:
Only NTLM authentication is supported.

public void setAuthentication(string username, string password)
Description:
Sets username and password credentials for NTLM authentication.
Parameters:
username - The username credential.
password - The password credential.
Note:
Only NTLM authentication is supported.

public void setStandard(string standard)
Description:
Sets the standard of the resultant PDF document.
Parameters:
standard - The standard of the resultant PDF document. The values are available in RunPDF.Constants (Example: Constants.STANDARD_PDF_A;). Default format is STANDARD_PDF.

public void avoidImageBrake(boolean value)
Description:
Sets if to avoid image break between pages.
Parameters:
value - Boolean value. Default is false.

public void enableLinks(boolean value)
Description:
Sets if to enable hyper links on the resultant PDF document.
Parameters:
value - Boolean value. Default is false.

public void setFormat(string format)
Description:
Sets the format of the document pages.
Parameters:
format - The format of the document pages. The values are available in RunPDF.Constants (Example: Constants.FORMAT_A0;). Default format is FORMAT_A4 - "A4".

public void setOrientation(string orientation)
Description:
Sets the orientation of the document pages.
Parameters:
orientation - The orientation of the document pages. The values are available in RunPDF.Constants (Example: Constants.ORIENTATION_LANDSCAPE;). Default format is Constants.ORIENTATION_PORTRAIT.


public void setHeaderSourceHtml(string headerSourceHtml)
Description:
Sets the HTTP source for the header.
Parameters:
headerSourceHtml - The HTTP source for the header.

public void setFooterSourceUrl(string footerSourceUrl)
Description:
Sets the URL source for the footer.
Parameters:
footerSourceUrl - The URL source for the footer.

public void setHeaderSourceUrl(string headerSourceUrl)
Description:
Sets the URL source for the header.
Parameters:
headerSourceUrl - The URL source for the header.

public void setHeaderHeight(string headerHeight)
Description:
Sets the height of the header.
Parameters:
headerHeight - The height of the header.

public void setFooterHeight(string footerHeight)
Description:
Sets the height of the footer.
Parameters:
footerHeight - The height of the footer.

public void showPageNumberOnFooter(boolean value)
Description:
Sets if to show page number on the footer.
Parameters:
value - Boolean value. Default is false.

public void showSecondDocumentOnNewPage(boolean value)
Description:
Sets if to start contents of the second web page on new page of the document.
Parameters:
value - Boolean value. Default is false.

public void setOwnerPassword(string ownerPassword)
Description:
Sets password of the document owner.
Parameters:
ownerPassword - Password of the document owner.

public void setUserPassword(string userPassword)
Description:
Sets password of the document user.
Parameters:
userPassword - Password of the document user.

public void allowPrint(boolean value)
Description:
Sets if to allow the document user to print the document.
Parameters:
value - Boolean value. Default is true.

public void allowEdit(boolean value)
Description:
Sets if to allow the document user to edit the document.
Parameters:
value - Boolean value. Default is true.

public void allowCopy(boolean value)
Description:
Sets if to allow the document user to copy contents of the document.
Parameters:
value - Boolean value. Default is true.

public void setWatermarkImageUrl(string watermarkImageUrl)
Description:
Sets URI to the watermark image. PNG format only.
Parameters:
watermarkImageUrl - URI to the watermark image.

public void setWatermarkText(string watermarkText)
Description:
Sets the watermark text.
Parameters:
watermarkText - The text of the watermark.

public void setWatermarkOpacity(string watermarkOpacity)
Description:
Sets the watermark opacity.
Parameters:
watermarkOpacity - Opacity of the watarmark. A number between 0 and 100. Default is 50.

public void setWatermarkTextColor(string watermarkTextColor)
Description:
Sets the watermark text color.
Parameters:
watermarkTextColor - Color of the watermark text. A valid name of the color. Default is Gray.

public void setWatermarkTextFontSize (string watermarkTextFontSize)
Description:
Sets the size of the watarmark text font.
Parameters:
watermarkTextFontSize - Size of the watarmark text font. A number between 0 and 100. Default is 50.

public void setWatermarkTextPosition (string watermarkTextPosition)
Description:
Sets the watermark text position.
Parameters:
watermarkText - Position of the watermark. The values are available in RunPDF.Constants (Example: Constants.WM_TEXT_POSITION_DIAGONAL;). Default position is Constants.WM_TEXT_POSITION_HORIZONTAL.