HtmlToPdfClient Class |
Namespace: SelectPdf.Api
The HtmlToPdfClient type exposes the following members.
Name | Description | |
---|---|---|
HtmlToPdfClient |
Construct the Html To Pdf Client.
|
Name | Description | |
---|---|---|
convertHtmlString(String) |
Convert the specified HTML string to PDF.
| |
convertHtmlString(String, String) |
Convert the specified HTML string to PDF. Use a base url to resolve relative paths to resources.
| |
convertHtmlStringAsync(String) |
Convert the specified HTML string to PDF with an asynchronous call.
| |
convertHtmlStringAsync(String, String) |
Convert the specified HTML string to PDF with an asynchronous call. Use a base url to resolve relative paths to resources.
| |
convertHtmlStringToFile(String, String) |
Convert the specified HTML string to PDF and writes the resulted PDF to a local file.
| |
convertHtmlStringToFile(String, String, String) |
Convert the specified HTML string to PDF and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.
| |
convertHtmlStringToFileAsync(String, String) |
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file.
| |
convertHtmlStringToFileAsync(String, String, String) |
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.
| |
convertHtmlStringToStream(String, Stream) |
Convert the specified HTML string to PDF and writes the resulted PDF to an output stream.
| |
convertHtmlStringToStream(String, String, Stream) |
Convert the specified HTML string to PDF and writes the resulted PDF to an output stream. Use a base url to resolve relative paths to resources.
| |
convertHtmlStringToStreamAsync(String, Stream) |
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream.
| |
convertHtmlStringToStreamAsync(String, String, Stream) |
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream. Use a base url to resolve relative paths to resources.
| |
convertUrl |
Convert the specified url to PDF.
| |
convertUrlAsync |
Convert the specified url to PDF using an asynchronous call.
| |
convertUrlToFile |
Convert the specified url to PDF and writes the resulted PDF to a local file.
| |
convertUrlToFileAsync |
Convert the specified url to PDF with an asynchronous call and writes the resulted PDF to a local file.
| |
convertUrlToStream |
Convert the specified url to PDF and writes the resulted PDF to an output stream.
| |
convertUrlToStreamAsync |
Convert the specified url to PDF with an asynchronous call and writes the resulted PDF to an output stream.
| |
getNumberOfPages |
Get the number of pages of the PDF document resulted from the API call.
| |
getWebElements |
Get the locations of certain web elements. This is retrieved if pdf_web_elements_selectors parameter is set and elements were found to match the selectors.
| |
setBackgroundColor |
Specify the background color of the PDF page in RGB html format. The default is #FFFFFF.
| |
setConversionDelay |
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load.
| |
setCookies |
Set HTTP cookies for the web page being converted.
| |
setCustomParameter |
Set a custom parameter. Do not use this method unless advised by SelectPdf.
| |
setDisableExternalLinks |
Do not create external links in the PDF. The default value is False and external links are created.
| |
setDisableInternalLinks |
Do not create internal links in the PDF. The default value is False and internal links are created.
| |
setDisableJavascript |
Do not run JavaScript in web pages. The default value is False and javascript is executed.
| |
setDocAddCreationDate |
Add the date and time when the PDF document was created to the PDF document information. The default value is False.
| |
setDocAuthor |
Set the name of the PDF document author.
| |
setDocKeywords |
Set the PDF document keywords.
| |
setDocSubject |
Set the subject of the PDF document.
| |
setDocTitle |
Set the PDF document title.
| |
setDrawHtmlBackground |
Set a flag indicating if the web page background is rendered in PDF. The default value is True.
| |
setFooterBaseUrl |
Set an optional base url parameter can be used together with the footer HTML to resolve relative paths from the html string.
| |
setFooterDisplayOnEvenPages |
Control the visibility of the footer on the even numbered pages of the generated pdf document. The default value is True.
| |
setFooterDisplayOnFirstPage |
Control the visibility of the footer on the first page of the generated pdf document. The default value is True.
| |
setFooterDisplayOnLastPage |
Add a special footer on the last page of the generated pdf document only. The default value is False.
| |
setFooterDisplayOnOddPages |
Control the visibility of the footer on the odd numbered pages of the generated pdf document. The default value is True.
| |
setFooterHeight |
The height of the pdf document footer. This height is specified in points. 1 point is 1/72 inch. The default value is 50.
| |
setFooterHtml |
Set the raw html that is converted and rendered in the pdf document footer.
| |
setFooterUrl |
Set the url of the web page that is converted and rendered in the PDF document footer.
| |
setFooterWebPageHeight |
Set the height in pixels used by the converter's internal browser window during the conversion of the footer content.
The default value is 0px and it means that the page height is automatically calculated by the converter.
| |
setFooterWebPageWidth |
Set the width in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 1024px.
| |
setHeaderBaseUrl |
Set an optional base url parameter can be used together with the header HTML to resolve relative paths from the html string.
| |
setHeaderDisplayOnEvenPages |
Control the visibility of the header on the even numbered pages of the generated pdf document. The default value is True.
| |
setHeaderDisplayOnFirstPage |
Control the visibility of the header on the first page of the generated pdf document. The default value is True.
| |
setHeaderDisplayOnOddPages |
Control the visibility of the header on the odd numbered pages of the generated pdf document. The default value is True.
| |
setHeaderHeight |
The height of the pdf document header. This height is specified in points. 1 point is 1/72 inch. The default value is 50.
| |
setHeaderHtml |
Set the raw html that is converted and rendered in the pdf document header.
| |
setHeaderUrl |
Set the url of the web page that is converted and rendered in the PDF document header.
| |
setHeaderWebPageHeight |
Set the height in pixels used by the converter's internal browser window during the conversion of the header content.
The default value is 0px and it means that the page height is automatically calculated by the converter.
| |
setHeaderWebPageWidth |
Set the width in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 1024px.
| |
setKeepImagesTogether |
Avoid breaking images between PDF pages. The default value is False and images are split between pages if larger.
| |
setMarginBottom |
Set bottom margin of the PDF pages. Default value is 5pt.
| |
setMarginLeft |
Set left margin of the PDF pages. Default value is 5pt.
| |
setMarginRight |
Set right margin of the PDF pages. Default value is 5pt.
| |
setMargins |
Set all margins of the PDF pages to the same value. Default value is 5pt.
| |
setMarginTop |
Set top margin of the PDF pages. Default value is 5pt.
| |
setMaxLoadTime |
Set the maximum amount of time (in seconds) that the converter will wait for the page to load.
| |
setMinLoadTime |
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load.
| |
setNavigationTimeout |
Set the maximum amount of time (in seconds) that the converter will wait for the page to load.
| |
setOwnerPassword |
Set PDF owner password.
| |
setPageBreaksEnhancedAlgorithm |
Get or set a flag indicating if an enhanced custom page breaks algorithm is used.
The enhanced algorithm is a little bit slower but it will prevent the appearance of hidden text in the PDF when custom page breaks are used.
The default value for this property is False.
| |
setPageHeight |
Set PDF page height in points. Default value is 842pt (A4 page height in points). 1pt = 1/72 inch.
| |
setPageNumbersAlignment |
Set the alignment of the page numbers text. The default value is PageNumbersAlignment.Right.
| |
setPageNumbersColor |
Specify the color of the page numbers text in #RRGGBB html format. The default value is #333333.
| |
setPageNumbersFirst |
Control the page number for the first page being rendered. The default value is 1.
| |
setPageNumbersFontName |
Set the font used to display the page numbers text. The default value is "Helvetica".
| |
setPageNumbersFontSize |
Set the size of the font used to display the page numbers. The default value is 10 points.
| |
setPageNumbersOffset |
Control the total number of pages offset in the generated pdf document. The default value is 0.
| |
setPageNumbersTemplate |
Set the text that is used to display the page numbers.
It can contain the placeholder {page_number} for the current page number and {total_pages} for the total number of pages.
The default value is "Page: {page_number} of {total_pages}".
| |
setPageNumbersVerticalPosition |
Specify the position in points on the vertical where the page numbers text is displayed in the footer. The default value is 10 points.
| |
setPageOrientation |
Set PDF page orientation. Default value is Portrait.
| |
setPageSize |
Set PDF page size. Default value is A4.
| |
setPageWidth |
Set PDF page width in points. Default value is 595pt (A4 page width in points). 1pt = 1/72 inch.
| |
setPdfBookmarksSelectors |
Generate automatic bookmarks in pdf. The elements that will be bookmarked are defined using CSS selectors.
For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and
the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.
| |
setPdfHideElements |
Exclude page elements from the conversion. The elements that will be excluded are defined using CSS selectors.
For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and
the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.
| |
setPdfName |
Specify the name of the pdf document that will be created. The default value is Document.pdf.
| |
setPdfShowOnlyElementID |
Convert only a specific section of the web page to pdf.
The section that will be converted to pdf is specified by the html element ID.
The element can be anything (image, table, table row, div, text, etc).
| |
setPdfWebElementsSelectors |
Get the locations of page elements from the conversion. The elements that will have their locations retrieved are defined using CSS selectors.
For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and
the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.
| |
setRenderingEngine |
Set the rendering engine used for the HTML to PDF conversion. Default value is WebKit.
| |
setRenderOnTimeout |
Try to render the PDF even in case of the web page loading timeout. The default value is False and an exception is raised in case of web page navigation timeout.
| |
setScaleImages |
Set a flag indicating if the images from the page are scaled during the conversion process. The default value is False and images are not scaled.
| |
setSecureProtocol |
Set the protocol used for secure (HTTPS) connections.
| |
setShowFooter |
Control if a custom footer is displayed in the generated PDF document. The default value is False.
| |
setShowHeader |
Control if a custom header is displayed in the generated PDF document. The default value is False.
| |
setShowPageNumbers |
Show page numbers. Default value is True.
| |
setSinglePagePdf |
Generate a single page PDF. The converter will automatically resize the PDF page to fit all the content in a single page.
The default value of this property is False and the PDF will contain several pages if the content is large.
| |
setSkipDecoding |
Internal use only.
| |
setStartupMode |
Set converter startup mode. The default value is StartupMode.Automatic and the conversion is started immediately.
| |
setUseCssPrint |
Specify if the CSS Print media type is used instead of the Screen media type. The default value is False.
| |
setUserPassword |
Set PDF user password.
| |
setViewerCenterWindow |
Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.
| |
setViewerDisplayDocTitle |
Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.
| |
setViewerFitWindow |
Set a flag specifying whether to resize the document's window to fit the size of the first displayed page. The default value is False.
| |
setViewerHideMenuBar |
Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.
| |
setViewerHideToolbar |
Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.
| |
setViewerHideWindowUI |
Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.
The default value is False.
| |
setViewerPageLayout |
Set the page layout to be used when the document is opened in a PDF viewer. The default value is PageLayout.OneColumn.
| |
setViewerPageMode |
Set the document page mode when the pdf document is opened in a PDF viewer. The default value is PageMode.UseNone.
| |
setWebPageHeight |
Set the height used by the converter's internal browser window in pixels. The default value is 0px and it means that the page height is automatically calculated by the converter.
| |
setWebPageWidth |
Set the width used by the converter's internal browser window in pixels. The default value is 1024px.
|
using System; using SelectPdf.Api; namespace SelectPdf.Api.Tests { class Program { static void Main(string[] args) { string url = "https://selectpdf.com"; string localFile = "Test.pdf"; string apiKey = "Your API key here"; Console.WriteLine("This is SelectPdf-{0}.", ApiClient.CLIENT_VERSION); try { HtmlToPdfClient client = new HtmlToPdfClient(apiKey); // set parameters - see full list at https://selectpdf.com/html-to-pdf-api/ client // main properties .setPageSize(PageSize.A4) // PDF page size .setPageOrientation(PageOrientation.Portrait) // PDF page orientation .setMargins(0) // PDF page margins .setRenderingEngine(RenderingEngine.WebKit) // rendering engine .setConversionDelay(1) // conversion delay .setNavigationTimeout(30) // navigation timeout .setShowPageNumbers(false) // page numbers .setPageBreaksEnhancedAlgorithm(true) // enhanced page break algorithm // additional properties // .setUseCssPrint(true) // enable CSS media print // .setDisableJavascript(true) // disable javascript // .setDisableInternalLinks(true) // disable internal links // .setDisableExternalLinks(true) // disable external links // .setKeepImagesTogether(true) // keep images together // .setScaleImages(true) // scale images to create smaller pdfs // .setSinglePagePdf(true) // generate a single page PDF // .setUserPassword("password") // secure the PDF with a password // generate automatic bookmarks // .setPdfBookmarksSelectors("H1, H2") // create outlines (bookmarks) for the specified elements // .setViewerPageMode(PageMode.UseOutlines) // display outlines (bookmarks) in viewer ; Console.WriteLine("Starting conversion ..."); // convert url to file client.convertUrlToFile(url, localFile); // convert url to memory // byte[] pdf = client.convertUrl(url); // convert html string to file // client.convertHtmlStringToFile("This is some <b>html</b>.", localFile); // convert html string to memory // byte[] pdf = client.convertHtmlString("This is some <b>html</b>."); Console.WriteLine("Finished! Number of pages: {0}.", client.getNumberOfPages()); // get API usage UsageClient usageClient = new UsageClient(apiKey); UsageInformation usage = usageClient.getUsage(false); Console.WriteLine("Conversions remained this month: {0}.", usage.Available); } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } } }