[{"data":1,"prerenderedAt":142},["Reactive",2],{"/guides/java/netty/convert-html-to-pdf-from-raw-html":3,"/guides/java/netty/convert-html-to-pdf-from-raw-html-related":60},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"property":12,"output":13,"related":14,"default":17,"body":18,"_type":55,"_id":56,"_source":57,"_file":58,"_extension":59},"/guides/java/netty/convert-html-to-pdf-from-raw-html","netty",false,"","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.","Java","Netty","source","pdf",[15,16],"convert-html-to-pdf-from-a-url","loading-css-from-a-string",true,{"type":19,"children":20,"toc":52},"root",[21,29,34,47],{"type":22,"tag":23,"props":24,"children":25},"element","p",{},[26],{"type":27,"value":28},"text","In this guide, we'll show you how to convert raw HTML to PDF using Java and the Netty library.",{"type":22,"tag":23,"props":30,"children":31},{},[32],{"type":27,"value":33},"Converting raw HTML content to PDF is useful when you have HTML content that isn't hosted on a web server.",{"type":22,"tag":35,"props":36,"children":41},"pre",{"className":37,"code":39,"language":40,"meta":7},[38],"language-java","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","java",[42],{"type":22,"tag":43,"props":44,"children":45},"code",{"__ignoreMap":7},[46],{"type":27,"value":39},{"type":22,"tag":23,"props":48,"children":49},{},[50],{"type":27,"value":51},"This allows you to convert HTML content directly to PDF without needing a URL.",{"title":7,"searchDepth":53,"depth":53,"links":54},2,[],"markdown","content:guides:java:netty:convert-html-to-pdf-from-raw-html.md","content","guides/java/netty/convert-html-to-pdf-from-raw-html.md","md",[61,65,69,73,77,81,85,86,90,94,98,102,106,110,114,118,122,126,130,134,138],{"_path":62,"title":63,"language":10,"library":11,"_id":64},"/guides/java/netty/accessing-secured-pages","Accessing secured pages","content:guides:java:netty:accessing-secured-pages.md",{"_path":66,"title":67,"language":10,"library":11,"_id":68},"/guides/java/netty/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:java:netty:adding-a-custom-header-or-footer.md",{"_path":70,"title":71,"language":10,"library":11,"_id":72},"/guides/java/netty/adding-a-text-watermark","Adding a text watermark","content:guides:java:netty:adding-a-text-watermark.md",{"_path":74,"title":75,"language":10,"library":11,"_id":76},"/guides/java/netty/adding-an-image-watermark","Adding an image watermark","content:guides:java:netty:adding-an-image-watermark.md",{"_path":78,"title":79,"language":10,"library":11,"_id":80},"/guides/java/netty/avoid-conversion-on-error","Avoid conversion on error","content:guides:java:netty:avoid-conversion-on-error.md",{"_path":82,"title":83,"language":10,"library":11,"_id":84},"/guides/java/netty/convert-html-to-pdf-from-a-url","Convert HTML to PDF from a URL","content:guides:java:netty:convert-html-to-pdf-from-a-url.md",{"_path":4,"title":8,"language":10,"library":11,"_id":56},{"_path":87,"title":88,"language":10,"library":11,"_id":89},"/guides/java/netty/define-a-time-limit","Define a time limit","content:guides:java:netty:define-a-time-limit.md",{"_path":91,"title":92,"language":10,"library":11,"_id":93},"/guides/java/netty/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:java:netty:exporting-only-a-specific-set-of-pages.md",{"_path":95,"title":96,"language":10,"library":11,"_id":97},"/guides/java/netty/generate-a-document-with-full-height","Generate a document with full height","content:guides:java:netty:generate-a-document-with-full-height.md",{"_path":99,"title":100,"language":10,"library":11,"_id":101},"/guides/java/netty/loading-css-from-a-string","Loading CSS from a string","content:guides:java:netty:loading-css-from-a-string.md",{"_path":103,"title":104,"language":10,"library":11,"_id":105},"/guides/java/netty/loading-css-from-a-url","Loading CSS from a URL","content:guides:java:netty:loading-css-from-a-url.md",{"_path":107,"title":108,"language":10,"library":11,"_id":109},"/guides/java/netty/loading-javascript-from-a-string","Loading JavaScript from a string","content:guides:java:netty:loading-javascript-from-a-string.md",{"_path":111,"title":112,"language":10,"library":11,"_id":113},"/guides/java/netty/loading-javascript-from-a-url","Loading JavaScript from a URL","content:guides:java:netty:loading-javascript-from-a-url.md",{"_path":115,"title":116,"language":10,"library":11,"_id":117},"/guides/java/netty/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:java:netty:protecting-the-generated-pdf.md",{"_path":119,"title":120,"language":10,"library":11,"_id":121},"/guides/java/netty/receive-a-webhook-event","Receive a webhook event","content:guides:java:netty:receive-a-webhook-event.md",{"_path":123,"title":124,"language":10,"library":11,"_id":125},"/guides/java/netty/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:java:netty:save-your-pdf-online-and-get-back-a-url.md",{"_path":127,"title":128,"language":10,"library":11,"_id":129},"/guides/java/netty/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 bucket","content:guides:java:netty:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":131,"title":132,"language":10,"library":11,"_id":133},"/guides/java/netty/send-custom-http-headers","Send custom HTTP headers","content:guides:java:netty:send-custom-http-headers.md",{"_path":135,"title":136,"language":10,"library":11,"_id":137},"/guides/java/netty/using-cookies","Using cookies","content:guides:java:netty:using-cookies.md",{"_path":139,"title":140,"language":10,"library":11,"_id":141},"/guides/java/netty/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:java:netty:waiting-for-a-custom-element-to-be-ready.md",1780405108558]