{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":906,"path":"api-reference/server-api-reference/SVGToPDFConversionAPBothAPI.md","title":"SVGToPDFConversionAPI - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# SVGToPDFConversionAPI - Scoped, Global\n\nThe SVGToPDFConversionAPI provides methods that enable the adding of an SVG to a PDF and converting an SVG to PDF.\n\nThis API is part of the ServiceNow PDF Generation Utilities plugin \\(com.snc.apppdfgenerator\\) and is provided within the `sn_pdfgeneratorutils` namespace. The plugin is activated by default.\n\nSee also [PDFGenerationAPI](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/PDFGenerationAPIBothAPI.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## SVGToPDFConversionAPI - SVGToPDFConversionAPI\\(\\)\n\nInstantiates a new SVGToPDFConversionAPI object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| ||\n\nThe following examples shows how to create a SVGToPDFConversionAPI object.\n\n```\nvar v = new sn_pdfgeneratorutils.SVGToPDFConversionAPI();\n```\n\n## SVGToPDFConversionAPI - addSVGToPDF\\(String svg, String inputPdfSysId, String targetTable, String targetSysId, String nameForPdf, Number pageNo, Number x, Number y, Number svgImgWidth, Number svgImgHeight\\)\n\nAdds an SVG image to a PDF on a specified page with image size and location coordinates.\n\n<table id=\"table_gms_ycm_j4b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsvg\n\n</td><td>\n\nString\n\n</td><td>\n\nSVG to convert to a PDF document.\n\n</td></tr><tr><td>\n\ninputPdfSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the target PDF in which to create a copy of with an SVG. The target PDF is in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><tr><td>\n\ntargetTable\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the table containing the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><tr><td>\n\ntargetTableSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><tr><td>\n\ntargetTable\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the table on which to attach the converted PDF.\n\n</td></tr><tr><td>\n\ntargetTableSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the record on which to attach the converted PDF.\n\n</td></tr><tr><td>\n\npdfName\n\n</td><td>\n\nString\n\n</td><td>\n\nName to give the PDF.Default: Sys\\_id of the PDF in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><tr><td>\n\npageNo\n\n</td><td>\n\nNumber\n\n</td><td>\n\nPage number in the attached PDF on which to place the SVG.\n\n</td></tr><tr><td>\n\nx\n\n</td><td>\n\nNumber\n\n</td><td>\n\nHorizontal position of the SVG in the page. Value is in points.\n\n</td></tr><tr><td>\n\ny\n\n</td><td>\n\nNumber\n\n</td><td>\n\nVertical position of the SVG in the page. Value is in points.\n\n</td></tr><tr><td>\n\nsvgImgWidth\n\n</td><td>\n\nNumber\n\n</td><td>\n\nWidth of the SVG image in pixels.\n\n</td></tr><tr><td>\n\nsvgImgHeight\n\n</td><td>\n\nNumber\n\n</td><td>\n\nHeight of the SVG image in pixels.\n\n</td></tr></tbody>\n</table><table id=\"table_hms_ycm_j4b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr id=\"row_svg2PDF-return-svg_attach\"><td>\n\nObject\n\n</td><td>\n\nObject containing sys\\_id of a new PDF attachment with inserted SVG if successful, error message otherwise.```\n{\n  \"attachment_id\": \"String\",\n  \"message\": \"String\",\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.​attachment\\_id\n\n</td><td>\n\nIf SVG conversion is successful, sys\\_id of the attached PDF. The file is listed in the Attachments \\[sys\\_attachment\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage confirming success or error. Possible values:\n\n-   Adding SVG content to PDF failed.\n-   Adding SVG to PDF and creating new PDF is successful.\n-   Given target record \\[&lt;tableName&gt; - &lt;targetTableSysId&gt;\\] does not exist. – Target table sys\\_id is not in the table provided. Make sure you include the correct table name for the record.\n-   Input PDF attachment sys id to add the SVG content is null\n-   Input SVG content is empty or null\n-   PdfReader is not opened with owner password\n-   The target table name to attach the modified PDF : &lt;targetTable&gt; is empty or null\n-   The target table name to attach the modified PDF : &lt;targetTable&gt; is not valid\n\n Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus indicating whether the operation is successful.Possible values:\n\n-   success - Operation was successful.\n-   failure – Operation was not successful. The **message** provides details.\n\n Data type: String\n\n</td></tr></tbody>\n</table>The following example shows how get SVG from the description field of an incident record and add it to page 5 of a PDF attachment. The new PDF with SVG is located in the Attachments \\[sys\\_attachment\\] table.\n\n```\nvar gr = new GlideRecord(\"incident\");\n\nvar svg;\n\nif (gr.get(\"<tableSysId>\")) {\n svg = gr.description.toString();\n}\n\nvar result = new sn_pdfgeneratorutils.SVGToPDFConversionAPI().addSVGToPDF(svg, \"<inputPdfSysId>\", \"incident\", \"<tableSysId>\", \"AddSVGToPDF\", 5, 30, 30, 300, 100);\ngs.info(JSON.stringify(result));\n```\n\nOutput:\n\n```\n{\"attachment_id\":\"<sys_id>\",\"message\":\"Adding SVG to PDF and creating new PDF is successful.\",\"status\":\"success\"}\n```\n\n## SVGToPDFConversionAPI - convertSVGToPDF\\(String svg, String pdfName, String targetTable, String targetTableSysId\\)\n\nConverts an SVG provided as string to PDF.\n\n<table id=\"table_gms_ycm_j4b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsvg\n\n</td><td>\n\nString\n\n</td><td>\n\nSVG to convert to a PDF document.\n\n</td></tr><tr><td>\n\npdfName\n\n</td><td>\n\nString\n\n</td><td>\n\nName to give the PDF.Default: Sys\\_id of the PDF in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><tr><td>\n\ntargetTable\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the table on which to attach the converted PDF.\n\n</td></tr><tr><td>\n\ntargetTableSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the record on which to attach the converted PDF.\n\n</td></tr></tbody>\n</table><table id=\"table_hms_ycm_j4b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nObject containing sys\\_id of the PDF attachment converted from SVG if successful, error message otherwise.```\n{\n  \"attachment_id\": \"String\",\n  \"message\": \"String\",\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.​attachment\\_id\n\n</td><td>\n\nIf SVG conversion is successful, sys\\_id of the attached PDF. The file is listed in the Attachments \\[sys\\_attachment\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage confirming success or error. Possible values:\n\n-   Converting SVG image to PDF document failed.\n-   Exception while reading Source document contents.\n-   Given target record \\[&lt;tableName&gt; - &lt;targetTableSysId&gt;\\] does not exist. – Target table sys\\_id is not in the table provided. Make sure you include the correct table name for the record.\n-   SVG to PDF conversion is successful.\n-   The Target table name - &lt;tableName&gt; to attach the converted SVG is not valid\n-   The Target table name - &lt;tableName&gt; to attach the converted SVG is empty or null\n\n Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus indicating whether the operation is successful.Possible values:\n\n-   success - Operation was successful.\n-   failure – Operation was not successful. The **message** provides details.\n\n Data type: String\n\n</td></tr></tbody>\n</table>The following example shows how get SVG from the description field of an incident record, to convert the SVG to PDF and attach it to a record.\n\n```\nvar gr = new GlideRecord(\"incident\");\n\nvar svg;\n\nif (gr.get(\"<tableSysId>\")) {\n svg = gr.description.toString();\n}\n\nvar v = new sn_pdfgeneratorutils.SVGToPDFConversionAPI();\n\nvar result = v.convertSVGToPDF(svg, \"ConvertSVGToPDF\", \"incident\", \"<targetTableSysId>\");\ngs.info(JSON.stringify(result));\n```\n\nOutput:\n\n```\n{\"attachment_id\":\"<pdf_attachment_sys_id>\",\"message\":\"SVG to PDF conversion is successful.\",\"status\":\"success\"}\n```\n\n## SVGToPDFConversionAPI - convertSVGToPDFWithSize\\(String svg, String nameForPDF, String targetTable, String targetTableSysId, Number svgImgWidth, Number svgImgHeight\\)\n\nConverts an SVG provided as string to PDF with image width and height values.\n\n<table id=\"table_nqj_1dm_j4b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsvg\n\n</td><td>\n\nString\n\n</td><td>\n\nSVG to convert to a PDF document.\n\n</td></tr><tr><td>\n\npdfName\n\n</td><td>\n\nString\n\n</td><td>\n\nName to give the PDF.Default: Sys\\_id of the PDF in the Attachments \\[sys\\_attachment\\] table.\n\n</td></tr><tr><td>\n\ntargetTable\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the table on which to attach the converted PDF.\n\n</td></tr><tr><td>\n\ntargetTableSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the record on which to attach the converted PDF.\n\n</td></tr><tr><td>\n\nsvgImgWidth\n\n</td><td>\n\nNumber\n\n</td><td>\n\nWidth of the SVG image in pixels.\n\n</td></tr><tr><td>\n\nsvgImgHeight\n\n</td><td>\n\nNumber\n\n</td><td>\n\nHeight of the SVG image in pixels.\n\n</td></tr></tbody>\n</table><table id=\"table_hms_ycm_j4b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nObject containing sys\\_id of the PDF attachment converted from SVG if successful, error message otherwise.```\n{\n  \"attachment_id\": \"String\",\n  \"message\": \"String\",\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.​attachment\\_id\n\n</td><td>\n\nIf SVG conversion is successful, sys\\_id of the attached PDF. The file is listed in the Attachments \\[sys\\_attachment\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage confirming success or error. Possible values:\n\n-   Converting SVG image to PDF document failed.\n-   Exception while reading Source document contents.\n-   Given target record \\[&lt;tableName&gt; - &lt;targetTableSysId&gt;\\] does not exist. – Target table sys\\_id is not in the table provided. Make sure you include the correct table name for the record.\n-   The Target table name - &lt;tableName&gt; to attach the converted SVG is not valid\n-   The Target table name - &lt;tableName&gt; to attach the converted SVG is empty or null\n-   SVG to PDF conversion is successful.\n\n Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus indicating whether the operation is successful.Possible values:\n\n-   success - Operation was successful.\n-   failure – Operation was not successful. The **message** provides details.\n\n Data type: String\n\n</td></tr></tbody>\n</table>The following example shows how get SVG from the description field of an incident record, to convert the SVG to PDF, and attach it to a record.\n\n```\nvar gr = new GlideRecord(\"incident\");\n\nvar svg;\n\nif (gr.get(\"<tableSysId>\")) {\n svg = gr.description.toString();\n}\n\nvar v = new sn_pdfgeneratorutils.SVGToPDFConversionAPI();\n\nvar result = v.convertSVGToPDFWithSize(svg, \"ConvertSVGToPDF\", \"incident\", \"<targetTableSysId>\", 600, 150);\ngs.info(JSON.stringify(result));\n```\n\nOutput:\n\n```\n{\"attachment_id\":\"<pdf_attachment_sys_id>\",\"message\":\"SVG to PDF conversion is successful.\",\"status\":\"success\"}\n```\n\n"}}