{"id":181,"date":"2007-08-29T00:08:00","date_gmt":"2007-08-29T00:08:00","guid":{"rendered":"\/lisa\/post\/2007\/08\/29\/A-Tad-More-About-PDF-and-Reports-as-Document-Sections.aspx"},"modified":"2021-08-30T15:08:49","modified_gmt":"2021-08-30T22:08:49","slug":"a-tad-more-about-pdf-and-reports-as-document-sections","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2007\/08\/29\/a-tad-more-about-pdf-and-reports-as-document-sections\/","title":{"rendered":"A Tad More About PDF and Reports-as-Document-Sections"},"content":{"rendered":"<p>I&#8217;ve been helping folks to <a title=\"PDFPower article\" href=\"\/articles\/pdfpower\/\">get PDF output for years using Ghostscript<\/a>.\u00a0 One of the things I like about it is that it\u00a0answers the <a title=\"The one about multiple sets of printing instructions\" href=\"\/lisa\/2007\/08\/11\/Reporting-Convergences-Chapter-The-one-about-multiple-sets-of-printing-instructions\/\">multiple sets of printing instructions in a document question<\/a> very naturally; you can concatenate multiple postscript files together into one PDF document, and each &#8220;document section&#8221; obeys the rules with which you printed it, no problem.<\/p>\n<p>PDFListener and <a title=\"Post about PDFClass source added to PDFListener article\" href=\"\/lisa\/2007\/08\/05\/PDF-Power-Redux-Redacted-and-Reduced\/\">PDFClass<\/a> exploit this capability for VFP report forms,\u00a0by supplying a collection of reports (in PDFListener&#8217;s case, inherited from FFC&#8217;s <a title=\"docs for _ReportListener Base Foundation Class\" href=\"\/lisa\/2007\/08\/11\/Reporting-Convergences-Chapter-The-one-about-multiple-sets-of-printing-instructions\/\">_ReportListener<\/a>) to help you manage the process of running multiple reports in a sequence to postscript files, sending appropriate instructions to Ghostscript, and tidying up.<\/p>\n<p>This isn&#8217;t a VFP-specific reporting scenario, of course.\u00a0 In fact I&#8217;ve been answering lots of RS forum posts with advice like this recently:<\/p>\n<blockquote><p>You can find a demo app with code for printing reports without UI, using the ReportViewer control, on this page: <a href=\"http:\/\/www.gotreportviewer.com\/\">http:\/\/www.gotreportviewer.com\/<\/a>. I expect it can be adapted to go to a ps printer driver and given target file information (or the ps driver setup can be set to go to a file target explicitly &#8212; but that doesn&#8217;t seem thread safe to me).<\/p>\n<p>Then you can use standard postscript to PDF capabilites to convert the string of files you just wrote out.\u00a0 I use Ghostscript to do this, you don&#8217;t need Adobe and you don&#8217;t need any UI for this step either. You can learn about Ghostscript here <a href=\"http:\/\/www.ghostscript.com\/awki\">http:\/\/www.ghostscript.com\/awki<\/a>\u00a0 There is a overview of command-line switches here<br \/>\n<a href=\"http:\/\/ghostscript.com\/doc\/8.54\/Use.htm#Options\">http:\/\/ghostscript.com\/doc\/8.54\/Use.htm#Options<\/a> &#8212; for your purposes, pay particular attention to the ability to create a commandfile listing all the<br \/>\nswitches as well as all the files you wish to process in this run (more flexible than listing the files directly on the command line if your list may be long).\u00a0 You may prefer to use the API directly (DLLs rather than command-line).\u00a0 It&#8217;s quite extensive.<\/p><\/blockquote>\n<p>The process is simple, and really does work quite well.<\/p>\n<p>But there&#8217;s an important difference between what VFP reports can do and what Reporting Services can do: in VFP&#8217;s case, we can&#8217;t get PDF output natively.\u00a0On the other hand,\u00a0 RS provides PDF as a native export format.\u00a0 That means RS folks don&#8217;t have to go all the way down to the PS file level to use PDF files as document sections if they don&#8217;t want to.<\/p>\n<p>While I think there is stuff in the Ghostscript API that will let you concatenate PDF files properly into a single document (stripping off the extra header information from each, or whatever it takes), I&#8217;m pleased to say that I&#8217;ve found another utility recently that does this job with no fuss at all.<\/p>\n<h5>Take a look at <a title=\"PDFTK home page\" href=\"http:\/\/www.accesspdf.com\/pdftk\/index.html\">PDFTK<\/a>.<\/h5>\n<p>PDFTK is a GPL,\u00a0cross-platform\u00a0toolkit for PDFs with no reliance on Acrobat.\u00a0 And if you&#8217;re working with PDFs as your input files, you have no reliance on printer setups either; that part is already done by the time you &#8220;get here&#8221;.\u00a0\u00a0 I&#8217;ll quote from their relevant examples:<\/p>\n<p class=\"code\"><span style=\"color: green;\">rem Merge Two or More PDFs into a New Document<\/span><br \/>\npdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf<br \/>\n<span style=\"color: green;\">rem or (Using Handles):<\/span><br \/>\npdftk A=1.pdf B=2.pdf cat A B output 12.pdf<br \/>\n<span style=\"color: green;\">rem or (Using Wildcards):<\/span><br \/>\npdftk *.pdf cat output combined.pdf<\/p>\n<p>&nbsp;<\/p>\n<p>What could be easier?<\/p>\n<p>What&#8217;s that you say? You don&#8217;t like the idea of shelling out to <em>unmanaged code<\/em>\u00a0to perform this task?<\/p>\n<p>And I thought java purists were annoying&#8230;<\/p>\n<h5>Retro is the new future<\/h5>\n<p>Quit whining, learn about true interop, and make <a title=\"set knee-jerk off\" href=\"\/lisa\/2007\/08\/13\/Vista-and-the-Managed-Developer-and-more-mgmt-musings\/\">the best tool for the job<\/a> your new mantra.<\/p>\n<p>Invoke\u00a0PDFTK with Windows Power Shell if it makes you feel more <em>au courant<\/em>, more <em>comme il faut<\/em>, more with-it, or more&#8230; powerful.<\/p>\n<p>I figure, since\u00a0it&#8217;s taken Windows until now (Windows Server 2008?) to come up with something integrated into the OS\u00a0that\u00a0<a title=\"James O'Neill on PowerShell and pipelines\" href=\"http:\/\/blogs.technet.com\/jamesone\/archive\/2007\/08\/28\/powershell-again-pipes-and-this-is-not-an-output\/\">handles a pipeline<\/a> like *nix always did,\u00a0PowerShell is\u00a0probably pretty good&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been helping folks to get PDF output for years using Ghostscript.\u00a0 One of the things I like about it is that it\u00a0answers the multiple sets of printing instructions in a document question very naturally; you can concatenate multiple postscript files together into one PDF document, and each &#8220;document section&#8221; obeys the rules with which<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2007\/08\/29\/a-tad-more-about-pdf-and-reports-as-document-sections\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5,6,9],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-general-techspeak","category-reporting","category-sql-server","category-visual-foxpro"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":2,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/181\/revisions\/431"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}