{"id":6424,"date":"2022-09-03T06:13:01","date_gmt":"2022-09-03T00:43:01","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/"},"modified":"2022-09-03T06:13:01","modified_gmt":"2022-09-03T00:43:01","slug":"solved-create-a-pdf-file-in-memory","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/","title":{"rendered":"[Solved] Create a PDF file in memory"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-26412278\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"26412278\" data-parentid=\"26409645\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>this solution, using itext, primefaces media. <\/p>\n<pre><code> &lt;p:dataTable widgetVar=\"tb1\" id=\"tablaFact\" var=\"item\" selection=\"#{listadoFacturasMB.selectedFactura}\" selectionMode=\"single\"  paginator=\"true\" \n   rows=\"20\" rowKey=\"#{item.idFactura}\" value=\"#{listadoFacturasMB.facturaUtilList}\"&gt; \n\n       &lt;p:ajax event=\"rowSelect\" update=\":frm1:growl :frm1:dialog\" oncomplete=\"PF('servDialog').show()\" listener=\"#{listadoFacturasMB.createPDF}\"\/&gt;                         \n\n        &lt;f:facet name=\"header\"&gt;\n            &lt;h:outputText value=\"Listado de facturas (Cantidad: #{listadoFacturasMB.cantFact})\"\/&gt;\n        &lt;\/f:facet&gt;\n\n        &lt;p:column style=\"width:10%\"  headerText=\"Nro\" sortBy=\"noFactura\" filterFunction=\"#{utilMB.filterByName}\"  filterBy=\"noFactura\" filterMatchMode=\"contains\"&gt;                          \n                        &lt;h:outputText value=\"#{item.noFactura}\"\/&gt;\n        &lt;\/p:column&gt;                                                                                     \n       &lt;\/p:dataTable&gt; \n\n             &lt;p:dialog  resizable=\"false\" closeOnEscape=\"true\" appendTo=\"@(body)\" modal=\"true\" id=\"dialog\" header=\"Detalles de la factura\" widgetVar=\"servDialog\" width=\"1000px\" height=\"630px\"&gt;  \n                &lt;p:media cache=\"false\" value=\"#{listadoFacturasMB.fileDownload}\" width=\"100%\"  height=\"600px\" player=\"pdf\"&gt;\n                    &lt;f:param name=\"id\" value=\"#{listadoFacturasMB.idFile}\" \/&gt;\n                &lt;\/p:media&gt;                   \n            &lt;\/p:dialog&gt; \n<\/code><\/pre>\n<p>Backing bean:<\/p>\n<pre><code>private StreamedContent fileDownload;\n\n  public void createPDF() {\n    try {       \n        Document pdf = new Document(PageSize.LETTER);\n        ByteArrayOutputStream baos = new ByteArrayOutputStream();\n        PdfWriter writer;\n        writer = PdfWriter.getInstance(pdf, baos);\n        if (!pdf.isOpen()) {\n            pdf.open();\n        }\n\n       \/\/Adding content to pdf\n\n        pdf.close();\n        String fileName = \"factura No \" + this.selectedFactura.getNoFactura();\n\n        InputStream stream = new ByteArrayInputStream(baos.toByteArray());\n        fileDownload = new DefaultStreamedContent(stream, \"application\/pdf\", fileName);\n\n    } catch (Exception e) {\n        JsfUtil.addErrorMessage(e, \"Error: createPDF() \" + e.getMessage());\n    }\n}\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">0<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Create a PDF file in memory <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] this solution, using itext, primefaces media. &lt;p:dataTable widgetVar=&#8221;tb1&#8243; id=&#8221;tablaFact&#8221; var=&#8221;item&#8221; selection=&#8221;#{listadoFacturasMB.selectedFactura}&#8221; selectionMode=&#8221;single&#8221; paginator=&#8221;true&#8221; rows=&#8221;20&#8243; rowKey=&#8221;#{item.idFactura}&#8221; value=&#8221;#{listadoFacturasMB.facturaUtilList}&#8221;&gt; &lt;p:ajax event=&#8221;rowSelect&#8221; update=&#8221;:frm1:growl :frm1:dialog&#8221; oncomplete=&#8221;PF(&#8216;servDialog&#8217;).show()&#8221; listener=&#8221;#{listadoFacturasMB.createPDF}&#8221;\/&gt; &lt;f:facet name=&#8221;header&#8221;&gt; &lt;h:outputText value=&#8221;Listado de facturas (Cantidad: #{listadoFacturasMB.cantFact})&#8221;\/&gt; &lt;\/f:facet&gt; &lt;p:column style=&#8221;width:10%&#8221; headerText=&#8221;Nro&#8221; sortBy=&#8221;noFactura&#8221; filterFunction=&#8221;#{utilMB.filterByName}&#8221; filterBy=&#8221;noFactura&#8221; filterMatchMode=&#8221;contains&#8221;&gt; &lt;h:outputText value=&#8221;#{item.noFactura}&#8221;\/&gt; &lt;\/p:column&gt; &lt;\/p:dataTable&gt; &lt;p:dialog resizable=&#8221;false&#8221; closeOnEscape=&#8221;true&#8221; appendTo=&#8221;@(body)&#8221; modal=&#8221;true&#8221; id=&#8221;dialog&#8221; header=&#8221;Detalles de la factura&#8221; widgetVar=&#8221;servDialog&#8221; width=&#8221;1000px&#8221; &#8230; <a title=\"[Solved] Create a PDF file in memory\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/\" aria-label=\"More on [Solved] Create a PDF file in memory\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1773,323,1772,489,1020],"class_list":["post-6424","post","type-post","status-publish","format-standard","hentry","category-solved","tag-itext","tag-java","tag-jsf","tag-pdf","tag-primefaces"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] Create a PDF file in memory - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Create a PDF file in memory - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] this solution, using itext, primefaces media. &lt;p:dataTable widgetVar=&quot;tb1&quot; id=&quot;tablaFact&quot; var=&quot;item&quot; selection=&quot;#{listadoFacturasMB.selectedFactura}&quot; selectionMode=&quot;single&quot; paginator=&quot;true&quot; rows=&quot;20&quot; rowKey=&quot;#{item.idFactura}&quot; value=&quot;#{listadoFacturasMB.facturaUtilList}&quot;&gt; &lt;p:ajax event=&quot;rowSelect&quot; update=&quot;:frm1:growl :frm1:dialog&quot; oncomplete=&quot;PF(&#039;servDialog&#039;).show()&quot; listener=&quot;#{listadoFacturasMB.createPDF}&quot;\/&gt; &lt;f:facet name=&quot;header&quot;&gt; &lt;h:outputText value=&quot;Listado de facturas (Cantidad: #{listadoFacturasMB.cantFact})&quot;\/&gt; &lt;\/f:facet&gt; &lt;p:column style=&quot;width:10%&quot; headerText=&quot;Nro&quot; sortBy=&quot;noFactura&quot; filterFunction=&quot;#{utilMB.filterByName}&quot; filterBy=&quot;noFactura&quot; filterMatchMode=&quot;contains&quot;&gt; &lt;h:outputText value=&quot;#{item.noFactura}&quot;\/&gt; &lt;\/p:column&gt; &lt;\/p:dataTable&gt; &lt;p:dialog resizable=&quot;false&quot; closeOnEscape=&quot;true&quot; appendTo=&quot;@(body)&quot; modal=&quot;true&quot; id=&quot;dialog&quot; header=&quot;Detalles de la factura&quot; widgetVar=&quot;servDialog&quot; width=&quot;1000px&quot; ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-03T00:43:01+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Create a PDF file in memory\",\"datePublished\":\"2022-09-03T00:43:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/\"},\"wordCount\":24,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"itext\",\"java\",\"jsf\",\"pdf\",\"primefaces\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/\",\"name\":\"[Solved] Create a PDF file in memory - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-09-03T00:43:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-create-a-pdf-file-in-memory\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Create a PDF file in memory\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Create a PDF file in memory - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Create a PDF file in memory - JassWeb","og_description":"[ad_1] this solution, using itext, primefaces media. &lt;p:dataTable widgetVar=\"tb1\" id=\"tablaFact\" var=\"item\" selection=\"#{listadoFacturasMB.selectedFactura}\" selectionMode=\"single\" paginator=\"true\" rows=\"20\" rowKey=\"#{item.idFactura}\" value=\"#{listadoFacturasMB.facturaUtilList}\"&gt; &lt;p:ajax event=\"rowSelect\" update=\":frm1:growl :frm1:dialog\" oncomplete=\"PF('servDialog').show()\" listener=\"#{listadoFacturasMB.createPDF}\"\/&gt; &lt;f:facet name=\"header\"&gt; &lt;h:outputText value=\"Listado de facturas (Cantidad: #{listadoFacturasMB.cantFact})\"\/&gt; &lt;\/f:facet&gt; &lt;p:column style=\"width:10%\" headerText=\"Nro\" sortBy=\"noFactura\" filterFunction=\"#{utilMB.filterByName}\" filterBy=\"noFactura\" filterMatchMode=\"contains\"&gt; &lt;h:outputText value=\"#{item.noFactura}\"\/&gt; &lt;\/p:column&gt; &lt;\/p:dataTable&gt; &lt;p:dialog resizable=\"false\" closeOnEscape=\"true\" appendTo=\"@(body)\" modal=\"true\" id=\"dialog\" header=\"Detalles de la factura\" widgetVar=\"servDialog\" width=\"1000px\" ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/","og_site_name":"JassWeb","article_published_time":"2022-09-03T00:43:01+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Create a PDF file in memory","datePublished":"2022-09-03T00:43:01+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/"},"wordCount":24,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["itext","java","jsf","pdf","primefaces"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/","url":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/","name":"[Solved] Create a PDF file in memory - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-03T00:43:01+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-create-a-pdf-file-in-memory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Create a PDF file in memory"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=6424"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6424\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=6424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=6424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=6424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}