[{"data":1,"prerenderedAt":3140},["Reactive",2],{"/guides/java/retrofit":3},[4,68,106,144,180,218,255,291,328,366,403,440,475,513,549,585,621,659,695,732,768,804,844,876,908,940,972,1004,1036,1068,1100,1132,1164,1196,1228,1260,1292,1324,1356,1388,1420,1452,1484,1524,1556,1588,1620,1652,1684,1716,1748,1780,1812,1844,1876,1908,1940,1972,2004,2036,2068,2100,2132,2164,2204,2236,2268,2300,2332,2364,2396,2428,2460,2492,2524,2556,2588,2620,2652,2684,2716,2748,2780,2812,2844,2884,2916,2948,2980,3012,3044,3076,3108],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"language":11,"library":12,"property":13,"output":14,"related":15,"default":18,"body":19,"_type":63,"_id":64,"_source":65,"_file":66,"_extension":67},"/guides/java/httpclient/accessing-secured-pages","httpclient",false,"","Accessing secured pages","Learn how to access secured pages using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, highlighting how you can access page protected by basic authentication to convert them to PDF using PDFShift's API.","Java","HttpClient","auth","pdf",[16,17],"send-custom-http-headers","using-cookies",true,{"type":20,"children":21,"toc":60},"root",[22,30,43,55],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27],{"type":28,"value":29},"text","In this guide, we'll show you how to access secured page (protected by basic authentication) using Java and the HttpClient library to convert them to PDF using PDFShift's API.",{"type":23,"tag":24,"props":31,"children":32},{},[33,35,41],{"type":28,"value":34},"When you're converting a document, you might want to access a secured page (protected by basic authentication) to convert it to PDF. This can be done by setting the ",{"type":23,"tag":36,"props":37,"children":39},"code",{"className":38},[],[40],{"type":28,"value":13},{"type":28,"value":42}," parameter to the request.",{"type":23,"tag":44,"props":45,"children":50},"pre",{"className":46,"code":48,"language":49,"meta":8},[47],"language-java","import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"auth\\\": {\\n\" +\n        \"    \\\"username\\\": \\\"user\\\",\\n\" +\n        \"    \\\"password\\\": \\\"password\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n","java",[51],{"type":23,"tag":36,"props":52,"children":53},{"__ignoreMap":8},[54],{"type":28,"value":48},{"type":23,"tag":24,"props":56,"children":57},{},[58],{"type":28,"value":59},"This allows you to protect your documents from any visitors while allowing PDFShift to access the page and convert it to PDF.",{"title":8,"searchDepth":61,"depth":61,"links":62},2,[],"markdown","content:guides:java:httpclient:accessing-secured-pages.md","content","guides/java/httpclient/accessing-secured-pages.md","md",{"_path":69,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":70,"description":71,"language":11,"library":12,"property":72,"output":14,"related":73,"default":7,"body":76,"_type":63,"_id":104,"_source":65,"_file":105,"_extension":67},"/guides/java/httpclient/adding-a-custom-header-or-footer","Adding a custom header or footer","Learn how to add custom headers and footers to your PDFs using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to customize PDF appearance with headers and footers.","header",[74,75],"loading-css-from-a-string","loading-css-from-a-url",{"type":20,"children":77,"toc":102},[78,83,88,97],{"type":23,"tag":24,"props":79,"children":80},{},[81],{"type":28,"value":82},"In this guide, we'll show you how to add custom headers and footers to your PDFs using Java and the HttpClient library.",{"type":23,"tag":24,"props":84,"children":85},{},[86],{"type":28,"value":87},"When generating PDFs, you might want to add custom headers and footers to your documents for branding or informational purposes.",{"type":23,"tag":44,"props":89,"children":92},{"className":90,"code":91,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"header\\\": {\\n\" +\n        \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Header Content\u003C/div>\\\",\\n\" +\n        \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n        \"  },\\n\" +\n        \"  \\\"footer\\\": {\\n\" +\n        \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Footer Content\u003C/div>\\\",\\n\" +\n        \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[93],{"type":23,"tag":36,"props":94,"children":95},{"__ignoreMap":8},[96],{"type":28,"value":91},{"type":23,"tag":24,"props":98,"children":99},{},[100],{"type":28,"value":101},"This allows you to add consistent branding elements to all your generated PDF documents.",{"title":8,"searchDepth":61,"depth":61,"links":103},[],"content:guides:java:httpclient:adding-a-custom-header-or-footer.md","guides/java/httpclient/adding-a-custom-header-or-footer.md",{"_path":107,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":108,"description":109,"language":11,"library":12,"property":110,"output":14,"related":111,"default":7,"body":114,"_type":63,"_id":142,"_source":65,"_file":143,"_extension":67},"/guides/java/httpclient/adding-a-text-watermark","Adding a text watermark","Learn how to add text watermarks to your PDFs using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to apply text watermarks to protect your documents.","watermark",[112,113],"adding-an-image-watermark","protecting-the-generated-pdf",{"type":20,"children":115,"toc":140},[116,121,126,135],{"type":23,"tag":24,"props":117,"children":118},{},[119],{"type":28,"value":120},"In this guide, we'll show you how to add text watermarks to your PDFs using Java and the HttpClient library.",{"type":23,"tag":24,"props":122,"children":123},{},[124],{"type":28,"value":125},"When generating PDFs, you might want to add text watermarks to your documents for protection or branding purposes.",{"type":23,"tag":44,"props":127,"children":130},{"className":128,"code":129,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"watermark\\\": {\\n\" +\n        \"    \\\"text\\\": \\\"CONFIDENTIAL\\\",\\n\" +\n        \"    \\\"opacity\\\": 0.3,\\n\" +\n        \"    \\\"size\\\": \\\"20px\\\",\\n\" +\n        \"    \\\"color\\\": \\\"#000000\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[131],{"type":23,"tag":36,"props":132,"children":133},{"__ignoreMap":8},[134],{"type":28,"value":129},{"type":23,"tag":24,"props":136,"children":137},{},[138],{"type":28,"value":139},"This allows you to add textual protection to your documents with customizable text.",{"title":8,"searchDepth":61,"depth":61,"links":141},[],"content:guides:java:httpclient:adding-a-text-watermark.md","guides/java/httpclient/adding-a-text-watermark.md",{"_path":145,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":146,"description":147,"language":11,"library":12,"property":110,"output":14,"related":148,"default":7,"body":150,"_type":63,"_id":178,"_source":65,"_file":179,"_extension":67},"/guides/java/httpclient/adding-an-image-watermark","Adding an image watermark","Learn how to add image watermarks to your PDFs using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to apply image watermarks to protect your documents.",[149,113],"adding-a-text-watermark",{"type":20,"children":151,"toc":176},[152,157,162,171],{"type":23,"tag":24,"props":153,"children":154},{},[155],{"type":28,"value":156},"In this guide, we'll show you how to add image watermarks to your PDFs using Java and the HttpClient library.",{"type":23,"tag":24,"props":158,"children":159},{},[160],{"type":28,"value":161},"When generating PDFs, you might want to add image watermarks to your documents for protection or branding purposes.",{"type":23,"tag":44,"props":163,"children":166},{"className":164,"code":165,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"watermark\\\": {\\n\" +\n        \"    \\\"image\\\": \\\"https://example.com/watermark.png\\\",\\n\" +\n        \"    \\\"opacity\\\": 0.5,\\n\" +\n        \"    \\\"position\\\": \\\"center\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[167],{"type":23,"tag":36,"props":168,"children":169},{"__ignoreMap":8},[170],{"type":28,"value":165},{"type":23,"tag":24,"props":172,"children":173},{},[174],{"type":28,"value":175},"This allows you to add visual protection to your documents with custom images.",{"title":8,"searchDepth":61,"depth":61,"links":177},[],"content:guides:java:httpclient:adding-an-image-watermark.md","guides/java/httpclient/adding-an-image-watermark.md",{"_path":181,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":182,"description":183,"language":11,"library":12,"property":184,"output":14,"related":185,"default":7,"body":188,"_type":63,"_id":216,"_source":65,"_file":217,"_extension":67},"/guides/java/httpclient/avoid-conversion-on-error","Avoid conversion on error","Learn how to avoid conversion on error using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to handle conversion errors gracefully.","continue_on_error",[186,187],"define-a-time-limit","receive-a-webhook-event",{"type":20,"children":189,"toc":214},[190,195,200,209],{"type":23,"tag":24,"props":191,"children":192},{},[193],{"type":28,"value":194},"In this guide, we'll show you how to avoid conversion on error using Java and the HttpClient library.",{"type":23,"tag":24,"props":196,"children":197},{},[198],{"type":28,"value":199},"When converting documents to PDF, you might want to prevent conversion if certain errors occur to avoid generating invalid PDFs.",{"type":23,"tag":44,"props":201,"children":204},{"className":202,"code":203,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"continue_on_error\\\": false\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[205],{"type":23,"tag":36,"props":206,"children":207},{"__ignoreMap":8},[208],{"type":28,"value":203},{"type":23,"tag":24,"props":210,"children":211},{},[212],{"type":28,"value":213},"This allows you to fail fast when conversion issues occur.",{"title":8,"searchDepth":61,"depth":61,"links":215},[],"content:guides:java:httpclient:avoid-conversion-on-error.md","guides/java/httpclient/avoid-conversion-on-error.md",{"_path":219,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":220,"description":221,"language":11,"library":12,"property":222,"output":14,"related":223,"default":18,"body":225,"_type":63,"_id":253,"_source":65,"_file":254,"_extension":67},"/guides/java/httpclient/convert-html-to-pdf-from-a-url","Convert HTML to PDF from a URL","Learn how to convert HTML from a URL to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to convert online HTML content to PDF.","source",[224,75],"convert-html-to-pdf-from-raw-html",{"type":20,"children":226,"toc":251},[227,232,237,246],{"type":23,"tag":24,"props":228,"children":229},{},[230],{"type":28,"value":231},"In this guide, we'll show you how to convert HTML from a URL to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":233,"children":234},{},[235],{"type":28,"value":236},"Converting HTML from a URL to PDF is a common requirement when you want to generate PDFs from existing web content.",{"type":23,"tag":44,"props":238,"children":241},{"className":239,"code":240,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[242],{"type":23,"tag":36,"props":243,"children":244},{"__ignoreMap":8},[245],{"type":28,"value":240},{"type":23,"tag":24,"props":247,"children":248},{},[249],{"type":28,"value":250},"This allows you to easily convert any webpage to a PDF document.",{"title":8,"searchDepth":61,"depth":61,"links":252},[],"content:guides:java:httpclient:convert-html-to-pdf-from-a-url.md","guides/java/httpclient/convert-html-to-pdf-from-a-url.md",{"_path":256,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":257,"description":258,"language":11,"library":12,"property":222,"output":14,"related":259,"default":18,"body":261,"_type":63,"_id":289,"_source":65,"_file":290,"_extension":67},"/guides/java/httpclient/convert-html-to-pdf-from-raw-html","Convert HTML to PDF from raw HTML","Learn how to convert raw HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to convert HTML content directly to PDF.",[260,74],"convert-html-to-pdf-from-a-url",{"type":20,"children":262,"toc":287},[263,268,273,282],{"type":23,"tag":24,"props":264,"children":265},{},[266],{"type":28,"value":267},"In this guide, we'll show you how to convert raw HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":269,"children":270},{},[271],{"type":28,"value":272},"Converting raw HTML content to PDF is useful when you have HTML content that isn't hosted on a web server.",{"type":23,"tag":44,"props":274,"children":277},{"className":275,"code":276,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"\u003Chtml>\u003Cbody>\u003Ch1>Hello World\u003C/h1>\u003C/body>\u003C/html>\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[278],{"type":23,"tag":36,"props":279,"children":280},{"__ignoreMap":8},[281],{"type":28,"value":276},{"type":23,"tag":24,"props":283,"children":284},{},[285],{"type":28,"value":286},"This allows you to convert HTML content directly to PDF without needing a URL.",{"title":8,"searchDepth":61,"depth":61,"links":288},[],"content:guides:java:httpclient:convert-html-to-pdf-from-raw-html.md","guides/java/httpclient/convert-html-to-pdf-from-raw-html.md",{"_path":292,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":293,"description":294,"language":11,"library":12,"property":295,"output":14,"related":296,"default":7,"body":298,"_type":63,"_id":326,"_source":65,"_file":327,"_extension":67},"/guides/java/httpclient/define-a-time-limit","Define a time limit","Learn how to define a time limit for PDF conversions using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to set timeouts to prevent long-running conversions.","timeout",[297,186],"avoid-conversion-on-error",{"type":20,"children":299,"toc":324},[300,305,310,319],{"type":23,"tag":24,"props":301,"children":302},{},[303],{"type":28,"value":304},"In this guide, we'll show you how to define a time limit for PDF conversions using Java and the HttpClient library.",{"type":23,"tag":24,"props":306,"children":307},{},[308],{"type":28,"value":309},"When converting documents to PDF, you might want to set a timeout to prevent long-running conversions from blocking your application.",{"type":23,"tag":44,"props":311,"children":314},{"className":312,"code":313,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"timeout\\\": 30\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[315],{"type":23,"tag":36,"props":316,"children":317},{"__ignoreMap":8},[318],{"type":28,"value":313},{"type":23,"tag":24,"props":320,"children":321},{},[322],{"type":28,"value":323},"This allows you to control how long a conversion can take before timing out.",{"title":8,"searchDepth":61,"depth":61,"links":325},[],"content:guides:java:httpclient:define-a-time-limit.md","guides/java/httpclient/define-a-time-limit.md",{"_path":329,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":330,"description":331,"language":11,"library":12,"property":332,"output":14,"related":333,"default":7,"body":336,"_type":63,"_id":364,"_source":65,"_file":365,"_extension":67},"/guides/java/httpclient/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","Learn how to export only specific pages from a document when converting to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to select specific pages for export.","pages",[334,335],"generate-a-document-with-full-height","save-your-pdf-online-and-get-back-a-url",{"type":20,"children":337,"toc":362},[338,343,348,357],{"type":23,"tag":24,"props":339,"children":340},{},[341],{"type":28,"value":342},"In this guide, we'll show you how to export only specific pages from a document when converting to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":344,"children":345},{},[346],{"type":28,"value":347},"When converting documents, you might want to export only a specific range of pages rather than the entire document.",{"type":23,"tag":44,"props":349,"children":352},{"className":350,"code":351,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"pages\\\": \\\"1-3\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[353],{"type":23,"tag":36,"props":354,"children":355},{"__ignoreMap":8},[356],{"type":28,"value":351},{"type":23,"tag":24,"props":358,"children":359},{},[360],{"type":28,"value":361},"This allows you to selectively export pages from multi-page documents.",{"title":8,"searchDepth":61,"depth":61,"links":363},[],"content:guides:java:httpclient:exporting-only-a-specific-set-of-pages.md","guides/java/httpclient/exporting-only-a-specific-set-of-pages.md",{"_path":367,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":368,"description":369,"language":11,"library":12,"property":370,"output":14,"related":371,"default":7,"body":373,"_type":63,"_id":401,"_source":65,"_file":402,"_extension":67},"/guides/java/httpclient/generate-a-document-with-full-height","Generate a document with full height","Learn how to generate a document with full height using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to create full-height PDFs.","full_height",[372,335],"exporting-only-a-specific-set-of-pages",{"type":20,"children":374,"toc":399},[375,380,385,394],{"type":23,"tag":24,"props":376,"children":377},{},[378],{"type":28,"value":379},"In this guide, we'll show you how to generate a document with full height using Java and the HttpClient library.",{"type":23,"tag":24,"props":381,"children":382},{},[383],{"type":28,"value":384},"When converting documents to PDF, you might want to ensure the entire document height is preserved.",{"type":23,"tag":44,"props":386,"children":389},{"className":387,"code":388,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"full_height\\\": true\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[390],{"type":23,"tag":36,"props":391,"children":392},{"__ignoreMap":8},[393],{"type":28,"value":388},{"type":23,"tag":24,"props":395,"children":396},{},[397],{"type":28,"value":398},"This ensures the entire document content is included in the PDF.",{"title":8,"searchDepth":61,"depth":61,"links":400},[],"content:guides:java:httpclient:generate-a-document-with-full-height.md","guides/java/httpclient/generate-a-document-with-full-height.md",{"_path":404,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":405,"description":406,"language":11,"library":12,"property":407,"output":14,"related":408,"default":7,"body":410,"_type":63,"_id":438,"_source":65,"_file":439,"_extension":67},"/guides/java/httpclient/loading-css-from-a-string","Loading CSS from a string","Learn how to load CSS from a string when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to apply inline CSS styling.","css",[75,409],"adding-a-custom-header-or-footer",{"type":20,"children":411,"toc":436},[412,417,422,431],{"type":23,"tag":24,"props":413,"children":414},{},[415],{"type":28,"value":416},"In this guide, we'll show you how to load CSS from a string when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":418,"children":419},{},[420],{"type":28,"value":421},"When converting HTML to PDF, you might want to apply CSS styling using inline CSS rather than external stylesheets.",{"type":23,"tag":44,"props":423,"children":426},{"className":424,"code":425,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"css\\\": \\\"body { font-family: Arial; } h1 { color: blue; }\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[427],{"type":23,"tag":36,"props":428,"children":429},{"__ignoreMap":8},[430],{"type":28,"value":425},{"type":23,"tag":24,"props":432,"children":433},{},[434],{"type":28,"value":435},"This allows you to apply custom styling directly to your PDFs.",{"title":8,"searchDepth":61,"depth":61,"links":437},[],"content:guides:java:httpclient:loading-css-from-a-string.md","guides/java/httpclient/loading-css-from-a-string.md",{"_path":441,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":442,"description":443,"language":11,"library":12,"property":407,"output":14,"related":444,"default":7,"body":445,"_type":63,"_id":473,"_source":65,"_file":474,"_extension":67},"/guides/java/httpclient/loading-css-from-a-url","Loading CSS from a URL","Learn how to load CSS from a URL when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to reference external CSS files.",[74,260],{"type":20,"children":446,"toc":471},[447,452,457,466],{"type":23,"tag":24,"props":448,"children":449},{},[450],{"type":28,"value":451},"In this guide, we'll show you how to load CSS from a URL when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":453,"children":454},{},[455],{"type":28,"value":456},"When converting HTML to PDF, you might want to reference external CSS files to maintain consistent styling.",{"type":23,"tag":44,"props":458,"children":461},{"className":459,"code":460,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"css\\\": \\\"https://example.com/styles.css\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[462],{"type":23,"tag":36,"props":463,"children":464},{"__ignoreMap":8},[465],{"type":28,"value":460},{"type":23,"tag":24,"props":467,"children":468},{},[469],{"type":28,"value":470},"This allows you to apply external stylesheets to your PDFs.",{"title":8,"searchDepth":61,"depth":61,"links":472},[],"content:guides:java:httpclient:loading-css-from-a-url.md","guides/java/httpclient/loading-css-from-a-url.md",{"_path":476,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":477,"description":478,"language":11,"library":12,"property":479,"output":14,"related":480,"default":7,"body":483,"_type":63,"_id":511,"_source":65,"_file":512,"_extension":67},"/guides/java/httpclient/loading-javascript-from-a-string","Loading JavaScript from a string","Learn how to load JavaScript from a string when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to include inline JavaScript.","javascript",[481,482],"loading-javascript-from-a-url","waiting-for-a-custom-element-to-be-ready",{"type":20,"children":484,"toc":509},[485,490,495,504],{"type":23,"tag":24,"props":486,"children":487},{},[488],{"type":28,"value":489},"In this guide, we'll show you how to load JavaScript from a string when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":491,"children":492},{},[493],{"type":28,"value":494},"When converting HTML to PDF, you might want to include JavaScript functionality using inline code.",{"type":23,"tag":44,"props":496,"children":499},{"className":497,"code":498,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"javascript\\\": \\\"document.body.style.backgroundColor = 'red';\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[500],{"type":23,"tag":36,"props":501,"children":502},{"__ignoreMap":8},[503],{"type":28,"value":498},{"type":23,"tag":24,"props":505,"children":506},{},[507],{"type":28,"value":508},"This enables dynamic behavior in your PDFs.",{"title":8,"searchDepth":61,"depth":61,"links":510},[],"content:guides:java:httpclient:loading-javascript-from-a-string.md","guides/java/httpclient/loading-javascript-from-a-string.md",{"_path":514,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":515,"description":516,"language":11,"library":12,"property":479,"output":14,"related":517,"default":7,"body":519,"_type":63,"_id":547,"_source":65,"_file":548,"_extension":67},"/guides/java/httpclient/loading-javascript-from-a-url","Loading JavaScript from a URL","Learn how to load JavaScript from a URL when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to reference external JavaScript files.",[518,482],"loading-javascript-from-a-string",{"type":20,"children":520,"toc":545},[521,526,531,540],{"type":23,"tag":24,"props":522,"children":523},{},[524],{"type":28,"value":525},"In this guide, we'll show you how to load JavaScript from a URL when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":527,"children":528},{},[529],{"type":28,"value":530},"When converting HTML to PDF, you might want to reference external JavaScript files to include dynamic functionality.",{"type":23,"tag":44,"props":532,"children":535},{"className":533,"code":534,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"javascript\\\": \\\"https://example.com/script.js\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[536],{"type":23,"tag":36,"props":537,"children":538},{"__ignoreMap":8},[539],{"type":28,"value":534},{"type":23,"tag":24,"props":541,"children":542},{},[543],{"type":28,"value":544},"This allows you to include external JavaScript libraries in your PDFs.",{"title":8,"searchDepth":61,"depth":61,"links":546},[],"content:guides:java:httpclient:loading-javascript-from-a-url.md","guides/java/httpclient/loading-javascript-from-a-url.md",{"_path":550,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":551,"description":552,"language":11,"library":12,"property":553,"output":14,"related":554,"default":7,"body":555,"_type":63,"_id":583,"_source":65,"_file":584,"_extension":67},"/guides/java/httpclient/protecting-the-generated-pdf","Protecting the generated PDF","Learn how to protect generated PDFs with passwords using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to secure your PDF documents.","protection",[112,149],{"type":20,"children":556,"toc":581},[557,562,567,576],{"type":23,"tag":24,"props":558,"children":559},{},[560],{"type":28,"value":561},"In this guide, we'll show you how to protect generated PDFs with passwords using Java and the HttpClient library.",{"type":23,"tag":24,"props":563,"children":564},{},[565],{"type":28,"value":566},"When generating PDFs, you might want to add password protection to restrict access.",{"type":23,"tag":44,"props":568,"children":571},{"className":569,"code":570,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"protection\\\": {\\n\" +\n        \"    \\\"user_password\\\": \\\"user123\\\",\\n\" +\n        \"    \\\"owner_password\\\": \\\"owner123\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[572],{"type":23,"tag":36,"props":573,"children":574},{"__ignoreMap":8},[575],{"type":28,"value":570},{"type":23,"tag":24,"props":577,"children":578},{},[579],{"type":28,"value":580},"This allows you to secure your PDF documents with passwords.",{"title":8,"searchDepth":61,"depth":61,"links":582},[],"content:guides:java:httpclient:protecting-the-generated-pdf.md","guides/java/httpclient/protecting-the-generated-pdf.md",{"_path":586,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":587,"description":588,"language":11,"library":12,"property":589,"output":14,"related":590,"default":7,"body":591,"_type":63,"_id":619,"_source":65,"_file":620,"_extension":67},"/guides/java/httpclient/receive-a-webhook-event","Receive a webhook event","Learn how to receive webhook events when PDF conversion is complete using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to handle asynchronous conversion notifications.","webhook",[335,297],{"type":20,"children":592,"toc":617},[593,598,603,612],{"type":23,"tag":24,"props":594,"children":595},{},[596],{"type":28,"value":597},"In this guide, we'll show you how to receive webhook events when PDF conversion is complete using Java and the HttpClient library.",{"type":23,"tag":24,"props":599,"children":600},{},[601],{"type":28,"value":602},"When converting documents asynchronously, you might want to be notified when the conversion is complete via a webhook.",{"type":23,"tag":44,"props":604,"children":607},{"className":605,"code":606,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"webhook\\\": {\\n\" +\n        \"    \\\"url\\\": \\\"https://your-server.com/webhook\\\",\\n\" +\n        \"    \\\"secret\\\": \\\"your-secret-key\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[608],{"type":23,"tag":36,"props":609,"children":610},{"__ignoreMap":8},[611],{"type":28,"value":606},{"type":23,"tag":24,"props":613,"children":614},{},[615],{"type":28,"value":616},"This allows you to be notified when conversions are complete without polling.",{"title":8,"searchDepth":61,"depth":61,"links":618},[],"content:guides:java:httpclient:receive-a-webhook-event.md","guides/java/httpclient/receive-a-webhook-event.md",{"_path":622,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":623,"description":624,"language":11,"library":12,"property":625,"output":626,"related":627,"default":7,"body":629,"_type":63,"_id":657,"_source":65,"_file":658,"_extension":67},"/guides/java/httpclient/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","Learn how to save your PDF online and get back a URL using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to store PDFs in cloud storage and retrieve URLs.","output","url",[628,187],"save-your-pdf-to-your-amazon-s3-bucket",{"type":20,"children":630,"toc":655},[631,636,641,650],{"type":23,"tag":24,"props":632,"children":633},{},[634],{"type":28,"value":635},"In this guide, we'll show you how to save your PDF online and get back a URL using Java and the HttpClient library.",{"type":23,"tag":24,"props":637,"children":638},{},[639],{"type":28,"value":640},"When generating PDFs, you might want to store them in cloud storage and get a URL to access them later.",{"type":23,"tag":44,"props":642,"children":645},{"className":643,"code":644,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"output\\\": {\\n\" +\n        \"    \\\"type\\\": \\\"url\\\",\\n\" +\n        \"    \\\"url\\\": \\\"https://your-storage.com/\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[646],{"type":23,"tag":36,"props":647,"children":648},{"__ignoreMap":8},[649],{"type":28,"value":644},{"type":23,"tag":24,"props":651,"children":652},{},[653],{"type":28,"value":654},"This allows you to store PDFs in cloud storage and access them via URLs.",{"title":8,"searchDepth":61,"depth":61,"links":656},[],"content:guides:java:httpclient:save-your-pdf-online-and-get-back-a-url.md","guides/java/httpclient/save-your-pdf-online-and-get-back-a-url.md",{"_path":660,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":661,"description":662,"language":11,"library":12,"property":625,"output":663,"related":664,"default":7,"body":665,"_type":63,"_id":693,"_source":65,"_file":694,"_extension":67},"/guides/java/httpclient/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 bucket","Learn how to save your PDF to your Amazon S3 bucket using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to store PDFs directly in AWS S3.","s3",[335,187],{"type":20,"children":666,"toc":691},[667,672,677,686],{"type":23,"tag":24,"props":668,"children":669},{},[670],{"type":28,"value":671},"In this guide, we'll show you how to save your PDF to your Amazon S3 bucket using Java and the HttpClient library.",{"type":23,"tag":24,"props":673,"children":674},{},[675],{"type":28,"value":676},"When generating PDFs, you might want to store them directly in Amazon S3 for easy access and management.",{"type":23,"tag":44,"props":678,"children":681},{"className":679,"code":680,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"output\\\": {\\n\" +\n        \"    \\\"type\\\": \\\"s3\\\",\\n\" +\n        \"    \\\"bucket\\\": \\\"your-bucket-name\\\",\\n\" +\n        \"    \\\"key\\\": \\\"path/to/document.pdf\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[682],{"type":23,"tag":36,"props":683,"children":684},{"__ignoreMap":8},[685],{"type":28,"value":680},{"type":23,"tag":24,"props":687,"children":688},{},[689],{"type":28,"value":690},"This allows you to store PDFs directly in your AWS S3 buckets.",{"title":8,"searchDepth":61,"depth":61,"links":692},[],"content:guides:java:httpclient:save-your-pdf-to-your-amazon-s3-bucket.md","guides/java/httpclient/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":696,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":697,"description":698,"language":11,"library":12,"property":699,"output":14,"related":700,"default":7,"body":702,"_type":63,"_id":730,"_source":65,"_file":731,"_extension":67},"/guides/java/httpclient/send-custom-http-headers","Send custom HTTP headers","Learn how to send custom HTTP headers when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to customize request headers.","headers",[701,17],"accessing-secured-pages",{"type":20,"children":703,"toc":728},[704,709,714,723],{"type":23,"tag":24,"props":705,"children":706},{},[707],{"type":28,"value":708},"In this guide, we'll show you how to send custom HTTP headers when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":710,"children":711},{},[712],{"type":28,"value":713},"When converting HTML to PDF, you might need to send custom HTTP headers to access protected resources or provide additional information.",{"type":23,"tag":44,"props":715,"children":718},{"className":716,"code":717,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"headers\\\": {\\n\" +\n        \"    \\\"authorization\\\": \\\"Bearer token123\\\",\\n\" +\n        \"    \\\"user-agent\\\": \\\"MyApp/1.0\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[719],{"type":23,"tag":36,"props":720,"children":721},{"__ignoreMap":8},[722],{"type":28,"value":717},{"type":23,"tag":24,"props":724,"children":725},{},[726],{"type":28,"value":727},"This allows you to customize the HTTP requests sent to the source URL.",{"title":8,"searchDepth":61,"depth":61,"links":729},[],"content:guides:java:httpclient:send-custom-http-headers.md","guides/java/httpclient/send-custom-http-headers.md",{"_path":733,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":734,"description":735,"language":11,"library":12,"property":736,"output":14,"related":737,"default":7,"body":738,"_type":63,"_id":766,"_source":65,"_file":767,"_extension":67},"/guides/java/httpclient/using-cookies","Using cookies","Learn how to use cookies when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to manage cookies during conversion.","cookies",[701,16],{"type":20,"children":739,"toc":764},[740,745,750,759],{"type":23,"tag":24,"props":741,"children":742},{},[743],{"type":28,"value":744},"In this guide, we'll show you how to use cookies when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":746,"children":747},{},[748],{"type":28,"value":749},"When converting HTML to PDF, you might need to send cookies to access authenticated content or maintain session state.",{"type":23,"tag":44,"props":751,"children":754},{"className":752,"code":753,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"cookies\\\": {\\n\" +\n        \"    \\\"sessionid\\\": \\\"abc123\\\",\\n\" +\n        \"    \\\"user\\\": \\\"john_doe\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[755],{"type":23,"tag":36,"props":756,"children":757},{"__ignoreMap":8},[758],{"type":28,"value":753},{"type":23,"tag":24,"props":760,"children":761},{},[762],{"type":28,"value":763},"This allows you to maintain session state when accessing protected content.",{"title":8,"searchDepth":61,"depth":61,"links":765},[],"content:guides:java:httpclient:using-cookies.md","guides/java/httpclient/using-cookies.md",{"_path":769,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":770,"description":771,"language":11,"library":12,"property":772,"output":14,"related":773,"default":7,"body":774,"_type":63,"_id":802,"_source":65,"_file":803,"_extension":67},"/guides/java/httpclient/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","Learn how to wait for a custom element to be ready when converting HTML to PDF using Java and the HttpClient library. This guide offers detailed steps with code samples in Java and the HttpClient library, showing how to handle dynamic content.","wait_for",[518,481],{"type":20,"children":775,"toc":800},[776,781,786,795],{"type":23,"tag":24,"props":777,"children":778},{},[779],{"type":28,"value":780},"In this guide, we'll show you how to wait for a custom element to be ready when converting HTML to PDF using Java and the HttpClient library.",{"type":23,"tag":24,"props":782,"children":783},{},[784],{"type":28,"value":785},"When converting HTML containing dynamic content, you might need to wait for specific elements to be rendered before generating the PDF.",{"type":23,"tag":44,"props":787,"children":790},{"className":788,"code":789,"language":49,"meta":8},[47],"import java.net.http.*;\nimport java.net.URI;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.time.Duration;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nHttpClient client = HttpClient.newBuilder()\n    .connectTimeout(Duration.ofSeconds(10))\n    .build();\n\nHttpRequest request = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.pdfshift.io/v3/convert/pdf\"))\n    .header(\"X-API-Key\", apiKey)\n    .header(\"Content-Type\", \"application/json\")\n    .POST(BodyPublishers.ofString(\"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"wait_for\\\": \\\"#dynamic-content.loaded\\\"\\n\" +\n        \"}\"))\n    .build();\n\nHttpResponse\u003Cbyte[]> response = client.send(request, BodyHandlers.ofByteArray());\n\n// Handle errors:\nif (response.statusCode() >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + response.statusCode());\n}\n\njava.nio.file.Files.write(java.nio.file.Paths.get(\"result.pdf\"), response.body());\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[791],{"type":23,"tag":36,"props":792,"children":793},{"__ignoreMap":8},[794],{"type":28,"value":789},{"type":23,"tag":24,"props":796,"children":797},{},[798],{"type":28,"value":799},"This allows you to ensure dynamic content is fully loaded before PDF generation.",{"title":8,"searchDepth":61,"depth":61,"links":801},[],"content:guides:java:httpclient:waiting-for-a-custom-element-to-be-ready.md","guides/java/httpclient/waiting-for-a-custom-element-to-be-ready.md",{"_path":805,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":807,"language":11,"library":808,"property":13,"output":14,"related":809,"default":18,"body":810,"_type":63,"_id":842,"_source":65,"_file":843,"_extension":67},"/guides/java/javanet/accessing-secured-pages","javanet","Learn how to access secured pages using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, highlighting how you can access page protected by basic authentication to convert them to PDF using PDFShift's API.","Java.net",[16,17],{"type":20,"children":811,"toc":840},[812,817,827,836],{"type":23,"tag":24,"props":813,"children":814},{},[815],{"type":28,"value":816},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Java and the Java.net library to convert them to PDF using PDFShift's API.",{"type":23,"tag":24,"props":818,"children":819},{},[820,821,826],{"type":28,"value":34},{"type":23,"tag":36,"props":822,"children":824},{"className":823},[],[825],{"type":28,"value":13},{"type":28,"value":42},{"type":23,"tag":44,"props":828,"children":831},{"className":829,"code":830,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"auth\\\": {\\n\" +\n    \"    \\\"username\\\": \\\"user\\\",\\n\" +\n    \"    \\\"password\\\": \\\"password\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[832],{"type":23,"tag":36,"props":833,"children":834},{"__ignoreMap":8},[835],{"type":28,"value":830},{"type":23,"tag":24,"props":837,"children":838},{},[839],{"type":28,"value":59},{"title":8,"searchDepth":61,"depth":61,"links":841},[],"content:guides:java:javanet:accessing-secured-pages.md","guides/java/javanet/accessing-secured-pages.md",{"_path":845,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":70,"description":846,"language":11,"library":808,"property":72,"output":14,"related":847,"default":7,"body":848,"_type":63,"_id":874,"_source":65,"_file":875,"_extension":67},"/guides/java/javanet/adding-a-custom-header-or-footer","Learn how to add custom headers and footers to your PDFs using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to customize PDF appearance with headers and footers.",[74,75],{"type":20,"children":849,"toc":872},[850,855,859,868],{"type":23,"tag":24,"props":851,"children":852},{},[853],{"type":28,"value":854},"In this guide, we'll show you how to add custom headers and footers to your PDFs using Java and the Java.net library.",{"type":23,"tag":24,"props":856,"children":857},{},[858],{"type":28,"value":87},{"type":23,"tag":44,"props":860,"children":863},{"className":861,"code":862,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"header\\\": {\\n\" +\n    \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Header Content\u003C/div>\\\",\\n\" +\n    \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n    \"  },\\n\" +\n    \"  \\\"footer\\\": {\\n\" +\n    \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Footer Content\u003C/div>\\\",\\n\" +\n    \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[864],{"type":23,"tag":36,"props":865,"children":866},{"__ignoreMap":8},[867],{"type":28,"value":862},{"type":23,"tag":24,"props":869,"children":870},{},[871],{"type":28,"value":101},{"title":8,"searchDepth":61,"depth":61,"links":873},[],"content:guides:java:javanet:adding-a-custom-header-or-footer.md","guides/java/javanet/adding-a-custom-header-or-footer.md",{"_path":877,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":108,"description":878,"language":11,"library":808,"property":110,"output":14,"related":879,"default":7,"body":880,"_type":63,"_id":906,"_source":65,"_file":907,"_extension":67},"/guides/java/javanet/adding-a-text-watermark","Learn how to add text watermarks to your PDFs using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to apply text watermarks to protect your documents.",[112,113],{"type":20,"children":881,"toc":904},[882,887,891,900],{"type":23,"tag":24,"props":883,"children":884},{},[885],{"type":28,"value":886},"In this guide, we'll show you how to add text watermarks to your PDFs using Java and the Java.net library.",{"type":23,"tag":24,"props":888,"children":889},{},[890],{"type":28,"value":125},{"type":23,"tag":44,"props":892,"children":895},{"className":893,"code":894,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"watermark\\\": {\\n\" +\n    \"    \\\"text\\\": \\\"CONFIDENTIAL\\\",\\n\" +\n    \"    \\\"opacity\\\": 0.3,\\n\" +\n    \"    \\\"size\\\": \\\"20px\\\",\\n\" +\n    \"    \\\"color\\\": \\\"#000000\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[896],{"type":23,"tag":36,"props":897,"children":898},{"__ignoreMap":8},[899],{"type":28,"value":894},{"type":23,"tag":24,"props":901,"children":902},{},[903],{"type":28,"value":139},{"title":8,"searchDepth":61,"depth":61,"links":905},[],"content:guides:java:javanet:adding-a-text-watermark.md","guides/java/javanet/adding-a-text-watermark.md",{"_path":909,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":146,"description":910,"language":11,"library":808,"property":110,"output":14,"related":911,"default":7,"body":912,"_type":63,"_id":938,"_source":65,"_file":939,"_extension":67},"/guides/java/javanet/adding-an-image-watermark","Learn how to add image watermarks to your PDFs using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to apply image watermarks to protect your documents.",[149,113],{"type":20,"children":913,"toc":936},[914,919,923,932],{"type":23,"tag":24,"props":915,"children":916},{},[917],{"type":28,"value":918},"In this guide, we'll show you how to add image watermarks to your PDFs using Java and the Java.net library.",{"type":23,"tag":24,"props":920,"children":921},{},[922],{"type":28,"value":161},{"type":23,"tag":44,"props":924,"children":927},{"className":925,"code":926,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"watermark\\\": {\\n\" +\n    \"    \\\"image\\\": \\\"https://example.com/watermark.png\\\",\\n\" +\n    \"    \\\"opacity\\\": 0.5,\\n\" +\n    \"    \\\"position\\\": \\\"center\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[928],{"type":23,"tag":36,"props":929,"children":930},{"__ignoreMap":8},[931],{"type":28,"value":926},{"type":23,"tag":24,"props":933,"children":934},{},[935],{"type":28,"value":175},{"title":8,"searchDepth":61,"depth":61,"links":937},[],"content:guides:java:javanet:adding-an-image-watermark.md","guides/java/javanet/adding-an-image-watermark.md",{"_path":941,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":182,"description":942,"language":11,"library":808,"property":184,"output":14,"related":943,"default":7,"body":944,"_type":63,"_id":970,"_source":65,"_file":971,"_extension":67},"/guides/java/javanet/avoid-conversion-on-error","Learn how to avoid conversion on error using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to handle conversion errors gracefully.",[186,187],{"type":20,"children":945,"toc":968},[946,951,955,964],{"type":23,"tag":24,"props":947,"children":948},{},[949],{"type":28,"value":950},"In this guide, we'll show you how to avoid conversion on error using Java and the Java.net library.",{"type":23,"tag":24,"props":952,"children":953},{},[954],{"type":28,"value":199},{"type":23,"tag":44,"props":956,"children":959},{"className":957,"code":958,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"continue_on_error\\\": false\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[960],{"type":23,"tag":36,"props":961,"children":962},{"__ignoreMap":8},[963],{"type":28,"value":958},{"type":23,"tag":24,"props":965,"children":966},{},[967],{"type":28,"value":213},{"title":8,"searchDepth":61,"depth":61,"links":969},[],"content:guides:java:javanet:avoid-conversion-on-error.md","guides/java/javanet/avoid-conversion-on-error.md",{"_path":973,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":220,"description":974,"language":11,"library":808,"property":222,"output":14,"related":975,"default":18,"body":976,"_type":63,"_id":1002,"_source":65,"_file":1003,"_extension":67},"/guides/java/javanet/convert-html-to-pdf-from-a-url","Learn how to convert HTML from a URL to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to convert online HTML content to PDF.",[224,75],{"type":20,"children":977,"toc":1000},[978,983,987,996],{"type":23,"tag":24,"props":979,"children":980},{},[981],{"type":28,"value":982},"In this guide, we'll show you how to convert HTML from a URL to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":984,"children":985},{},[986],{"type":28,"value":236},{"type":23,"tag":44,"props":988,"children":991},{"className":989,"code":990,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[992],{"type":23,"tag":36,"props":993,"children":994},{"__ignoreMap":8},[995],{"type":28,"value":990},{"type":23,"tag":24,"props":997,"children":998},{},[999],{"type":28,"value":250},{"title":8,"searchDepth":61,"depth":61,"links":1001},[],"content:guides:java:javanet:convert-html-to-pdf-from-a-url.md","guides/java/javanet/convert-html-to-pdf-from-a-url.md",{"_path":1005,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":257,"description":1006,"language":11,"library":808,"property":222,"output":14,"related":1007,"default":18,"body":1008,"_type":63,"_id":1034,"_source":65,"_file":1035,"_extension":67},"/guides/java/javanet/convert-html-to-pdf-from-raw-html","Learn how to convert raw HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to convert HTML content directly to PDF.",[260,74],{"type":20,"children":1009,"toc":1032},[1010,1015,1019,1028],{"type":23,"tag":24,"props":1011,"children":1012},{},[1013],{"type":28,"value":1014},"In this guide, we'll show you how to convert raw HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1016,"children":1017},{},[1018],{"type":28,"value":272},{"type":23,"tag":44,"props":1020,"children":1023},{"className":1021,"code":1022,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"\u003Chtml>\u003Cbody>\u003Ch1>Hello World\u003C/h1>\u003C/body>\u003C/html>\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1024],{"type":23,"tag":36,"props":1025,"children":1026},{"__ignoreMap":8},[1027],{"type":28,"value":1022},{"type":23,"tag":24,"props":1029,"children":1030},{},[1031],{"type":28,"value":286},{"title":8,"searchDepth":61,"depth":61,"links":1033},[],"content:guides:java:javanet:convert-html-to-pdf-from-raw-html.md","guides/java/javanet/convert-html-to-pdf-from-raw-html.md",{"_path":1037,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":293,"description":1038,"language":11,"library":808,"property":295,"output":14,"related":1039,"default":7,"body":1040,"_type":63,"_id":1066,"_source":65,"_file":1067,"_extension":67},"/guides/java/javanet/define-a-time-limit","Learn how to define a time limit for PDF conversions using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to set timeouts to prevent long-running conversions.",[297,186],{"type":20,"children":1041,"toc":1064},[1042,1047,1051,1060],{"type":23,"tag":24,"props":1043,"children":1044},{},[1045],{"type":28,"value":1046},"In this guide, we'll show you how to define a time limit for PDF conversions using Java and the Java.net library.",{"type":23,"tag":24,"props":1048,"children":1049},{},[1050],{"type":28,"value":309},{"type":23,"tag":44,"props":1052,"children":1055},{"className":1053,"code":1054,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n// Set a timeout in milliseconds\nconnection.setConnectTimeout(30000);\nconnection.setReadTimeout(30000);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"timeout\\\": 30\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1056],{"type":23,"tag":36,"props":1057,"children":1058},{"__ignoreMap":8},[1059],{"type":28,"value":1054},{"type":23,"tag":24,"props":1061,"children":1062},{},[1063],{"type":28,"value":323},{"title":8,"searchDepth":61,"depth":61,"links":1065},[],"content:guides:java:javanet:define-a-time-limit.md","guides/java/javanet/define-a-time-limit.md",{"_path":1069,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":330,"description":1070,"language":11,"library":808,"property":332,"output":14,"related":1071,"default":7,"body":1072,"_type":63,"_id":1098,"_source":65,"_file":1099,"_extension":67},"/guides/java/javanet/exporting-only-a-specific-set-of-pages","Learn how to export only specific pages from a document when converting to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to select specific pages for export.",[334,335],{"type":20,"children":1073,"toc":1096},[1074,1079,1083,1092],{"type":23,"tag":24,"props":1075,"children":1076},{},[1077],{"type":28,"value":1078},"In this guide, we'll show you how to export only specific pages from a document when converting to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1080,"children":1081},{},[1082],{"type":28,"value":347},{"type":23,"tag":44,"props":1084,"children":1087},{"className":1085,"code":1086,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"pages\\\": \\\"1-3\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1088],{"type":23,"tag":36,"props":1089,"children":1090},{"__ignoreMap":8},[1091],{"type":28,"value":1086},{"type":23,"tag":24,"props":1093,"children":1094},{},[1095],{"type":28,"value":361},{"title":8,"searchDepth":61,"depth":61,"links":1097},[],"content:guides:java:javanet:exporting-only-a-specific-set-of-pages.md","guides/java/javanet/exporting-only-a-specific-set-of-pages.md",{"_path":1101,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":368,"description":1102,"language":11,"library":808,"property":370,"output":14,"related":1103,"default":7,"body":1104,"_type":63,"_id":1130,"_source":65,"_file":1131,"_extension":67},"/guides/java/javanet/generate-a-document-with-full-height","Learn how to generate a document with full height using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to create full-height PDFs.",[372,335],{"type":20,"children":1105,"toc":1128},[1106,1111,1115,1124],{"type":23,"tag":24,"props":1107,"children":1108},{},[1109],{"type":28,"value":1110},"In this guide, we'll show you how to generate a document with full height using Java and the Java.net library.",{"type":23,"tag":24,"props":1112,"children":1113},{},[1114],{"type":28,"value":384},{"type":23,"tag":44,"props":1116,"children":1119},{"className":1117,"code":1118,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"full_height\\\": true\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1120],{"type":23,"tag":36,"props":1121,"children":1122},{"__ignoreMap":8},[1123],{"type":28,"value":1118},{"type":23,"tag":24,"props":1125,"children":1126},{},[1127],{"type":28,"value":398},{"title":8,"searchDepth":61,"depth":61,"links":1129},[],"content:guides:java:javanet:generate-a-document-with-full-height.md","guides/java/javanet/generate-a-document-with-full-height.md",{"_path":1133,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":405,"description":1134,"language":11,"library":808,"property":407,"output":14,"related":1135,"default":7,"body":1136,"_type":63,"_id":1162,"_source":65,"_file":1163,"_extension":67},"/guides/java/javanet/loading-css-from-a-string","Learn how to load CSS from a string when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to apply inline CSS styling.",[75,409],{"type":20,"children":1137,"toc":1160},[1138,1143,1147,1156],{"type":23,"tag":24,"props":1139,"children":1140},{},[1141],{"type":28,"value":1142},"In this guide, we'll show you how to load CSS from a string when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1144,"children":1145},{},[1146],{"type":28,"value":421},{"type":23,"tag":44,"props":1148,"children":1151},{"className":1149,"code":1150,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"css\\\": \\\"body { font-family: Arial; } h1 { color: blue; }\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1152],{"type":23,"tag":36,"props":1153,"children":1154},{"__ignoreMap":8},[1155],{"type":28,"value":1150},{"type":23,"tag":24,"props":1157,"children":1158},{},[1159],{"type":28,"value":435},{"title":8,"searchDepth":61,"depth":61,"links":1161},[],"content:guides:java:javanet:loading-css-from-a-string.md","guides/java/javanet/loading-css-from-a-string.md",{"_path":1165,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":442,"description":1166,"language":11,"library":808,"property":407,"output":14,"related":1167,"default":7,"body":1168,"_type":63,"_id":1194,"_source":65,"_file":1195,"_extension":67},"/guides/java/javanet/loading-css-from-a-url","Learn how to load CSS from a URL when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to reference external CSS files.",[74,260],{"type":20,"children":1169,"toc":1192},[1170,1175,1179,1188],{"type":23,"tag":24,"props":1171,"children":1172},{},[1173],{"type":28,"value":1174},"In this guide, we'll show you how to load CSS from a URL when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1176,"children":1177},{},[1178],{"type":28,"value":456},{"type":23,"tag":44,"props":1180,"children":1183},{"className":1181,"code":1182,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"css\\\": \\\"https://example.com/styles.css\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1184],{"type":23,"tag":36,"props":1185,"children":1186},{"__ignoreMap":8},[1187],{"type":28,"value":1182},{"type":23,"tag":24,"props":1189,"children":1190},{},[1191],{"type":28,"value":470},{"title":8,"searchDepth":61,"depth":61,"links":1193},[],"content:guides:java:javanet:loading-css-from-a-url.md","guides/java/javanet/loading-css-from-a-url.md",{"_path":1197,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":477,"description":1198,"language":11,"library":808,"property":479,"output":14,"related":1199,"default":7,"body":1200,"_type":63,"_id":1226,"_source":65,"_file":1227,"_extension":67},"/guides/java/javanet/loading-javascript-from-a-string","Learn how to load JavaScript from a string when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to include inline JavaScript.",[481,482],{"type":20,"children":1201,"toc":1224},[1202,1207,1211,1220],{"type":23,"tag":24,"props":1203,"children":1204},{},[1205],{"type":28,"value":1206},"In this guide, we'll show you how to load JavaScript from a string when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1208,"children":1209},{},[1210],{"type":28,"value":494},{"type":23,"tag":44,"props":1212,"children":1215},{"className":1213,"code":1214,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"javascript\\\": \\\"document.body.style.backgroundColor = 'red';\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1216],{"type":23,"tag":36,"props":1217,"children":1218},{"__ignoreMap":8},[1219],{"type":28,"value":1214},{"type":23,"tag":24,"props":1221,"children":1222},{},[1223],{"type":28,"value":508},{"title":8,"searchDepth":61,"depth":61,"links":1225},[],"content:guides:java:javanet:loading-javascript-from-a-string.md","guides/java/javanet/loading-javascript-from-a-string.md",{"_path":1229,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":515,"description":1230,"language":11,"library":808,"property":479,"output":14,"related":1231,"default":7,"body":1232,"_type":63,"_id":1258,"_source":65,"_file":1259,"_extension":67},"/guides/java/javanet/loading-javascript-from-a-url","Learn how to load JavaScript from a URL when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to reference external JavaScript files.",[518,482],{"type":20,"children":1233,"toc":1256},[1234,1239,1243,1252],{"type":23,"tag":24,"props":1235,"children":1236},{},[1237],{"type":28,"value":1238},"In this guide, we'll show you how to load JavaScript from a URL when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1240,"children":1241},{},[1242],{"type":28,"value":530},{"type":23,"tag":44,"props":1244,"children":1247},{"className":1245,"code":1246,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"javascript\\\": \\\"https://example.com/script.js\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1248],{"type":23,"tag":36,"props":1249,"children":1250},{"__ignoreMap":8},[1251],{"type":28,"value":1246},{"type":23,"tag":24,"props":1253,"children":1254},{},[1255],{"type":28,"value":544},{"title":8,"searchDepth":61,"depth":61,"links":1257},[],"content:guides:java:javanet:loading-javascript-from-a-url.md","guides/java/javanet/loading-javascript-from-a-url.md",{"_path":1261,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":551,"description":1262,"language":11,"library":808,"property":553,"output":14,"related":1263,"default":7,"body":1264,"_type":63,"_id":1290,"_source":65,"_file":1291,"_extension":67},"/guides/java/javanet/protecting-the-generated-pdf","Learn how to protect generated PDFs with passwords using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to secure your PDF documents.",[112,149],{"type":20,"children":1265,"toc":1288},[1266,1271,1275,1284],{"type":23,"tag":24,"props":1267,"children":1268},{},[1269],{"type":28,"value":1270},"In this guide, we'll show you how to protect generated PDFs with passwords using Java and the Java.net library.",{"type":23,"tag":24,"props":1272,"children":1273},{},[1274],{"type":28,"value":566},{"type":23,"tag":44,"props":1276,"children":1279},{"className":1277,"code":1278,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"protection\\\": {\\n\" +\n    \"    \\\"user_password\\\": \\\"user123\\\",\\n\" +\n    \"    \\\"owner_password\\\": \\\"owner123\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1280],{"type":23,"tag":36,"props":1281,"children":1282},{"__ignoreMap":8},[1283],{"type":28,"value":1278},{"type":23,"tag":24,"props":1285,"children":1286},{},[1287],{"type":28,"value":580},{"title":8,"searchDepth":61,"depth":61,"links":1289},[],"content:guides:java:javanet:protecting-the-generated-pdf.md","guides/java/javanet/protecting-the-generated-pdf.md",{"_path":1293,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":587,"description":1294,"language":11,"library":808,"property":589,"output":14,"related":1295,"default":7,"body":1296,"_type":63,"_id":1322,"_source":65,"_file":1323,"_extension":67},"/guides/java/javanet/receive-a-webhook-event","Learn how to receive webhook events when PDF conversion is complete using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to handle asynchronous conversion notifications.",[335,297],{"type":20,"children":1297,"toc":1320},[1298,1303,1307,1316],{"type":23,"tag":24,"props":1299,"children":1300},{},[1301],{"type":28,"value":1302},"In this guide, we'll show you how to receive webhook events when PDF conversion is complete using Java and the Java.net library.",{"type":23,"tag":24,"props":1304,"children":1305},{},[1306],{"type":28,"value":602},{"type":23,"tag":44,"props":1308,"children":1311},{"className":1309,"code":1310,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"webhook\\\": {\\n\" +\n    \"    \\\"url\\\": \\\"https://your-server.com/webhook\\\",\\n\" +\n    \"    \\\"secret\\\": \\\"your-secret-key\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1312],{"type":23,"tag":36,"props":1313,"children":1314},{"__ignoreMap":8},[1315],{"type":28,"value":1310},{"type":23,"tag":24,"props":1317,"children":1318},{},[1319],{"type":28,"value":616},{"title":8,"searchDepth":61,"depth":61,"links":1321},[],"content:guides:java:javanet:receive-a-webhook-event.md","guides/java/javanet/receive-a-webhook-event.md",{"_path":1325,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":623,"description":1326,"language":11,"library":808,"property":625,"output":626,"related":1327,"default":7,"body":1328,"_type":63,"_id":1354,"_source":65,"_file":1355,"_extension":67},"/guides/java/javanet/save-your-pdf-online-and-get-back-a-url","Learn how to save your PDF online and get back a URL using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to store PDFs in cloud storage and retrieve URLs.",[628,187],{"type":20,"children":1329,"toc":1352},[1330,1335,1339,1348],{"type":23,"tag":24,"props":1331,"children":1332},{},[1333],{"type":28,"value":1334},"In this guide, we'll show you how to save your PDF online and get back a URL using Java and the Java.net library.",{"type":23,"tag":24,"props":1336,"children":1337},{},[1338],{"type":28,"value":640},{"type":23,"tag":44,"props":1340,"children":1343},{"className":1341,"code":1342,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"output\\\": {\\n\" +\n    \"    \\\"type\\\": \\\"url\\\",\\n\" +\n    \"    \\\"url\\\": \\\"https://your-storage.com/\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1344],{"type":23,"tag":36,"props":1345,"children":1346},{"__ignoreMap":8},[1347],{"type":28,"value":1342},{"type":23,"tag":24,"props":1349,"children":1350},{},[1351],{"type":28,"value":654},{"title":8,"searchDepth":61,"depth":61,"links":1353},[],"content:guides:java:javanet:save-your-pdf-online-and-get-back-a-url.md","guides/java/javanet/save-your-pdf-online-and-get-back-a-url.md",{"_path":1357,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":661,"description":1358,"language":11,"library":808,"property":625,"output":663,"related":1359,"default":7,"body":1360,"_type":63,"_id":1386,"_source":65,"_file":1387,"_extension":67},"/guides/java/javanet/save-your-pdf-to-your-amazon-s3-bucket","Learn how to save your PDF to your Amazon S3 bucket using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to store PDFs directly in AWS S3.",[335,187],{"type":20,"children":1361,"toc":1384},[1362,1367,1371,1380],{"type":23,"tag":24,"props":1363,"children":1364},{},[1365],{"type":28,"value":1366},"In this guide, we'll show you how to save your PDF to your Amazon S3 bucket using Java and the Java.net library.",{"type":23,"tag":24,"props":1368,"children":1369},{},[1370],{"type":28,"value":676},{"type":23,"tag":44,"props":1372,"children":1375},{"className":1373,"code":1374,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"output\\\": {\\n\" +\n    \"    \\\"type\\\": \\\"s3\\\",\\n\" +\n    \"    \\\"bucket\\\": \\\"your-bucket-name\\\",\\n\" +\n    \"    \\\"key\\\": \\\"path/to/document.pdf\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1376],{"type":23,"tag":36,"props":1377,"children":1378},{"__ignoreMap":8},[1379],{"type":28,"value":1374},{"type":23,"tag":24,"props":1381,"children":1382},{},[1383],{"type":28,"value":690},{"title":8,"searchDepth":61,"depth":61,"links":1385},[],"content:guides:java:javanet:save-your-pdf-to-your-amazon-s3-bucket.md","guides/java/javanet/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":1389,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":697,"description":1390,"language":11,"library":808,"property":699,"output":14,"related":1391,"default":7,"body":1392,"_type":63,"_id":1418,"_source":65,"_file":1419,"_extension":67},"/guides/java/javanet/send-custom-http-headers","Learn how to send custom HTTP headers when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to customize request headers.",[701,17],{"type":20,"children":1393,"toc":1416},[1394,1399,1403,1412],{"type":23,"tag":24,"props":1395,"children":1396},{},[1397],{"type":28,"value":1398},"In this guide, we'll show you how to send custom HTTP headers when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1400,"children":1401},{},[1402],{"type":28,"value":713},{"type":23,"tag":44,"props":1404,"children":1407},{"className":1405,"code":1406,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"headers\\\": {\\n\" +\n    \"    \\\"authorization\\\": \\\"Bearer token123\\\",\\n\" +\n    \"    \\\"user-agent\\\": \\\"MyApp/1.0\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1408],{"type":23,"tag":36,"props":1409,"children":1410},{"__ignoreMap":8},[1411],{"type":28,"value":1406},{"type":23,"tag":24,"props":1413,"children":1414},{},[1415],{"type":28,"value":727},{"title":8,"searchDepth":61,"depth":61,"links":1417},[],"content:guides:java:javanet:send-custom-http-headers.md","guides/java/javanet/send-custom-http-headers.md",{"_path":1421,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":734,"description":1422,"language":11,"library":808,"property":736,"output":14,"related":1423,"default":7,"body":1424,"_type":63,"_id":1450,"_source":65,"_file":1451,"_extension":67},"/guides/java/javanet/using-cookies","Learn how to use cookies when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to manage cookies during conversion.",[701,16],{"type":20,"children":1425,"toc":1448},[1426,1431,1435,1444],{"type":23,"tag":24,"props":1427,"children":1428},{},[1429],{"type":28,"value":1430},"In this guide, we'll show you how to use cookies when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1432,"children":1433},{},[1434],{"type":28,"value":749},{"type":23,"tag":44,"props":1436,"children":1439},{"className":1437,"code":1438,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"cookies\\\": {\\n\" +\n    \"    \\\"sessionid\\\": \\\"abc123\\\",\\n\" +\n    \"    \\\"user\\\": \\\"john_doe\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1440],{"type":23,"tag":36,"props":1441,"children":1442},{"__ignoreMap":8},[1443],{"type":28,"value":1438},{"type":23,"tag":24,"props":1445,"children":1446},{},[1447],{"type":28,"value":763},{"title":8,"searchDepth":61,"depth":61,"links":1449},[],"content:guides:java:javanet:using-cookies.md","guides/java/javanet/using-cookies.md",{"_path":1453,"_dir":806,"_draft":7,"_partial":7,"_locale":8,"title":770,"description":1454,"language":11,"library":808,"property":772,"output":14,"related":1455,"default":7,"body":1456,"_type":63,"_id":1482,"_source":65,"_file":1483,"_extension":67},"/guides/java/javanet/waiting-for-a-custom-element-to-be-ready","Learn how to wait for a custom element to be ready when converting HTML to PDF using Java and the Java.net library. This guide offers detailed steps with code samples in Java and the Java.net library, showing how to handle dynamic content.",[518,481],{"type":20,"children":1457,"toc":1480},[1458,1463,1467,1476],{"type":23,"tag":24,"props":1459,"children":1460},{},[1461],{"type":28,"value":1462},"In this guide, we'll show you how to wait for a custom element to be ready when converting HTML to PDF using Java and the Java.net library.",{"type":23,"tag":24,"props":1464,"children":1465},{},[1466],{"type":28,"value":785},{"type":23,"tag":44,"props":1468,"children":1471},{"className":1469,"code":1470,"language":49,"meta":8},[47],"import java.net.*;\nimport java.io.*;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nURL url = new URL(\"https://api.pdfshift.io/v3/convert/pdf\");\nHttpURLConnection connection = (HttpURLConnection) url.openConnection();\nconnection.setRequestMethod(\"POST\");\nconnection.setRequestProperty(\"X-API-Key\", apiKey);\nconnection.setRequestProperty(\"Content-Type\", \"application/json\");\nconnection.setDoOutput(true);\n\nString payload = \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"wait_for\\\": \\\"#dynamic-content.loaded\\\"\\n\" +\n    \"}\";\n\ntry (OutputStream os = connection.getOutputStream()) {\n    byte[] input = payload.getBytes(\"utf-8\");\n    os.write(input, 0, input.length);\n}\n\nint responseCode = connection.getResponseCode();\n\n// Handle errors:\nif (responseCode >= 400) {\n    throw new RuntimeException(\"Request failed with status code \" + responseCode);\n}\n\nInputStream inputStream = connection.getInputStream();\nFileOutputStream outputStream = new FileOutputStream(\"result.pdf\");\nbyte[] buffer = new byte[1024];\nint bytesRead;\nwhile ((bytesRead = inputStream.read(buffer)) != -1) {\n    outputStream.write(buffer, 0, bytesRead);\n}\noutputStream.close();\ninputStream.close();\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[1472],{"type":23,"tag":36,"props":1473,"children":1474},{"__ignoreMap":8},[1475],{"type":28,"value":1470},{"type":23,"tag":24,"props":1477,"children":1478},{},[1479],{"type":28,"value":799},{"title":8,"searchDepth":61,"depth":61,"links":1481},[],"content:guides:java:javanet:waiting-for-a-custom-element-to-be-ready.md","guides/java/javanet/waiting-for-a-custom-element-to-be-ready.md",{"_path":1485,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":1487,"language":11,"library":1488,"property":13,"output":14,"related":1489,"default":18,"body":1490,"_type":63,"_id":1522,"_source":65,"_file":1523,"_extension":67},"/guides/java/netty/accessing-secured-pages","netty","Learn how to access secured pages using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, highlighting how you can access page protected by basic authentication to convert them to PDF using PDFShift's API.","Netty",[16,17],{"type":20,"children":1491,"toc":1520},[1492,1497,1507,1516],{"type":23,"tag":24,"props":1493,"children":1494},{},[1495],{"type":28,"value":1496},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Java and the Netty library to convert them to PDF using PDFShift's API.",{"type":23,"tag":24,"props":1498,"children":1499},{},[1500,1501,1506],{"type":28,"value":34},{"type":23,"tag":36,"props":1502,"children":1504},{"className":1503},[],[1505],{"type":28,"value":13},{"type":28,"value":42},{"type":23,"tag":44,"props":1508,"children":1511},{"className":1509,"code":1510,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"auth\\\": {\\n\" +\n        \"    \\\"username\\\": \\\"user\\\",\\n\" +\n        \"    \\\"password\\\": \\\"password\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1512],{"type":23,"tag":36,"props":1513,"children":1514},{"__ignoreMap":8},[1515],{"type":28,"value":1510},{"type":23,"tag":24,"props":1517,"children":1518},{},[1519],{"type":28,"value":59},{"title":8,"searchDepth":61,"depth":61,"links":1521},[],"content:guides:java:netty:accessing-secured-pages.md","guides/java/netty/accessing-secured-pages.md",{"_path":1525,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":70,"description":1526,"language":11,"library":1488,"property":72,"output":14,"related":1527,"default":7,"body":1528,"_type":63,"_id":1554,"_source":65,"_file":1555,"_extension":67},"/guides/java/netty/adding-a-custom-header-or-footer","Learn how to add custom headers and footers to your PDFs using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to customize PDF appearance with headers and footers.",[74,75],{"type":20,"children":1529,"toc":1552},[1530,1535,1539,1548],{"type":23,"tag":24,"props":1531,"children":1532},{},[1533],{"type":28,"value":1534},"In this guide, we'll show you how to add custom headers and footers to your PDFs using Java and the Netty library.",{"type":23,"tag":24,"props":1536,"children":1537},{},[1538],{"type":28,"value":87},{"type":23,"tag":44,"props":1540,"children":1543},{"className":1541,"code":1542,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"header\\\": {\\n\" +\n        \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Header Content\u003C/div>\\\",\\n\" +\n        \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n        \"  },\\n\" +\n        \"  \\\"footer\\\": {\\n\" +\n        \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Footer Content\u003C/div>\\\",\\n\" +\n        \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1544],{"type":23,"tag":36,"props":1545,"children":1546},{"__ignoreMap":8},[1547],{"type":28,"value":1542},{"type":23,"tag":24,"props":1549,"children":1550},{},[1551],{"type":28,"value":101},{"title":8,"searchDepth":61,"depth":61,"links":1553},[],"content:guides:java:netty:adding-a-custom-header-or-footer.md","guides/java/netty/adding-a-custom-header-or-footer.md",{"_path":1557,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":108,"description":1558,"language":11,"library":1488,"property":110,"output":14,"related":1559,"default":7,"body":1560,"_type":63,"_id":1586,"_source":65,"_file":1587,"_extension":67},"/guides/java/netty/adding-a-text-watermark","Learn how to add text watermarks to your PDFs using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to apply text watermarks to protect your documents.",[112,113],{"type":20,"children":1561,"toc":1584},[1562,1567,1571,1580],{"type":23,"tag":24,"props":1563,"children":1564},{},[1565],{"type":28,"value":1566},"In this guide, we'll show you how to add text watermarks to your PDFs using Java and the Netty library.",{"type":23,"tag":24,"props":1568,"children":1569},{},[1570],{"type":28,"value":125},{"type":23,"tag":44,"props":1572,"children":1575},{"className":1573,"code":1574,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"watermark\\\": {\\n\" +\n        \"    \\\"text\\\": \\\"CONFIDENTIAL\\\",\\n\" +\n        \"    \\\"opacity\\\": 0.3,\\n\" +\n        \"    \\\"size\\\": \\\"20px\\\",\\n\" +\n        \"    \\\"color\\\": \\\"#000000\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1576],{"type":23,"tag":36,"props":1577,"children":1578},{"__ignoreMap":8},[1579],{"type":28,"value":1574},{"type":23,"tag":24,"props":1581,"children":1582},{},[1583],{"type":28,"value":139},{"title":8,"searchDepth":61,"depth":61,"links":1585},[],"content:guides:java:netty:adding-a-text-watermark.md","guides/java/netty/adding-a-text-watermark.md",{"_path":1589,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":146,"description":1590,"language":11,"library":1488,"property":110,"output":14,"related":1591,"default":7,"body":1592,"_type":63,"_id":1618,"_source":65,"_file":1619,"_extension":67},"/guides/java/netty/adding-an-image-watermark","Learn how to add image watermarks to your PDFs using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to apply image watermarks to protect your documents.",[149,113],{"type":20,"children":1593,"toc":1616},[1594,1599,1603,1612],{"type":23,"tag":24,"props":1595,"children":1596},{},[1597],{"type":28,"value":1598},"In this guide, we'll show you how to add image watermarks to your PDFs using Java and the Netty library.",{"type":23,"tag":24,"props":1600,"children":1601},{},[1602],{"type":28,"value":161},{"type":23,"tag":44,"props":1604,"children":1607},{"className":1605,"code":1606,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"watermark\\\": {\\n\" +\n        \"    \\\"image\\\": \\\"https://example.com/watermark.png\\\",\\n\" +\n        \"    \\\"opacity\\\": 0.5,\\n\" +\n        \"    \\\"position\\\": \\\"center\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1608],{"type":23,"tag":36,"props":1609,"children":1610},{"__ignoreMap":8},[1611],{"type":28,"value":1606},{"type":23,"tag":24,"props":1613,"children":1614},{},[1615],{"type":28,"value":175},{"title":8,"searchDepth":61,"depth":61,"links":1617},[],"content:guides:java:netty:adding-an-image-watermark.md","guides/java/netty/adding-an-image-watermark.md",{"_path":1621,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":182,"description":1622,"language":11,"library":1488,"property":184,"output":14,"related":1623,"default":7,"body":1624,"_type":63,"_id":1650,"_source":65,"_file":1651,"_extension":67},"/guides/java/netty/avoid-conversion-on-error","Learn how to avoid conversion on error using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to handle conversion errors gracefully.",[186,187],{"type":20,"children":1625,"toc":1648},[1626,1631,1635,1644],{"type":23,"tag":24,"props":1627,"children":1628},{},[1629],{"type":28,"value":1630},"In this guide, we'll show you how to avoid conversion on error using Java and the Netty library.",{"type":23,"tag":24,"props":1632,"children":1633},{},[1634],{"type":28,"value":199},{"type":23,"tag":44,"props":1636,"children":1639},{"className":1637,"code":1638,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"continue_on_error\\\": false\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1640],{"type":23,"tag":36,"props":1641,"children":1642},{"__ignoreMap":8},[1643],{"type":28,"value":1638},{"type":23,"tag":24,"props":1645,"children":1646},{},[1647],{"type":28,"value":213},{"title":8,"searchDepth":61,"depth":61,"links":1649},[],"content:guides:java:netty:avoid-conversion-on-error.md","guides/java/netty/avoid-conversion-on-error.md",{"_path":1653,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":220,"description":1654,"language":11,"library":1488,"property":222,"output":14,"related":1655,"default":18,"body":1656,"_type":63,"_id":1682,"_source":65,"_file":1683,"_extension":67},"/guides/java/netty/convert-html-to-pdf-from-a-url","Learn how to convert HTML from a URL to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to convert online HTML content to PDF.",[224,75],{"type":20,"children":1657,"toc":1680},[1658,1663,1667,1676],{"type":23,"tag":24,"props":1659,"children":1660},{},[1661],{"type":28,"value":1662},"In this guide, we'll show you how to convert HTML from a URL to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1664,"children":1665},{},[1666],{"type":28,"value":236},{"type":23,"tag":44,"props":1668,"children":1671},{"className":1669,"code":1670,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1672],{"type":23,"tag":36,"props":1673,"children":1674},{"__ignoreMap":8},[1675],{"type":28,"value":1670},{"type":23,"tag":24,"props":1677,"children":1678},{},[1679],{"type":28,"value":250},{"title":8,"searchDepth":61,"depth":61,"links":1681},[],"content:guides:java:netty:convert-html-to-pdf-from-a-url.md","guides/java/netty/convert-html-to-pdf-from-a-url.md",{"_path":1685,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":257,"description":1686,"language":11,"library":1488,"property":222,"output":14,"related":1687,"default":18,"body":1688,"_type":63,"_id":1714,"_source":65,"_file":1715,"_extension":67},"/guides/java/netty/convert-html-to-pdf-from-raw-html","Learn how to convert raw HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to convert HTML content directly to PDF.",[260,74],{"type":20,"children":1689,"toc":1712},[1690,1695,1699,1708],{"type":23,"tag":24,"props":1691,"children":1692},{},[1693],{"type":28,"value":1694},"In this guide, we'll show you how to convert raw HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1696,"children":1697},{},[1698],{"type":28,"value":272},{"type":23,"tag":44,"props":1700,"children":1703},{"className":1701,"code":1702,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"\u003Chtml>\u003Cbody>\u003Ch1>Hello World\u003C/h1>\u003C/body>\u003C/html>\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1704],{"type":23,"tag":36,"props":1705,"children":1706},{"__ignoreMap":8},[1707],{"type":28,"value":1702},{"type":23,"tag":24,"props":1709,"children":1710},{},[1711],{"type":28,"value":286},{"title":8,"searchDepth":61,"depth":61,"links":1713},[],"content:guides:java:netty:convert-html-to-pdf-from-raw-html.md","guides/java/netty/convert-html-to-pdf-from-raw-html.md",{"_path":1717,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":293,"description":1718,"language":11,"library":1488,"property":295,"output":14,"related":1719,"default":7,"body":1720,"_type":63,"_id":1746,"_source":65,"_file":1747,"_extension":67},"/guides/java/netty/define-a-time-limit","Learn how to define a time limit for PDF conversions using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to set timeouts to prevent long-running conversions.",[297,186],{"type":20,"children":1721,"toc":1744},[1722,1727,1731,1740],{"type":23,"tag":24,"props":1723,"children":1724},{},[1725],{"type":28,"value":1726},"In this guide, we'll show you how to define a time limit for PDF conversions using Java and the Netty library.",{"type":23,"tag":24,"props":1728,"children":1729},{},[1730],{"type":28,"value":309},{"type":23,"tag":44,"props":1732,"children":1735},{"className":1733,"code":1734,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"timeout\\\": 30\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1736],{"type":23,"tag":36,"props":1737,"children":1738},{"__ignoreMap":8},[1739],{"type":28,"value":1734},{"type":23,"tag":24,"props":1741,"children":1742},{},[1743],{"type":28,"value":323},{"title":8,"searchDepth":61,"depth":61,"links":1745},[],"content:guides:java:netty:define-a-time-limit.md","guides/java/netty/define-a-time-limit.md",{"_path":1749,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":330,"description":1750,"language":11,"library":1488,"property":332,"output":14,"related":1751,"default":7,"body":1752,"_type":63,"_id":1778,"_source":65,"_file":1779,"_extension":67},"/guides/java/netty/exporting-only-a-specific-set-of-pages","Learn how to export only specific pages from a document when converting to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to select specific pages for export.",[334,335],{"type":20,"children":1753,"toc":1776},[1754,1759,1763,1772],{"type":23,"tag":24,"props":1755,"children":1756},{},[1757],{"type":28,"value":1758},"In this guide, we'll show you how to export only specific pages from a document when converting to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1760,"children":1761},{},[1762],{"type":28,"value":347},{"type":23,"tag":44,"props":1764,"children":1767},{"className":1765,"code":1766,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"pages\\\": \\\"1-3\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1768],{"type":23,"tag":36,"props":1769,"children":1770},{"__ignoreMap":8},[1771],{"type":28,"value":1766},{"type":23,"tag":24,"props":1773,"children":1774},{},[1775],{"type":28,"value":361},{"title":8,"searchDepth":61,"depth":61,"links":1777},[],"content:guides:java:netty:exporting-only-a-specific-set-of-pages.md","guides/java/netty/exporting-only-a-specific-set-of-pages.md",{"_path":1781,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":368,"description":1782,"language":11,"library":1488,"property":370,"output":14,"related":1783,"default":7,"body":1784,"_type":63,"_id":1810,"_source":65,"_file":1811,"_extension":67},"/guides/java/netty/generate-a-document-with-full-height","Learn how to generate a document with full height using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to create full-height PDFs.",[372,335],{"type":20,"children":1785,"toc":1808},[1786,1791,1795,1804],{"type":23,"tag":24,"props":1787,"children":1788},{},[1789],{"type":28,"value":1790},"In this guide, we'll show you how to generate a document with full height using Java and the Netty library.",{"type":23,"tag":24,"props":1792,"children":1793},{},[1794],{"type":28,"value":384},{"type":23,"tag":44,"props":1796,"children":1799},{"className":1797,"code":1798,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"full_height\\\": true\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1800],{"type":23,"tag":36,"props":1801,"children":1802},{"__ignoreMap":8},[1803],{"type":28,"value":1798},{"type":23,"tag":24,"props":1805,"children":1806},{},[1807],{"type":28,"value":398},{"title":8,"searchDepth":61,"depth":61,"links":1809},[],"content:guides:java:netty:generate-a-document-with-full-height.md","guides/java/netty/generate-a-document-with-full-height.md",{"_path":1813,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":405,"description":1814,"language":11,"library":1488,"property":407,"output":14,"related":1815,"default":7,"body":1816,"_type":63,"_id":1842,"_source":65,"_file":1843,"_extension":67},"/guides/java/netty/loading-css-from-a-string","Learn how to load CSS from a string when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to apply inline CSS styling.",[75,409],{"type":20,"children":1817,"toc":1840},[1818,1823,1827,1836],{"type":23,"tag":24,"props":1819,"children":1820},{},[1821],{"type":28,"value":1822},"In this guide, we'll show you how to load CSS from a string when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1824,"children":1825},{},[1826],{"type":28,"value":421},{"type":23,"tag":44,"props":1828,"children":1831},{"className":1829,"code":1830,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"css\\\": \\\"body { font-family: Arial; } h1 { color: blue; }\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1832],{"type":23,"tag":36,"props":1833,"children":1834},{"__ignoreMap":8},[1835],{"type":28,"value":1830},{"type":23,"tag":24,"props":1837,"children":1838},{},[1839],{"type":28,"value":435},{"title":8,"searchDepth":61,"depth":61,"links":1841},[],"content:guides:java:netty:loading-css-from-a-string.md","guides/java/netty/loading-css-from-a-string.md",{"_path":1845,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":442,"description":1846,"language":11,"library":1488,"property":407,"output":14,"related":1847,"default":7,"body":1848,"_type":63,"_id":1874,"_source":65,"_file":1875,"_extension":67},"/guides/java/netty/loading-css-from-a-url","Learn how to load CSS from a URL when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to reference external CSS files.",[74,260],{"type":20,"children":1849,"toc":1872},[1850,1855,1859,1868],{"type":23,"tag":24,"props":1851,"children":1852},{},[1853],{"type":28,"value":1854},"In this guide, we'll show you how to load CSS from a URL when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1856,"children":1857},{},[1858],{"type":28,"value":456},{"type":23,"tag":44,"props":1860,"children":1863},{"className":1861,"code":1862,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"css\\\": \\\"https://example.com/styles.css\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1864],{"type":23,"tag":36,"props":1865,"children":1866},{"__ignoreMap":8},[1867],{"type":28,"value":1862},{"type":23,"tag":24,"props":1869,"children":1870},{},[1871],{"type":28,"value":470},{"title":8,"searchDepth":61,"depth":61,"links":1873},[],"content:guides:java:netty:loading-css-from-a-url.md","guides/java/netty/loading-css-from-a-url.md",{"_path":1877,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":477,"description":1878,"language":11,"library":1488,"property":479,"output":14,"related":1879,"default":7,"body":1880,"_type":63,"_id":1906,"_source":65,"_file":1907,"_extension":67},"/guides/java/netty/loading-javascript-from-a-string","Learn how to load JavaScript from a string when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to include inline JavaScript.",[481,482],{"type":20,"children":1881,"toc":1904},[1882,1887,1891,1900],{"type":23,"tag":24,"props":1883,"children":1884},{},[1885],{"type":28,"value":1886},"In this guide, we'll show you how to load JavaScript from a string when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1888,"children":1889},{},[1890],{"type":28,"value":494},{"type":23,"tag":44,"props":1892,"children":1895},{"className":1893,"code":1894,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"javascript\\\": \\\"document.body.style.backgroundColor = 'red';\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1896],{"type":23,"tag":36,"props":1897,"children":1898},{"__ignoreMap":8},[1899],{"type":28,"value":1894},{"type":23,"tag":24,"props":1901,"children":1902},{},[1903],{"type":28,"value":508},{"title":8,"searchDepth":61,"depth":61,"links":1905},[],"content:guides:java:netty:loading-javascript-from-a-string.md","guides/java/netty/loading-javascript-from-a-string.md",{"_path":1909,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":515,"description":1910,"language":11,"library":1488,"property":479,"output":14,"related":1911,"default":7,"body":1912,"_type":63,"_id":1938,"_source":65,"_file":1939,"_extension":67},"/guides/java/netty/loading-javascript-from-a-url","Learn how to load JavaScript from a URL when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to reference external JavaScript files.",[518,482],{"type":20,"children":1913,"toc":1936},[1914,1919,1923,1932],{"type":23,"tag":24,"props":1915,"children":1916},{},[1917],{"type":28,"value":1918},"In this guide, we'll show you how to load JavaScript from a URL when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":1920,"children":1921},{},[1922],{"type":28,"value":530},{"type":23,"tag":44,"props":1924,"children":1927},{"className":1925,"code":1926,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"javascript\\\": \\\"https://example.com/script.js\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1928],{"type":23,"tag":36,"props":1929,"children":1930},{"__ignoreMap":8},[1931],{"type":28,"value":1926},{"type":23,"tag":24,"props":1933,"children":1934},{},[1935],{"type":28,"value":544},{"title":8,"searchDepth":61,"depth":61,"links":1937},[],"content:guides:java:netty:loading-javascript-from-a-url.md","guides/java/netty/loading-javascript-from-a-url.md",{"_path":1941,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":551,"description":1942,"language":11,"library":1488,"property":553,"output":14,"related":1943,"default":7,"body":1944,"_type":63,"_id":1970,"_source":65,"_file":1971,"_extension":67},"/guides/java/netty/protecting-the-generated-pdf","Learn how to protect generated PDFs with passwords using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to secure your PDF documents.",[112,149],{"type":20,"children":1945,"toc":1968},[1946,1951,1955,1964],{"type":23,"tag":24,"props":1947,"children":1948},{},[1949],{"type":28,"value":1950},"In this guide, we'll show you how to protect generated PDFs with passwords using Java and the Netty library.",{"type":23,"tag":24,"props":1952,"children":1953},{},[1954],{"type":28,"value":566},{"type":23,"tag":44,"props":1956,"children":1959},{"className":1957,"code":1958,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"protection\\\": {\\n\" +\n        \"    \\\"user_password\\\": \\\"user123\\\",\\n\" +\n        \"    \\\"owner_password\\\": \\\"owner123\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1960],{"type":23,"tag":36,"props":1961,"children":1962},{"__ignoreMap":8},[1963],{"type":28,"value":1958},{"type":23,"tag":24,"props":1965,"children":1966},{},[1967],{"type":28,"value":580},{"title":8,"searchDepth":61,"depth":61,"links":1969},[],"content:guides:java:netty:protecting-the-generated-pdf.md","guides/java/netty/protecting-the-generated-pdf.md",{"_path":1973,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":587,"description":1974,"language":11,"library":1488,"property":589,"output":14,"related":1975,"default":7,"body":1976,"_type":63,"_id":2002,"_source":65,"_file":2003,"_extension":67},"/guides/java/netty/receive-a-webhook-event","Learn how to receive webhook events when PDF conversion is complete using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to handle asynchronous conversion notifications.",[335,297],{"type":20,"children":1977,"toc":2000},[1978,1983,1987,1996],{"type":23,"tag":24,"props":1979,"children":1980},{},[1981],{"type":28,"value":1982},"In this guide, we'll show you how to receive webhook events when PDF conversion is complete using Java and the Netty library.",{"type":23,"tag":24,"props":1984,"children":1985},{},[1986],{"type":28,"value":602},{"type":23,"tag":44,"props":1988,"children":1991},{"className":1989,"code":1990,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"webhook\\\": {\\n\" +\n        \"    \\\"url\\\": \\\"https://your-server.com/webhook\\\",\\n\" +\n        \"    \\\"secret\\\": \\\"your-secret-key\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[1992],{"type":23,"tag":36,"props":1993,"children":1994},{"__ignoreMap":8},[1995],{"type":28,"value":1990},{"type":23,"tag":24,"props":1997,"children":1998},{},[1999],{"type":28,"value":616},{"title":8,"searchDepth":61,"depth":61,"links":2001},[],"content:guides:java:netty:receive-a-webhook-event.md","guides/java/netty/receive-a-webhook-event.md",{"_path":2005,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":623,"description":2006,"language":11,"library":1488,"property":625,"output":626,"related":2007,"default":7,"body":2008,"_type":63,"_id":2034,"_source":65,"_file":2035,"_extension":67},"/guides/java/netty/save-your-pdf-online-and-get-back-a-url","Learn how to save your PDF online and get back a URL using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to store PDFs in cloud storage and retrieve URLs.",[628,187],{"type":20,"children":2009,"toc":2032},[2010,2015,2019,2028],{"type":23,"tag":24,"props":2011,"children":2012},{},[2013],{"type":28,"value":2014},"In this guide, we'll show you how to save your PDF online and get back a URL using Java and the Netty library.",{"type":23,"tag":24,"props":2016,"children":2017},{},[2018],{"type":28,"value":640},{"type":23,"tag":44,"props":2020,"children":2023},{"className":2021,"code":2022,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"output\\\": {\\n\" +\n        \"    \\\"type\\\": \\\"url\\\",\\n\" +\n        \"    \\\"url\\\": \\\"https://your-storage.com/\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[2024],{"type":23,"tag":36,"props":2025,"children":2026},{"__ignoreMap":8},[2027],{"type":28,"value":2022},{"type":23,"tag":24,"props":2029,"children":2030},{},[2031],{"type":28,"value":654},{"title":8,"searchDepth":61,"depth":61,"links":2033},[],"content:guides:java:netty:save-your-pdf-online-and-get-back-a-url.md","guides/java/netty/save-your-pdf-online-and-get-back-a-url.md",{"_path":2037,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":661,"description":2038,"language":11,"library":1488,"property":625,"output":663,"related":2039,"default":7,"body":2040,"_type":63,"_id":2066,"_source":65,"_file":2067,"_extension":67},"/guides/java/netty/save-your-pdf-to-your-amazon-s3-bucket","Learn how to save your PDF to your Amazon S3 bucket using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to store PDFs directly in AWS S3.",[335,187],{"type":20,"children":2041,"toc":2064},[2042,2047,2051,2060],{"type":23,"tag":24,"props":2043,"children":2044},{},[2045],{"type":28,"value":2046},"In this guide, we'll show you how to save your PDF to your Amazon S3 bucket using Java and the Netty library.",{"type":23,"tag":24,"props":2048,"children":2049},{},[2050],{"type":28,"value":676},{"type":23,"tag":44,"props":2052,"children":2055},{"className":2053,"code":2054,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"output\\\": {\\n\" +\n        \"    \\\"type\\\": \\\"s3\\\",\\n\" +\n        \"    \\\"bucket\\\": \\\"your-bucket-name\\\",\\n\" +\n        \"    \\\"key\\\": \\\"path/to/document.pdf\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[2056],{"type":23,"tag":36,"props":2057,"children":2058},{"__ignoreMap":8},[2059],{"type":28,"value":2054},{"type":23,"tag":24,"props":2061,"children":2062},{},[2063],{"type":28,"value":690},{"title":8,"searchDepth":61,"depth":61,"links":2065},[],"content:guides:java:netty:save-your-pdf-to-your-amazon-s3-bucket.md","guides/java/netty/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":2069,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":697,"description":2070,"language":11,"library":1488,"property":699,"output":14,"related":2071,"default":7,"body":2072,"_type":63,"_id":2098,"_source":65,"_file":2099,"_extension":67},"/guides/java/netty/send-custom-http-headers","Learn how to send custom HTTP headers when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to customize request headers.",[701,17],{"type":20,"children":2073,"toc":2096},[2074,2079,2083,2092],{"type":23,"tag":24,"props":2075,"children":2076},{},[2077],{"type":28,"value":2078},"In this guide, we'll show you how to send custom HTTP headers when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":2080,"children":2081},{},[2082],{"type":28,"value":713},{"type":23,"tag":44,"props":2084,"children":2087},{"className":2085,"code":2086,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"headers\\\": {\\n\" +\n        \"    \\\"authorization\\\": \\\"Bearer token123\\\",\\n\" +\n        \"    \\\"user-agent\\\": \\\"MyApp/1.0\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[2088],{"type":23,"tag":36,"props":2089,"children":2090},{"__ignoreMap":8},[2091],{"type":28,"value":2086},{"type":23,"tag":24,"props":2093,"children":2094},{},[2095],{"type":28,"value":727},{"title":8,"searchDepth":61,"depth":61,"links":2097},[],"content:guides:java:netty:send-custom-http-headers.md","guides/java/netty/send-custom-http-headers.md",{"_path":2101,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":734,"description":2102,"language":11,"library":1488,"property":736,"output":14,"related":2103,"default":7,"body":2104,"_type":63,"_id":2130,"_source":65,"_file":2131,"_extension":67},"/guides/java/netty/using-cookies","Learn how to use cookies when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to manage cookies during conversion.",[701,16],{"type":20,"children":2105,"toc":2128},[2106,2111,2115,2124],{"type":23,"tag":24,"props":2107,"children":2108},{},[2109],{"type":28,"value":2110},"In this guide, we'll show you how to use cookies when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":2112,"children":2113},{},[2114],{"type":28,"value":749},{"type":23,"tag":44,"props":2116,"children":2119},{"className":2117,"code":2118,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"cookies\\\": {\\n\" +\n        \"    \\\"sessionid\\\": \\\"abc123\\\",\\n\" +\n        \"    \\\"user\\\": \\\"john_doe\\\"\\n\" +\n        \"  }\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[2120],{"type":23,"tag":36,"props":2121,"children":2122},{"__ignoreMap":8},[2123],{"type":28,"value":2118},{"type":23,"tag":24,"props":2125,"children":2126},{},[2127],{"type":28,"value":763},{"title":8,"searchDepth":61,"depth":61,"links":2129},[],"content:guides:java:netty:using-cookies.md","guides/java/netty/using-cookies.md",{"_path":2133,"_dir":1486,"_draft":7,"_partial":7,"_locale":8,"title":770,"description":2134,"language":11,"library":1488,"property":772,"output":14,"related":2135,"default":7,"body":2136,"_type":63,"_id":2162,"_source":65,"_file":2163,"_extension":67},"/guides/java/netty/waiting-for-a-custom-element-to-be-ready","Learn how to wait for a custom element to be ready when converting HTML to PDF using Java and the Netty library. This guide offers detailed steps with code samples in Java and the Netty library, showing how to handle dynamic content.",[518,481],{"type":20,"children":2137,"toc":2160},[2138,2143,2147,2156],{"type":23,"tag":24,"props":2139,"children":2140},{},[2141],{"type":28,"value":2142},"In this guide, we'll show you how to wait for a custom element to be ready when converting HTML to PDF using Java and the Netty library.",{"type":23,"tag":24,"props":2144,"children":2145},{},[2146],{"type":28,"value":785},{"type":23,"tag":44,"props":2148,"children":2151},{"className":2149,"code":2150,"language":49,"meta":8},[47],"import io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.*;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport io.netty.handler.codec.http.*;\nimport io.netty.util.CharsetUtil;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nEventLoopGroup group = new NioEventLoopGroup();\ntry {\n    Bootstrap b = new Bootstrap();\n    b.group(group)\n        .channel(NioSocketChannel.class)\n        .handler(new ChannelInitializer\u003CSocketChannel>() {\n            @Override\n            public void initChannel(SocketChannel ch) {\n                ChannelPipeline p = ch.pipeline();\n                p.addLast(new HttpClientCodec());\n                p.addLast(new HttpObjectAggregator(1024 * 1024));\n            }\n        });\n\n    Channel ch = b.connect(\"api.pdfshift.io\", 443).sync().channel();\n\n    FullHttpRequest request = new DefaultFullHttpRequest(\n        HttpVersion.HTTP_1_1, HttpMethod.POST, \"/v3/convert/pdf\");\n    \n    request.headers().set(HttpHeaderNames.HOST, \"api.pdfshift.io\");\n    request.headers().set(\"X-API-Key\", apiKey);\n    request.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json\");\n    \n    String payload = \"{\\n\" +\n        \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n        \"  \\\"wait_for\\\": \\\"#dynamic-content.loaded\\\"\\n\" +\n        \"}\";\n    \n    request.content().writeBytes(payload.getBytes(CharsetUtil.UTF_8));\n    request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());\n\n    ChannelFuture f = ch.writeAndFlush(request);\n    f.addListener(ChannelFutureListener.CLOSE);\n    \n    // Handle response and save PDF...\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n} finally {\n    group.shutdownGracefully();\n}\n",[2152],{"type":23,"tag":36,"props":2153,"children":2154},{"__ignoreMap":8},[2155],{"type":28,"value":2150},{"type":23,"tag":24,"props":2157,"children":2158},{},[2159],{"type":28,"value":799},{"title":8,"searchDepth":61,"depth":61,"links":2161},[],"content:guides:java:netty:waiting-for-a-custom-element-to-be-ready.md","guides/java/netty/waiting-for-a-custom-element-to-be-ready.md",{"_path":2165,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":2167,"language":11,"library":2168,"property":13,"output":14,"related":2169,"default":18,"body":2170,"_type":63,"_id":2202,"_source":65,"_file":2203,"_extension":67},"/guides/java/okhttp/accessing-secured-pages","okhttp","Learn how to access secured pages using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, highlighting how you can access page protected by basic authentication to convert them to PDF using PDFShift's API.","OkHTTP",[16,17],{"type":20,"children":2171,"toc":2200},[2172,2177,2187,2196],{"type":23,"tag":24,"props":2173,"children":2174},{},[2175],{"type":28,"value":2176},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Java and the OkHTTP library to convert them to PDF using PDFShift's API.",{"type":23,"tag":24,"props":2178,"children":2179},{},[2180,2181,2186],{"type":28,"value":34},{"type":23,"tag":36,"props":2182,"children":2184},{"className":2183},[],[2185],{"type":28,"value":13},{"type":28,"value":42},{"type":23,"tag":44,"props":2188,"children":2191},{"className":2189,"code":2190,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"auth\\\": {\\n\" +\n    \"    \\\"username\\\": \\\"user\\\",\\n\" +\n    \"    \\\"password\\\": \\\"password\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2192],{"type":23,"tag":36,"props":2193,"children":2194},{"__ignoreMap":8},[2195],{"type":28,"value":2190},{"type":23,"tag":24,"props":2197,"children":2198},{},[2199],{"type":28,"value":59},{"title":8,"searchDepth":61,"depth":61,"links":2201},[],"content:guides:java:okhttp:accessing-secured-pages.md","guides/java/okhttp/accessing-secured-pages.md",{"_path":2205,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":70,"description":2206,"language":11,"library":2168,"property":72,"output":14,"related":2207,"default":7,"body":2208,"_type":63,"_id":2234,"_source":65,"_file":2235,"_extension":67},"/guides/java/okhttp/adding-a-custom-header-or-footer","Learn how to add custom headers and footers to your PDFs using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to customize PDF appearance with headers and footers.",[74,75],{"type":20,"children":2209,"toc":2232},[2210,2215,2219,2228],{"type":23,"tag":24,"props":2211,"children":2212},{},[2213],{"type":28,"value":2214},"In this guide, we'll show you how to add custom headers and footers to your PDFs using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2216,"children":2217},{},[2218],{"type":28,"value":87},{"type":23,"tag":44,"props":2220,"children":2223},{"className":2221,"code":2222,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"header\\\": {\\n\" +\n    \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Header Content\u003C/div>\\\",\\n\" +\n    \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n    \"  },\\n\" +\n    \"  \\\"footer\\\": {\\n\" +\n    \"    \\\"content\\\": \\\"\u003Cdiv style='text-align: center;'>Footer Content\u003C/div>\\\",\\n\" +\n    \"    \\\"height\\\": \\\"20mm\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2224],{"type":23,"tag":36,"props":2225,"children":2226},{"__ignoreMap":8},[2227],{"type":28,"value":2222},{"type":23,"tag":24,"props":2229,"children":2230},{},[2231],{"type":28,"value":101},{"title":8,"searchDepth":61,"depth":61,"links":2233},[],"content:guides:java:okhttp:adding-a-custom-header-or-footer.md","guides/java/okhttp/adding-a-custom-header-or-footer.md",{"_path":2237,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":108,"description":2238,"language":11,"library":2168,"property":110,"output":14,"related":2239,"default":7,"body":2240,"_type":63,"_id":2266,"_source":65,"_file":2267,"_extension":67},"/guides/java/okhttp/adding-a-text-watermark","Learn how to add text watermarks to your PDFs using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to apply text watermarks to protect your documents.",[112,113],{"type":20,"children":2241,"toc":2264},[2242,2247,2251,2260],{"type":23,"tag":24,"props":2243,"children":2244},{},[2245],{"type":28,"value":2246},"In this guide, we'll show you how to add text watermarks to your PDFs using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2248,"children":2249},{},[2250],{"type":28,"value":125},{"type":23,"tag":44,"props":2252,"children":2255},{"className":2253,"code":2254,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"watermark\\\": {\\n\" +\n    \"    \\\"text\\\": \\\"CONFIDENTIAL\\\",\\n\" +\n    \"    \\\"opacity\\\": 0.3,\\n\" +\n    \"    \\\"size\\\": \\\"20px\\\",\\n\" +\n    \"    \\\"color\\\": \\\"#000000\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2256],{"type":23,"tag":36,"props":2257,"children":2258},{"__ignoreMap":8},[2259],{"type":28,"value":2254},{"type":23,"tag":24,"props":2261,"children":2262},{},[2263],{"type":28,"value":139},{"title":8,"searchDepth":61,"depth":61,"links":2265},[],"content:guides:java:okhttp:adding-a-text-watermark.md","guides/java/okhttp/adding-a-text-watermark.md",{"_path":2269,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":146,"description":2270,"language":11,"library":2168,"property":110,"output":14,"related":2271,"default":7,"body":2272,"_type":63,"_id":2298,"_source":65,"_file":2299,"_extension":67},"/guides/java/okhttp/adding-an-image-watermark","Learn how to add image watermarks to your PDFs using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to apply image watermarks to protect your documents.",[149,113],{"type":20,"children":2273,"toc":2296},[2274,2279,2283,2292],{"type":23,"tag":24,"props":2275,"children":2276},{},[2277],{"type":28,"value":2278},"In this guide, we'll show you how to add image watermarks to your PDFs using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2280,"children":2281},{},[2282],{"type":28,"value":161},{"type":23,"tag":44,"props":2284,"children":2287},{"className":2285,"code":2286,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"watermark\\\": {\\n\" +\n    \"    \\\"image\\\": \\\"https://example.com/watermark.png\\\",\\n\" +\n    \"    \\\"opacity\\\": 0.5,\\n\" +\n    \"    \\\"position\\\": \\\"center\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2288],{"type":23,"tag":36,"props":2289,"children":2290},{"__ignoreMap":8},[2291],{"type":28,"value":2286},{"type":23,"tag":24,"props":2293,"children":2294},{},[2295],{"type":28,"value":175},{"title":8,"searchDepth":61,"depth":61,"links":2297},[],"content:guides:java:okhttp:adding-an-image-watermark.md","guides/java/okhttp/adding-an-image-watermark.md",{"_path":2301,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":182,"description":2302,"language":11,"library":2168,"property":184,"output":14,"related":2303,"default":7,"body":2304,"_type":63,"_id":2330,"_source":65,"_file":2331,"_extension":67},"/guides/java/okhttp/avoid-conversion-on-error","Learn how to avoid conversion on error using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to handle conversion errors gracefully.",[186,187],{"type":20,"children":2305,"toc":2328},[2306,2311,2315,2324],{"type":23,"tag":24,"props":2307,"children":2308},{},[2309],{"type":28,"value":2310},"In this guide, we'll show you how to avoid conversion on error using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2312,"children":2313},{},[2314],{"type":28,"value":199},{"type":23,"tag":44,"props":2316,"children":2319},{"className":2317,"code":2318,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"continue_on_error\\\": false\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2320],{"type":23,"tag":36,"props":2321,"children":2322},{"__ignoreMap":8},[2323],{"type":28,"value":2318},{"type":23,"tag":24,"props":2325,"children":2326},{},[2327],{"type":28,"value":213},{"title":8,"searchDepth":61,"depth":61,"links":2329},[],"content:guides:java:okhttp:avoid-conversion-on-error.md","guides/java/okhttp/avoid-conversion-on-error.md",{"_path":2333,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":220,"description":2334,"language":11,"library":2168,"property":222,"output":14,"related":2335,"default":18,"body":2336,"_type":63,"_id":2362,"_source":65,"_file":2363,"_extension":67},"/guides/java/okhttp/convert-html-to-pdf-from-a-url","Learn how to convert HTML from a URL to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to convert online HTML content to PDF.",[224,75],{"type":20,"children":2337,"toc":2360},[2338,2343,2347,2356],{"type":23,"tag":24,"props":2339,"children":2340},{},[2341],{"type":28,"value":2342},"In this guide, we'll show you how to convert HTML from a URL to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2344,"children":2345},{},[2346],{"type":28,"value":236},{"type":23,"tag":44,"props":2348,"children":2351},{"className":2349,"code":2350,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2352],{"type":23,"tag":36,"props":2353,"children":2354},{"__ignoreMap":8},[2355],{"type":28,"value":2350},{"type":23,"tag":24,"props":2357,"children":2358},{},[2359],{"type":28,"value":250},{"title":8,"searchDepth":61,"depth":61,"links":2361},[],"content:guides:java:okhttp:convert-html-to-pdf-from-a-url.md","guides/java/okhttp/convert-html-to-pdf-from-a-url.md",{"_path":2365,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":257,"description":2366,"language":11,"library":2168,"property":222,"output":14,"related":2367,"default":18,"body":2368,"_type":63,"_id":2394,"_source":65,"_file":2395,"_extension":67},"/guides/java/okhttp/convert-html-to-pdf-from-raw-html","Learn how to convert raw HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to convert HTML content directly to PDF.",[260,74],{"type":20,"children":2369,"toc":2392},[2370,2375,2379,2388],{"type":23,"tag":24,"props":2371,"children":2372},{},[2373],{"type":28,"value":2374},"In this guide, we'll show you how to convert raw HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2376,"children":2377},{},[2378],{"type":28,"value":272},{"type":23,"tag":44,"props":2380,"children":2383},{"className":2381,"code":2382,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"\u003Chtml>\u003Cbody>\u003Ch1>Hello World\u003C/h1>\u003C/body>\u003C/html>\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2384],{"type":23,"tag":36,"props":2385,"children":2386},{"__ignoreMap":8},[2387],{"type":28,"value":2382},{"type":23,"tag":24,"props":2389,"children":2390},{},[2391],{"type":28,"value":286},{"title":8,"searchDepth":61,"depth":61,"links":2393},[],"content:guides:java:okhttp:convert-html-to-pdf-from-raw-html.md","guides/java/okhttp/convert-html-to-pdf-from-raw-html.md",{"_path":2397,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":293,"description":2398,"language":11,"library":2168,"property":295,"output":14,"related":2399,"default":7,"body":2400,"_type":63,"_id":2426,"_source":65,"_file":2427,"_extension":67},"/guides/java/okhttp/define-a-time-limit","Learn how to define a time limit for PDF conversions using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to set timeouts to prevent long-running conversions.",[297,186],{"type":20,"children":2401,"toc":2424},[2402,2407,2411,2420],{"type":23,"tag":24,"props":2403,"children":2404},{},[2405],{"type":28,"value":2406},"In this guide, we'll show you how to define a time limit for PDF conversions using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2408,"children":2409},{},[2410],{"type":28,"value":309},{"type":23,"tag":44,"props":2412,"children":2415},{"className":2413,"code":2414,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient.Builder()\n    .connectTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n    .readTimeout(30, java.util.concurrent.TimeUnit.SECONDS)\n    .build();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"timeout\\\": 30\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2416],{"type":23,"tag":36,"props":2417,"children":2418},{"__ignoreMap":8},[2419],{"type":28,"value":2414},{"type":23,"tag":24,"props":2421,"children":2422},{},[2423],{"type":28,"value":323},{"title":8,"searchDepth":61,"depth":61,"links":2425},[],"content:guides:java:okhttp:define-a-time-limit.md","guides/java/okhttp/define-a-time-limit.md",{"_path":2429,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":330,"description":2430,"language":11,"library":2168,"property":332,"output":14,"related":2431,"default":7,"body":2432,"_type":63,"_id":2458,"_source":65,"_file":2459,"_extension":67},"/guides/java/okhttp/exporting-only-a-specific-set-of-pages","Learn how to export only specific pages from a document when converting to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to select specific pages for export.",[334,335],{"type":20,"children":2433,"toc":2456},[2434,2439,2443,2452],{"type":23,"tag":24,"props":2435,"children":2436},{},[2437],{"type":28,"value":2438},"In this guide, we'll show you how to export only specific pages from a document when converting to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2440,"children":2441},{},[2442],{"type":28,"value":347},{"type":23,"tag":44,"props":2444,"children":2447},{"className":2445,"code":2446,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"pages\\\": \\\"1-3\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2448],{"type":23,"tag":36,"props":2449,"children":2450},{"__ignoreMap":8},[2451],{"type":28,"value":2446},{"type":23,"tag":24,"props":2453,"children":2454},{},[2455],{"type":28,"value":361},{"title":8,"searchDepth":61,"depth":61,"links":2457},[],"content:guides:java:okhttp:exporting-only-a-specific-set-of-pages.md","guides/java/okhttp/exporting-only-a-specific-set-of-pages.md",{"_path":2461,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":368,"description":2462,"language":11,"library":2168,"property":370,"output":14,"related":2463,"default":7,"body":2464,"_type":63,"_id":2490,"_source":65,"_file":2491,"_extension":67},"/guides/java/okhttp/generate-a-document-with-full-height","Learn how to generate a document with full height using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to create full-height PDFs.",[372,335],{"type":20,"children":2465,"toc":2488},[2466,2471,2475,2484],{"type":23,"tag":24,"props":2467,"children":2468},{},[2469],{"type":28,"value":2470},"In this guide, we'll show you how to generate a document with full height using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2472,"children":2473},{},[2474],{"type":28,"value":384},{"type":23,"tag":44,"props":2476,"children":2479},{"className":2477,"code":2478,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"full_height\\\": true\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2480],{"type":23,"tag":36,"props":2481,"children":2482},{"__ignoreMap":8},[2483],{"type":28,"value":2478},{"type":23,"tag":24,"props":2485,"children":2486},{},[2487],{"type":28,"value":398},{"title":8,"searchDepth":61,"depth":61,"links":2489},[],"content:guides:java:okhttp:generate-a-document-with-full-height.md","guides/java/okhttp/generate-a-document-with-full-height.md",{"_path":2493,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":405,"description":2494,"language":11,"library":2168,"property":407,"output":14,"related":2495,"default":7,"body":2496,"_type":63,"_id":2522,"_source":65,"_file":2523,"_extension":67},"/guides/java/okhttp/loading-css-from-a-string","Learn how to load CSS from a string when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to apply inline CSS styling.",[75,409],{"type":20,"children":2497,"toc":2520},[2498,2503,2507,2516],{"type":23,"tag":24,"props":2499,"children":2500},{},[2501],{"type":28,"value":2502},"In this guide, we'll show you how to load CSS from a string when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2504,"children":2505},{},[2506],{"type":28,"value":421},{"type":23,"tag":44,"props":2508,"children":2511},{"className":2509,"code":2510,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"css\\\": \\\"body { font-family: Arial; } h1 { color: blue; }\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2512],{"type":23,"tag":36,"props":2513,"children":2514},{"__ignoreMap":8},[2515],{"type":28,"value":2510},{"type":23,"tag":24,"props":2517,"children":2518},{},[2519],{"type":28,"value":435},{"title":8,"searchDepth":61,"depth":61,"links":2521},[],"content:guides:java:okhttp:loading-css-from-a-string.md","guides/java/okhttp/loading-css-from-a-string.md",{"_path":2525,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":442,"description":2526,"language":11,"library":2168,"property":407,"output":14,"related":2527,"default":7,"body":2528,"_type":63,"_id":2554,"_source":65,"_file":2555,"_extension":67},"/guides/java/okhttp/loading-css-from-a-url","Learn how to load CSS from a URL when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to reference external CSS files.",[74,260],{"type":20,"children":2529,"toc":2552},[2530,2535,2539,2548],{"type":23,"tag":24,"props":2531,"children":2532},{},[2533],{"type":28,"value":2534},"In this guide, we'll show you how to load CSS from a URL when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2536,"children":2537},{},[2538],{"type":28,"value":456},{"type":23,"tag":44,"props":2540,"children":2543},{"className":2541,"code":2542,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"css\\\": \\\"https://example.com/styles.css\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2544],{"type":23,"tag":36,"props":2545,"children":2546},{"__ignoreMap":8},[2547],{"type":28,"value":2542},{"type":23,"tag":24,"props":2549,"children":2550},{},[2551],{"type":28,"value":470},{"title":8,"searchDepth":61,"depth":61,"links":2553},[],"content:guides:java:okhttp:loading-css-from-a-url.md","guides/java/okhttp/loading-css-from-a-url.md",{"_path":2557,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":477,"description":2558,"language":11,"library":2168,"property":479,"output":14,"related":2559,"default":7,"body":2560,"_type":63,"_id":2586,"_source":65,"_file":2587,"_extension":67},"/guides/java/okhttp/loading-javascript-from-a-string","Learn how to load JavaScript from a string when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to include inline JavaScript.",[481,482],{"type":20,"children":2561,"toc":2584},[2562,2567,2571,2580],{"type":23,"tag":24,"props":2563,"children":2564},{},[2565],{"type":28,"value":2566},"In this guide, we'll show you how to load JavaScript from a string when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2568,"children":2569},{},[2570],{"type":28,"value":494},{"type":23,"tag":44,"props":2572,"children":2575},{"className":2573,"code":2574,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"javascript\\\": \\\"document.body.style.backgroundColor = 'red';\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2576],{"type":23,"tag":36,"props":2577,"children":2578},{"__ignoreMap":8},[2579],{"type":28,"value":2574},{"type":23,"tag":24,"props":2581,"children":2582},{},[2583],{"type":28,"value":508},{"title":8,"searchDepth":61,"depth":61,"links":2585},[],"content:guides:java:okhttp:loading-javascript-from-a-string.md","guides/java/okhttp/loading-javascript-from-a-string.md",{"_path":2589,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":515,"description":2590,"language":11,"library":2168,"property":479,"output":14,"related":2591,"default":7,"body":2592,"_type":63,"_id":2618,"_source":65,"_file":2619,"_extension":67},"/guides/java/okhttp/loading-javascript-from-a-url","Learn how to load JavaScript from a URL when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to reference external JavaScript files.",[518,482],{"type":20,"children":2593,"toc":2616},[2594,2599,2603,2612],{"type":23,"tag":24,"props":2595,"children":2596},{},[2597],{"type":28,"value":2598},"In this guide, we'll show you how to load JavaScript from a URL when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2600,"children":2601},{},[2602],{"type":28,"value":530},{"type":23,"tag":44,"props":2604,"children":2607},{"className":2605,"code":2606,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"javascript\\\": \\\"https://example.com/script.js\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2608],{"type":23,"tag":36,"props":2609,"children":2610},{"__ignoreMap":8},[2611],{"type":28,"value":2606},{"type":23,"tag":24,"props":2613,"children":2614},{},[2615],{"type":28,"value":544},{"title":8,"searchDepth":61,"depth":61,"links":2617},[],"content:guides:java:okhttp:loading-javascript-from-a-url.md","guides/java/okhttp/loading-javascript-from-a-url.md",{"_path":2621,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":551,"description":2622,"language":11,"library":2168,"property":553,"output":14,"related":2623,"default":7,"body":2624,"_type":63,"_id":2650,"_source":65,"_file":2651,"_extension":67},"/guides/java/okhttp/protecting-the-generated-pdf","Learn how to protect generated PDFs with passwords using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to secure your PDF documents.",[112,149],{"type":20,"children":2625,"toc":2648},[2626,2631,2635,2644],{"type":23,"tag":24,"props":2627,"children":2628},{},[2629],{"type":28,"value":2630},"In this guide, we'll show you how to protect generated PDFs with passwords using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2632,"children":2633},{},[2634],{"type":28,"value":566},{"type":23,"tag":44,"props":2636,"children":2639},{"className":2637,"code":2638,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"protection\\\": {\\n\" +\n    \"    \\\"user_password\\\": \\\"user123\\\",\\n\" +\n    \"    \\\"owner_password\\\": \\\"owner123\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2640],{"type":23,"tag":36,"props":2641,"children":2642},{"__ignoreMap":8},[2643],{"type":28,"value":2638},{"type":23,"tag":24,"props":2645,"children":2646},{},[2647],{"type":28,"value":580},{"title":8,"searchDepth":61,"depth":61,"links":2649},[],"content:guides:java:okhttp:protecting-the-generated-pdf.md","guides/java/okhttp/protecting-the-generated-pdf.md",{"_path":2653,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":587,"description":2654,"language":11,"library":2168,"property":589,"output":14,"related":2655,"default":7,"body":2656,"_type":63,"_id":2682,"_source":65,"_file":2683,"_extension":67},"/guides/java/okhttp/receive-a-webhook-event","Learn how to receive webhook events when PDF conversion is complete using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to handle asynchronous conversion notifications.",[335,297],{"type":20,"children":2657,"toc":2680},[2658,2663,2667,2676],{"type":23,"tag":24,"props":2659,"children":2660},{},[2661],{"type":28,"value":2662},"In this guide, we'll show you how to receive webhook events when PDF conversion is complete using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2664,"children":2665},{},[2666],{"type":28,"value":602},{"type":23,"tag":44,"props":2668,"children":2671},{"className":2669,"code":2670,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"webhook\\\": {\\n\" +\n    \"    \\\"url\\\": \\\"https://your-server.com/webhook\\\",\\n\" +\n    \"    \\\"secret\\\": \\\"your-secret-key\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2672],{"type":23,"tag":36,"props":2673,"children":2674},{"__ignoreMap":8},[2675],{"type":28,"value":2670},{"type":23,"tag":24,"props":2677,"children":2678},{},[2679],{"type":28,"value":616},{"title":8,"searchDepth":61,"depth":61,"links":2681},[],"content:guides:java:okhttp:receive-a-webhook-event.md","guides/java/okhttp/receive-a-webhook-event.md",{"_path":2685,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":623,"description":2686,"language":11,"library":2168,"property":625,"output":626,"related":2687,"default":7,"body":2688,"_type":63,"_id":2714,"_source":65,"_file":2715,"_extension":67},"/guides/java/okhttp/save-your-pdf-online-and-get-back-a-url","Learn how to save your PDF online and get back a URL using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to store PDFs in cloud storage and retrieve URLs.",[628,187],{"type":20,"children":2689,"toc":2712},[2690,2695,2699,2708],{"type":23,"tag":24,"props":2691,"children":2692},{},[2693],{"type":28,"value":2694},"In this guide, we'll show you how to save your PDF online and get back a URL using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2696,"children":2697},{},[2698],{"type":28,"value":640},{"type":23,"tag":44,"props":2700,"children":2703},{"className":2701,"code":2702,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"output\\\": {\\n\" +\n    \"    \\\"type\\\": \\\"url\\\",\\n\" +\n    \"    \\\"url\\\": \\\"https://your-storage.com/\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2704],{"type":23,"tag":36,"props":2705,"children":2706},{"__ignoreMap":8},[2707],{"type":28,"value":2702},{"type":23,"tag":24,"props":2709,"children":2710},{},[2711],{"type":28,"value":654},{"title":8,"searchDepth":61,"depth":61,"links":2713},[],"content:guides:java:okhttp:save-your-pdf-online-and-get-back-a-url.md","guides/java/okhttp/save-your-pdf-online-and-get-back-a-url.md",{"_path":2717,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":661,"description":2718,"language":11,"library":2168,"property":625,"output":663,"related":2719,"default":7,"body":2720,"_type":63,"_id":2746,"_source":65,"_file":2747,"_extension":67},"/guides/java/okhttp/save-your-pdf-to-your-amazon-s3-bucket","Learn how to save your PDF to your Amazon S3 bucket using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to store PDFs directly in AWS S3.",[335,187],{"type":20,"children":2721,"toc":2744},[2722,2727,2731,2740],{"type":23,"tag":24,"props":2723,"children":2724},{},[2725],{"type":28,"value":2726},"In this guide, we'll show you how to save your PDF to your Amazon S3 bucket using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2728,"children":2729},{},[2730],{"type":28,"value":676},{"type":23,"tag":44,"props":2732,"children":2735},{"className":2733,"code":2734,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"output\\\": {\\n\" +\n    \"    \\\"type\\\": \\\"s3\\\",\\n\" +\n    \"    \\\"bucket\\\": \\\"your-bucket-name\\\",\\n\" +\n    \"    \\\"key\\\": \\\"path/to/document.pdf\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2736],{"type":23,"tag":36,"props":2737,"children":2738},{"__ignoreMap":8},[2739],{"type":28,"value":2734},{"type":23,"tag":24,"props":2741,"children":2742},{},[2743],{"type":28,"value":690},{"title":8,"searchDepth":61,"depth":61,"links":2745},[],"content:guides:java:okhttp:save-your-pdf-to-your-amazon-s3-bucket.md","guides/java/okhttp/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":2749,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":697,"description":2750,"language":11,"library":2168,"property":699,"output":14,"related":2751,"default":7,"body":2752,"_type":63,"_id":2778,"_source":65,"_file":2779,"_extension":67},"/guides/java/okhttp/send-custom-http-headers","Learn how to send custom HTTP headers when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to customize request headers.",[701,17],{"type":20,"children":2753,"toc":2776},[2754,2759,2763,2772],{"type":23,"tag":24,"props":2755,"children":2756},{},[2757],{"type":28,"value":2758},"In this guide, we'll show you how to send custom HTTP headers when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2760,"children":2761},{},[2762],{"type":28,"value":713},{"type":23,"tag":44,"props":2764,"children":2767},{"className":2765,"code":2766,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"headers\\\": {\\n\" +\n    \"    \\\"authorization\\\": \\\"Bearer token123\\\",\\n\" +\n    \"    \\\"user-agent\\\": \\\"MyApp/1.0\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2768],{"type":23,"tag":36,"props":2769,"children":2770},{"__ignoreMap":8},[2771],{"type":28,"value":2766},{"type":23,"tag":24,"props":2773,"children":2774},{},[2775],{"type":28,"value":727},{"title":8,"searchDepth":61,"depth":61,"links":2777},[],"content:guides:java:okhttp:send-custom-http-headers.md","guides/java/okhttp/send-custom-http-headers.md",{"_path":2781,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":734,"description":2782,"language":11,"library":2168,"property":736,"output":14,"related":2783,"default":7,"body":2784,"_type":63,"_id":2810,"_source":65,"_file":2811,"_extension":67},"/guides/java/okhttp/using-cookies","Learn how to use cookies when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to manage cookies during conversion.",[701,16],{"type":20,"children":2785,"toc":2808},[2786,2791,2795,2804],{"type":23,"tag":24,"props":2787,"children":2788},{},[2789],{"type":28,"value":2790},"In this guide, we'll show you how to use cookies when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2792,"children":2793},{},[2794],{"type":28,"value":749},{"type":23,"tag":44,"props":2796,"children":2799},{"className":2797,"code":2798,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"cookies\\\": {\\n\" +\n    \"    \\\"sessionid\\\": \\\"abc123\\\",\\n\" +\n    \"    \\\"user\\\": \\\"john_doe\\\"\\n\" +\n    \"  }\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2800],{"type":23,"tag":36,"props":2801,"children":2802},{"__ignoreMap":8},[2803],{"type":28,"value":2798},{"type":23,"tag":24,"props":2805,"children":2806},{},[2807],{"type":28,"value":763},{"title":8,"searchDepth":61,"depth":61,"links":2809},[],"content:guides:java:okhttp:using-cookies.md","guides/java/okhttp/using-cookies.md",{"_path":2813,"_dir":2166,"_draft":7,"_partial":7,"_locale":8,"title":770,"description":2814,"language":11,"library":2168,"property":772,"output":14,"related":2815,"default":7,"body":2816,"_type":63,"_id":2842,"_source":65,"_file":2843,"_extension":67},"/guides/java/okhttp/waiting-for-a-custom-element-to-be-ready","Learn how to wait for a custom element to be ready when converting HTML to PDF using Java and the OkHTTP library. This guide offers detailed steps with code samples in Java and the OkHTTP library, showing how to handle dynamic content.",[518,481],{"type":20,"children":2817,"toc":2840},[2818,2823,2827,2836],{"type":23,"tag":24,"props":2819,"children":2820},{},[2821],{"type":28,"value":2822},"In this guide, we'll show you how to wait for a custom element to be ready when converting HTML to PDF using Java and the OkHTTP library.",{"type":23,"tag":24,"props":2824,"children":2825},{},[2826],{"type":28,"value":785},{"type":23,"tag":44,"props":2828,"children":2831},{"className":2829,"code":2830,"language":49,"meta":8},[47],"import okhttp3.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\nString apiKey = \"sk_xxxxxxxxxxxx\";\n\nOkHttpClient client = new OkHttpClient();\n\nRequestBody body = RequestBody.create(\n    \"{\\n\" +\n    \"  \\\"source\\\": \\\"https://www.example.com\\\",\\n\" +\n    \"  \\\"wait_for\\\": \\\"#dynamic-content.loaded\\\"\\n\" +\n    \"}\", MediaType.parse(\"application/json\"));\n\nRequest request = new Request.Builder()\n    .url(\"https://api.pdfshift.io/v3/convert/pdf\")\n    .addHeader(\"X-API-Key\", apiKey)\n    .post(body)\n    .build();\n\ntry (Response response = client.newCall(request).execute()) {\n    \n    // Handle errors:\n    if (!response.isSuccessful()) {\n        throw new IOException(\"Request failed with status code \" + response.code());\n    }\n    \n    ResponseBody responseBody = response.body();\n    if (responseBody != null) {\n        java.nio.file.Files.write(\n            java.nio.file.Paths.get(\"result.pdf\"), \n            responseBody.bytes()\n        );\n    }\n    \n    System.out.println(\"The PDF document was generated and saved to result.pdf\");\n}\n",[2832],{"type":23,"tag":36,"props":2833,"children":2834},{"__ignoreMap":8},[2835],{"type":28,"value":2830},{"type":23,"tag":24,"props":2837,"children":2838},{},[2839],{"type":28,"value":799},{"title":8,"searchDepth":61,"depth":61,"links":2841},[],"content:guides:java:okhttp:waiting-for-a-custom-element-to-be-ready.md","guides/java/okhttp/waiting-for-a-custom-element-to-be-ready.md",{"_path":2845,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":2847,"language":11,"library":2848,"property":13,"output":14,"related":2849,"default":18,"body":2850,"_type":63,"_id":2882,"_source":65,"_file":2883,"_extension":67},"/guides/java/retrofit/accessing-secured-pages","retrofit","Learn how to access secured pages using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, highlighting how you can access page protected by basic authentication to convert them to PDF using PDFShift's API.","Retrofit",[16,17],{"type":20,"children":2851,"toc":2880},[2852,2857,2867,2876],{"type":23,"tag":24,"props":2853,"children":2854},{},[2855],{"type":28,"value":2856},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Java and the Retrofit library to convert them to PDF using PDFShift's API.",{"type":23,"tag":24,"props":2858,"children":2859},{},[2860,2861,2866],{"type":28,"value":34},{"type":23,"tag":36,"props":2862,"children":2864},{"className":2863},[],[2865],{"type":28,"value":13},{"type":28,"value":42},{"type":23,"tag":44,"props":2868,"children":2871},{"className":2869,"code":2870,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\nJsonObject auth = new JsonObject();\nauth.addProperty(\"username\", \"user\");\nauth.addProperty(\"password\", \"password\");\npayload.add(\"auth\", auth);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[2872],{"type":23,"tag":36,"props":2873,"children":2874},{"__ignoreMap":8},[2875],{"type":28,"value":2870},{"type":23,"tag":24,"props":2877,"children":2878},{},[2879],{"type":28,"value":59},{"title":8,"searchDepth":61,"depth":61,"links":2881},[],"content:guides:java:retrofit:accessing-secured-pages.md","guides/java/retrofit/accessing-secured-pages.md",{"_path":2885,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":70,"description":2886,"language":11,"library":2848,"property":72,"output":14,"related":2887,"default":7,"body":2888,"_type":63,"_id":2914,"_source":65,"_file":2915,"_extension":67},"/guides/java/retrofit/adding-a-custom-header-or-footer","Learn how to add custom headers and footers to your PDFs using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to customize PDF appearance with headers and footers.",[74,75],{"type":20,"children":2889,"toc":2912},[2890,2895,2899,2908],{"type":23,"tag":24,"props":2891,"children":2892},{},[2893],{"type":28,"value":2894},"In this guide, we'll show you how to add custom headers and footers to your PDFs using Java and the Retrofit library.",{"type":23,"tag":24,"props":2896,"children":2897},{},[2898],{"type":28,"value":87},{"type":23,"tag":44,"props":2900,"children":2903},{"className":2901,"code":2902,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\nJsonObject header = new JsonObject();\nheader.addProperty(\"content\", \"\u003Cdiv style='text-align: center;'>Header Content\u003C/div>\");\nheader.addProperty(\"height\", \"20mm\");\nJsonObject footer = new JsonObject();\nfooter.addProperty(\"content\", \"\u003Cdiv style='text-align: center;'>Footer Content\u003C/div>\");\nfooter.addProperty(\"height\", \"20mm\");\npayload.add(\"header\", header);\npayload.add(\"footer\", footer);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[2904],{"type":23,"tag":36,"props":2905,"children":2906},{"__ignoreMap":8},[2907],{"type":28,"value":2902},{"type":23,"tag":24,"props":2909,"children":2910},{},[2911],{"type":28,"value":101},{"title":8,"searchDepth":61,"depth":61,"links":2913},[],"content:guides:java:retrofit:adding-a-custom-header-or-footer.md","guides/java/retrofit/adding-a-custom-header-or-footer.md",{"_path":2917,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":108,"description":2918,"language":11,"library":2848,"property":110,"output":14,"related":2919,"default":7,"body":2920,"_type":63,"_id":2946,"_source":65,"_file":2947,"_extension":67},"/guides/java/retrofit/adding-a-text-watermark","Learn how to add text watermarks to your PDFs using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to apply text watermarks to protect your documents.",[112,113],{"type":20,"children":2921,"toc":2944},[2922,2927,2931,2940],{"type":23,"tag":24,"props":2923,"children":2924},{},[2925],{"type":28,"value":2926},"In this guide, we'll show you how to add text watermarks to your PDFs using Java and the Retrofit library.",{"type":23,"tag":24,"props":2928,"children":2929},{},[2930],{"type":28,"value":125},{"type":23,"tag":44,"props":2932,"children":2935},{"className":2933,"code":2934,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\nJsonObject watermark = new JsonObject();\nwatermark.addProperty(\"text\", \"CONFIDENTIAL\");\nwatermark.addProperty(\"opacity\", 0.3);\nwatermark.addProperty(\"size\", \"20px\");\nwatermark.addProperty(\"color\", \"#000000\");\npayload.add(\"watermark\", watermark);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[2936],{"type":23,"tag":36,"props":2937,"children":2938},{"__ignoreMap":8},[2939],{"type":28,"value":2934},{"type":23,"tag":24,"props":2941,"children":2942},{},[2943],{"type":28,"value":139},{"title":8,"searchDepth":61,"depth":61,"links":2945},[],"content:guides:java:retrofit:adding-a-text-watermark.md","guides/java/retrofit/adding-a-text-watermark.md",{"_path":2949,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":146,"description":2950,"language":11,"library":2848,"property":110,"output":14,"related":2951,"default":7,"body":2952,"_type":63,"_id":2978,"_source":65,"_file":2979,"_extension":67},"/guides/java/retrofit/adding-an-image-watermark","Learn how to add image watermarks to your PDFs using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to apply image watermarks to protect your documents.",[149,113],{"type":20,"children":2953,"toc":2976},[2954,2959,2963,2972],{"type":23,"tag":24,"props":2955,"children":2956},{},[2957],{"type":28,"value":2958},"In this guide, we'll show you how to add image watermarks to your PDFs using Java and the Retrofit library.",{"type":23,"tag":24,"props":2960,"children":2961},{},[2962],{"type":28,"value":161},{"type":23,"tag":44,"props":2964,"children":2967},{"className":2965,"code":2966,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\nJsonObject watermark = new JsonObject();\nwatermark.addProperty(\"image\", \"https://example.com/watermark.png\");\nwatermark.addProperty(\"opacity\", 0.5);\nwatermark.addProperty(\"position\", \"center\");\npayload.add(\"watermark\", watermark);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[2968],{"type":23,"tag":36,"props":2969,"children":2970},{"__ignoreMap":8},[2971],{"type":28,"value":2966},{"type":23,"tag":24,"props":2973,"children":2974},{},[2975],{"type":28,"value":175},{"title":8,"searchDepth":61,"depth":61,"links":2977},[],"content:guides:java:retrofit:adding-an-image-watermark.md","guides/java/retrofit/adding-an-image-watermark.md",{"_path":2981,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":182,"description":2982,"language":11,"library":2848,"property":184,"output":14,"related":2983,"default":7,"body":2984,"_type":63,"_id":3010,"_source":65,"_file":3011,"_extension":67},"/guides/java/retrofit/avoid-conversion-on-error","Learn how to avoid conversion on error using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to handle conversion errors gracefully.",[186,187],{"type":20,"children":2985,"toc":3008},[2986,2991,2995,3004],{"type":23,"tag":24,"props":2987,"children":2988},{},[2989],{"type":28,"value":2990},"In this guide, we'll show you how to avoid conversion on error using Java and the Retrofit library.",{"type":23,"tag":24,"props":2992,"children":2993},{},[2994],{"type":28,"value":199},{"type":23,"tag":44,"props":2996,"children":2999},{"className":2997,"code":2998,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\npayload.addProperty(\"continue_on_error\", false);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[3000],{"type":23,"tag":36,"props":3001,"children":3002},{"__ignoreMap":8},[3003],{"type":28,"value":2998},{"type":23,"tag":24,"props":3005,"children":3006},{},[3007],{"type":28,"value":213},{"title":8,"searchDepth":61,"depth":61,"links":3009},[],"content:guides:java:retrofit:avoid-conversion-on-error.md","guides/java/retrofit/avoid-conversion-on-error.md",{"_path":3013,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":220,"description":3014,"language":11,"library":2848,"property":222,"output":14,"related":3015,"default":18,"body":3016,"_type":63,"_id":3042,"_source":65,"_file":3043,"_extension":67},"/guides/java/retrofit/convert-html-to-pdf-from-a-url","Learn how to convert HTML from a URL to PDF using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to convert online HTML content to PDF.",[224,75],{"type":20,"children":3017,"toc":3040},[3018,3023,3027,3036],{"type":23,"tag":24,"props":3019,"children":3020},{},[3021],{"type":28,"value":3022},"In this guide, we'll show you how to convert HTML from a URL to PDF using Java and the Retrofit library.",{"type":23,"tag":24,"props":3024,"children":3025},{},[3026],{"type":28,"value":236},{"type":23,"tag":44,"props":3028,"children":3031},{"className":3029,"code":3030,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[3032],{"type":23,"tag":36,"props":3033,"children":3034},{"__ignoreMap":8},[3035],{"type":28,"value":3030},{"type":23,"tag":24,"props":3037,"children":3038},{},[3039],{"type":28,"value":250},{"title":8,"searchDepth":61,"depth":61,"links":3041},[],"content:guides:java:retrofit:convert-html-to-pdf-from-a-url.md","guides/java/retrofit/convert-html-to-pdf-from-a-url.md",{"_path":3045,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":257,"description":3046,"language":11,"library":2848,"property":222,"output":14,"related":3047,"default":18,"body":3048,"_type":63,"_id":3074,"_source":65,"_file":3075,"_extension":67},"/guides/java/retrofit/convert-html-to-pdf-from-raw-html","Learn how to convert raw HTML to PDF using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to convert HTML content directly to PDF.",[260,74],{"type":20,"children":3049,"toc":3072},[3050,3055,3059,3068],{"type":23,"tag":24,"props":3051,"children":3052},{},[3053],{"type":28,"value":3054},"In this guide, we'll show you how to convert raw HTML to PDF using Java and the Retrofit library.",{"type":23,"tag":24,"props":3056,"children":3057},{},[3058],{"type":28,"value":272},{"type":23,"tag":44,"props":3060,"children":3063},{"className":3061,"code":3062,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"\u003Chtml>\u003Cbody>\u003Ch1>Hello World\u003C/h1>\u003C/body>\u003C/html>\");\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[3064],{"type":23,"tag":36,"props":3065,"children":3066},{"__ignoreMap":8},[3067],{"type":28,"value":3062},{"type":23,"tag":24,"props":3069,"children":3070},{},[3071],{"type":28,"value":286},{"title":8,"searchDepth":61,"depth":61,"links":3073},[],"content:guides:java:retrofit:convert-html-to-pdf-from-raw-html.md","guides/java/retrofit/convert-html-to-pdf-from-raw-html.md",{"_path":3077,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":293,"description":3078,"language":11,"library":2848,"property":295,"output":14,"related":3079,"default":7,"body":3080,"_type":63,"_id":3106,"_source":65,"_file":3107,"_extension":67},"/guides/java/retrofit/define-a-time-limit","Learn how to define a time limit for PDF conversions using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to set timeouts to prevent long-running conversions.",[297,186],{"type":20,"children":3081,"toc":3104},[3082,3087,3091,3100],{"type":23,"tag":24,"props":3083,"children":3084},{},[3085],{"type":28,"value":3086},"In this guide, we'll show you how to define a time limit for PDF conversions using Java and the Retrofit library.",{"type":23,"tag":24,"props":3088,"children":3089},{},[3090],{"type":28,"value":309},{"type":23,"tag":44,"props":3092,"children":3095},{"className":3093,"code":3094,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\npayload.addProperty(\"timeout\", 30);\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[3096],{"type":23,"tag":36,"props":3097,"children":3098},{"__ignoreMap":8},[3099],{"type":28,"value":3094},{"type":23,"tag":24,"props":3101,"children":3102},{},[3103],{"type":28,"value":323},{"title":8,"searchDepth":61,"depth":61,"links":3105},[],"content:guides:java:retrofit:define-a-time-limit.md","guides/java/retrofit/define-a-time-limit.md",{"_path":3109,"_dir":2846,"_draft":7,"_partial":7,"_locale":8,"title":330,"description":3110,"language":11,"library":2848,"property":332,"output":14,"related":3111,"default":7,"body":3112,"_type":63,"_id":3138,"_source":65,"_file":3139,"_extension":67},"/guides/java/retrofit/exporting-only-a-specific-set-of-pages","Learn how to export only specific pages from a document when converting to PDF using Java and the Retrofit library. This guide offers detailed steps with code samples in Java and the Retrofit library, showing how to select specific pages for export.",[334,335],{"type":20,"children":3113,"toc":3136},[3114,3119,3123,3132],{"type":23,"tag":24,"props":3115,"children":3116},{},[3117],{"type":28,"value":3118},"In this guide, we'll show you how to export only specific pages from a document when converting to PDF using Java and the Retrofit library.",{"type":23,"tag":24,"props":3120,"children":3121},{},[3122],{"type":28,"value":347},{"type":23,"tag":44,"props":3124,"children":3127},{"className":3125,"code":3126,"language":49,"meta":8},[47],"import retrofit2.*;\nimport retrofit2.converter.gson.GsonConverterFactory;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n// You can get an API key at https://pdfshift.io\npublic interface PdfShiftApi {\n    @POST(\"v3/convert/pdf\")\n    Call\u003CResponseBody> convertToPdf(\n        @Header(\"X-API-Key\") String apiKey,\n        @Body JsonObject body\n    );\n}\n\n// Usage\nGson gson = new GsonBuilder().create();\nRetrofit retrofit = new Retrofit.Builder()\n    .baseUrl(\"https://api.pdfshift.io/\")\n    .addConverterFactory(GsonConverterFactory.create(gson))\n    .build();\n\nPdfShiftApi api = retrofit.create(PdfShiftApi.class);\n\nJsonObject payload = new JsonObject();\npayload.addProperty(\"source\", \"https://www.example.com\");\npayload.addProperty(\"pages\", \"1-3\");\n\nCall\u003CResponseBody> call = api.convertToPdf(\"sk_xxxxxxxxxxxx\", payload);\nResponse\u003CResponseBody> response = call.execute();\n\n// Handle errors:\nif (!response.isSuccessful()) {\n    throw new IOException(\"Request failed with status code \" + response.code());\n}\n\nResponseBody responseBody = response.body();\nif (responseBody != null) {\n    java.nio.file.Files.write(\n        java.nio.file.Paths.get(\"result.pdf\"), \n        responseBody.bytes()\n    );\n}\n\nSystem.out.println(\"The PDF document was generated and saved to result.pdf\");\n",[3128],{"type":23,"tag":36,"props":3129,"children":3130},{"__ignoreMap":8},[3131],{"type":28,"value":3126},{"type":23,"tag":24,"props":3133,"children":3134},{},[3135],{"type":28,"value":361},{"title":8,"searchDepth":61,"depth":61,"links":3137},[],"content:guides:java:retrofit:exporting-only-a-specific-set-of-pages.md","guides/java/retrofit/exporting-only-a-specific-set-of-pages.md",1785426826480]