Merging and Password Protecting PDFs Exported by Crystal Reports
page 4 of 6
by Richard Dudley
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 72881/ 56

Merging the PDF Files

[Download Code]

Add the following statement to the top of our code-behind file:

Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Merger

Un-comment both calls to GenerateReport(), but comment out the Response.Redirect statements, as so:

  Dim strExportFile1, strExportFile2 As String


  strExportFile1 = GenerateReport("customers")
  'Response.Redirect(strExportFile1)


  strExportFile2 = GenerateReport("suppliers")
  'Response.Redirect(strExportFile2)

The above change will create two PDFs, but not redirect to either of them.  To merge the two PDFs, add the following lines of code to the end of page_load:

  ' Create a merge document and set a few properties
  ' Code adapted from DynamicPDF Help File
  Dim MyDocument As MergeDocument = MergeDocument.Merge(MapPath(strExportFile1), MapPath(strExportFile2))
  MyDocument.Creator = "Asp Alliance"
  MyDocument.Author = "Richard J. Dudley"
  MyDocument.Title = "Merging PDFs From Crystal Reports"


  ' Following line of code merges the two files and streams output to browser
  ' no file is saved on the server's hard drive
  MyDocument.DrawToWeb(Me, "MergedReport.PDF")

Recompile your project and load the default page.  You should see a single PDF with both reports in it.

DrawToWeb() directs output directly the the browser--no file is created on your server's disk.  If you want to save the file on your server, use the Draw() method, and then use Response.Redirect to send the file to the browser (or set the source of a download link).


View Entire Article

User Comments

Title: Bookmark   
Name: Kirk
Date: 2010-02-05 7:36:29 AM
Comment:
How do you add bookmarks?
Title: You don't need to shell out on commercial components   
Name: Zarkonia
Date: 2008-05-28 8:09:20 PM
Comment:
Hi All,

Take a look at Pdftk...

Pdftk is free software (GPL) and it runs on Windows, Linux, Mac OS X, FreeBSD and Solaris.

It's a command line app - but with careful use of the SHELL command works like a charm in classic VB or the System.Diagnostics namespace in the .NET world.

I recommend it...
Title: Lib. Demo   
Name: XTemplar
Date: 2007-10-22 12:10:18 AM
Comment:
Dear Richard,
1.)May i have the demo. lib ??
My email: XTemplar@gmail.com
2.)What PDF version it support? All?
3.)What's the charges for it if it's suitable for me?

Thanks,
- XTemplar
Title: Problem for Merge PDF   
Name: Shekh Mohasin
Date: 2007-03-15 12:49:38 AM
Comment:
Hi Richard,
i have try ur code for Merage two PDF file, but in ur sources code i not found "ceTe" Libray file which is very imp it code to Mearge so, can u pls send me the Libray file
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Merger

my MailId is
shekhmohasin@gmail.com

Thanks,
Shekh Mohasin
Title: SE   
Name: Yathish
Date: 2007-02-19 1:28:42 AM
Comment:
Hi Richard,

Is there any mechanism to open rpt files directly in Acrobat Reader instead of Crystal Report Viewer

Thanx,

Yathish M.P
Title: Passwords   
Name: Debbie
Date: 2006-12-28 3:53:25 PM
Comment:
What is the syntax for passing the password to the merger?
Title: How is it better than PDFLib for .Net   
Name: Richard Dudley
Date: 2006-10-26 9:31:09 PM
Comment:
Tech4U,

Only one way to find out--download the demo version and try it! "Load" depends on how large your reports are, and how your application is coded.
Title: How is it better than PDFLib for .Net   
Name: Tech4U
Date: 2006-10-24 2:07:32 PM
Comment:
Hi,
I've an existing app - Windows service, which generates multiple PDF files (Data retrieved from cubes and then Exported to pdf using Crystal) and PDFLib merges all the pdf files together into one file, but the problem is, as mine is a multithreaded app, the PDFLib fails badly and it allows me to select only a couple of Reports(which contains individual reports) but I want to allow user to select more than 5 reports or so, so that they can get all the 5 PDF files (including 100-200 individual pdf files). Can Dynamic PDF Merger handle this kind of load.
Title: Need Information about Continous PAging while merging reports   
Name: Brijesh (brijeshs@nous.soft.net)
Date: 2006-09-07 5:34:36 AM
Comment:
Hi Richard,
I have gone through your article of merging two crystal reports and its really very interesting.I just want to know that if we are using page numbers on both reports so while merging Reports whether the continous paging will happen.

In other words, if 1st report is having 5 pages and the second report is having 4 pages. When we merge these two reports, whether the second report will start from 6th page or Is there any option/setting that will make the second report to start from 6th page not from 1st page.

Any help would be appreciated.

Thanks
Brijesh Singh
Title: PW Protecting XML Files   
Name: Richard Dudley
Date: 2006-06-09 11:09:36 AM
Comment:
This really isn't the best place for that question, since this is an article on PDFs.

Since XML files are just text files, there's really not a good way to password protect them in the file system. Th ebest you could to would be to encrypt them with DPAPI somehow, or some other reversible encryption scheme.
Title: I have gone through the article and found to be interesting. I too have a problem and hope your component have the support feature. I have a requireme   
Name: I have gone through the article and found to be interesting. I too have a problem and hope your component have the suppo
Date: 2006-06-09 7:30:33 AM
Comment:
I have gone through the article and found to be interesting. I too have a problem and hope your component have the support feature. I have a requirement where I should password protect the xml files. This feature should be used from the .net desktop application. The software which I am developing for a client should use/read the xml files from the application. But these files should be password protected from the external drives/location, so that no one should be able to open these xml files.
Title: Reports with ASP   
Name: Richard Dudley
Date: 2006-03-27 1:32:48 PM
Comment:
Kevin,

You can generate Crystal Reports with ASP, but not in this example. This example uses the version bundled with Visual Studio .NET, and you'd have to use a .NET language.

To work in ASP, you'd need the retail version of Crystal Reports. There are tutorials available in the help docs and on the Business objects website.
Title: Generate report in ASP   
Name: Kevin
Date: 2006-03-27 3:14:41 AM
Comment:
Hi,

I wanted to know if it's possible to generate the report in asp instead of .net. And how to do it?

Thanks,

Kevin
Title: Add PW On Open   
Name: Richard Dudley
Date: 2005-11-28 9:31:36 AM
Comment:
Circle,

This article shows you how to add a password to a PDF exported from Crystal Reports. If you add a user password, the end user will be required to enter the password when the file is opened. You can use the same component I did, you just set a different property.
Title: Password protection on PDF File   
Name: Circle
Date: 2005-11-27 11:57:26 AM
Comment:
I m new on .Net & crystal report. Have develop project in Window Form and have to produce report in PDF format ultimately. So i prepare a crystal report and plan to use export function to generate the PDF file, but user request password protection on open the PDF file. Would like to have your advice.
Title: 3rd-party alternative (Visual CUT)   
Name: Ido Millet
Date: 2005-11-22 6:04:03 PM
Comment:
For those who are looking for a 3rd-party solution to do the above and more, my Visual CUT software can automate the exporting of Crystal reports to PDFs, the merging of these PDF files (including the merging of any bookmark information) and, optionally, adding page numbers, a table of contents, and password protection to the resulting merged pdf file.

Cheers,
- Ido
www.MilletSoftware.com
Title: Protecting XML Files   
Name: Richard Dudley
Date: 2005-10-24 3:19:27 PM
Comment:
Mallikarjun,

This has nothing to do with protecting XML files. Since XML files are plain text, they really can't be protected completely. One option might be to store the XML as an encrypted string, which you decrypt when you need to process the XML. If you have questions on how to accomplosh that, try the forums at http://asp.net.
Title: Project Manager   
Name: Mallikarjun
Date: 2005-10-22 11:28:03 PM
Comment:
Hi,

I have gone through the article and found to be interesting. I too have a problem and hope your component have the support feature. I have a requirement where I should password protect the xml files. This feature should be used from the .net desktop application. The software which I am developing for a client should use/read the xml files from the application. But these files should be password protected from the external drives/location, so that no one should be able to open these xml files.

Please assist me if your component has this feature.

Thanks in advance.
Title: Dynamic PDF merger   
Name: Shilpa
Date: 2005-10-13 11:41:27 PM
Comment:
Hi Richard,
I know you are discussing about different scenario of generating PDF files.But with my experience I don't prefer to use DynamicPDF merger.If you generate a PDF file some how and a add any kind of password to it and try to merge it with another PDF.It gives error!
Title: Dynamic PDF Merger   
Name: Richard Dudley
Date: 2005-10-05 8:12:55 PM
Comment:
Shilpa,

PDF documents created by Crystal Reports won't be password protected just ater they are created.

Perhaps your problem is in the way you are using the component? Are you supplying the password?
Title: Some problem with Dynamic PDF merger   
Name: Shilpa
Date: 2005-10-05 1:53:06 PM
Comment:
You article is good.But there is a problem in Dynamic PDF MERGER COMPONENT.
If any of the PDF document is already protected with password then you cannot merge them. It shows an error: "Document can not be decrypted. Invalid owner password."

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 4:42:39 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search