Split Crystal Report Into Separate Files by Page - c#

I'm trying to break a multi page crystal report into multiple files by page and name according from their respective fields. I've been fooling around with the code from this question however I run into all type of SAP error's. Is there not a simple way to iterate say like:
foreach(var page in CrystalReport)
{
report.ExportTiDisk(ExportFormatType.WordForWindows, page.[NameField]);
}
Worst case I could do this with the Word API but that another can of worms I'd rather not open.
Thank you in advance

Dear please check the code.
Why you need to export in multiple files, it is bad as suppose you have a report with 300 pages result, then are you think to make 300 files to export and customer to check each & every files. Think again.
Still here is solution, Please refer to the following VB.Net code for exporting to seperate pdf files.
Dim rdoc As New ReportDocument
'------------------------------------
'Add your code to set rdoc object
'--------------------------------------
Dim exportOpts As ExportOptions = New ExportOptions()
Dim pdfRtfWordOpts As PdfRtfWordFormatOptions = ExportOptions.CreatePdfRtfWordFormatOptions()
Dim destinationOpts As DiskFileDestinationOptions = ExportOptions.CreateDiskFileDestinationOptions()
For li_count As Integer = 1 To pagecount
pdfRtfWordOpts.FirstPageNumber = li_count
pdfRtfWordOpts.LastPageNumber = li_count
pdfRtfWordOpts.UsePageRange = True
exportOpts.ExportFormatOptions = pdfRtfWordOpts
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
destinationOpts.DiskFileName = "D:\report File" & li_count & ".pdf"
exportOpts.ExportDestinationOptions = destinationOpts
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
rdoc.Export(exportOpts)
Next
refer link export in multiple file
You have not written your CR-version, So please refer to this link also which says, not able to export in multiple files in cr-2008.
http://social.msdn.microsoft.com/Forums/en-US/f85e167d-edb3-44d0-82fc-2d2b6f92f57b/how-do-i-export-multiple-pdf-files-from-a-single-crystal-report-ie-a-pdf-file-for-each?forum=vscrystalreports
http://scn.sap.com/thread/1132776

The process of splitting a report in multiple files is known as bursting. You can split by group , not by page. However splitting by group will allow you to split based on the data , not by mechanical reason like page number. As a result if you have a customer with more data which is printed on 2 pages the report will be spitted correctly and the generated file for this customer will be 2 pages too. Bursting is a little bit complicate to develop but there are few tools on the market that can do it. Check this video :
http://www.r-tag.com/Pages/Preview_Bursting.aspx
I believe the tool in this video is free.

Related

PDFSharp: Bookmarks added to first page of each PDF end up all linking to first page of combined pdf

I am using PDFSharp to add a bookmark to page one of a PDF document for a client. The client is providing multiple PDF documents with varying pages and each PDF is a single bill for a person. The client asked me to put the account number in a bookmark on the first page so they can combine them together and process a single PDF with many bills using the bookmark as a means to identify the account number.
I successfully created the bookmark using the following code, but when the client combines the files together using Ghostscript, all bookmarks are assigned to page 1 on the combined PDF. When they combine other PDF's from another system that essentially does the same thing the bookmarks display as desired on the combined file. I am not sure what they are doing differently to make this work.
How can I get the bookmark to be set correctly so it is maintained when combined?
string file = "c:/test.pdf";
string accountNumber = "001234";
using (PdfDocument doc = PdfReader.Open(file, PdfDocumentOpenMode.Modify))
{
PdfPage page = doc.Pages[0];
doc.Outlines.Add(accountNumber, page);
doc.Save(file);
}
I figured it out. Although redundant since the second parameter in Outlines.Add() is setting the destination page, I just needed the following line:
outline.DestinationPage = page;

How to open Image manager through Enterprise Architect API

I am working on Enterprise Architect through C# add-ins. I need to display the image manager through automation where user can add directly add images on an "add image" button click in form.
I use the API Repository.InvokeConstructPicker() but it only opens the select package/class/component window. Is there an EA API available to open the Image Manager.
No, there is none. There is the undocumented Respository.CustomCommand which can open several properties windows. But the image manager is not part of that (or it has not been discovered what parameters to supply).
Please see Edit2 below about adding new values to the table.
Edit: Based on another question I had to dig into this a bit deeper.
I found out that, although EA imports a number of different image formats, it internally uses PNG to store the image. Obviously their BMP-importer does not like all BMP formats (not so deep in that, but I seem to remember there's some 8/16 bit stuff; typical Windoze weirdness). Anyhow, I used this Python code snippet to retrieve some test image data, previously imported into EA:
import sys
import win32com.client
import base64
import xml.etree.ElementTree
eaRep = None
try:
eaApp = win32com.client.GetActiveObject(Class="EA.App")
eaRep = eaApp.repository
except:
print "failure to open EA"
sys.exit(2)
def dump():
sqlRes = eaRep.SQLQuery("SELECT * FROM t_image")
root = xml.etree.ElementTree.fromstring(sqlRes)
for dataset in root:
for data in dataset:
for row in data:
name = row[1].text
print name
data = row[3].text
png = base64.standard_b64decode(data)
file = open("c:/" + name + ".png", "wb")
file.write(png)
file.close()
dump()
This correctly extracted the images from the database.
Edit2: I was assuming that EA stores the png as base64, but that's not true. EA only delivers base64 on return of SQLQuery. But they internally just store the raw png in Image. So, unfortunately, you can not use Repository.Execute since it can not transport binary data - or at least I have not figured out how to do that. As a work around you can look into Repository.ConnectionString and open a native connection to the database. Once you have plugged the new picture(s) in the table you can use them via thier ImageID.
Contents of t_image:
ImageID : You just need to create an unique ID
Name : an arbitrary string
Type : fixed string Bitmap
Image : blob of a png
Here's a Python snippet that connects natively to an EAP file:
import pyodbc
db_file = r'''C:\Documents and Settings\Administrator\Desktop\empty.eap'''
odbc_conn_str = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=' + db_file
conn = pyodbc.connect(odbc_conn_str)
cursor = conn.cursor()
cursor.execute("select * from t_image")
row = cursor.fetchone()
if row:
print(row)
Rather than printing the row with the image data (which shows that its contents is a png-blob) you can use it to actually issue an INSERT or UPDATE to modify t_image.

Delete .doc duplication during PDF conversion c#

I currently have a program that merges a folder consisting of word docs into one combined file via user input with a FileBrowserDialog. Once files are selected, a 'combine' button applies the code shown below which sources the folder containing the documents, output location and name of the file created.
string fileDate = DateTime.Now.ToString("dd-MM-yy");
string fileTime = DateTime.Now.ToString("HH.mm.ss");
string outcomeFolder = outputFolder;
string outputFileType = ".docx";
string outputFile = "Combined Folder " + fileDate + " # " + fileTime + outputFileType;
string outputFileName = Path.Combine(outcomeFolder, outputFile);
// Combines the file name, output path selected and the yes / no for pagebreaks.
MsWord.Merge(sourceFiles, outputFileName, pageBreaker);
// Message displaying how many files are combined.
MessageBox.Show("A total of " + sourceFiles.Length.ToString() + " documents have been merged", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);}
The MsWord referenced calls a separate .CS file which combines the folder components, output name and a boolean to enable page-breaks. The MsWord also automatically saves the word .doc to the user specified location once the contents of the folder are successfully combined. MsWord.Merge(sourceFiles, outputFileName, pageBreaker);
The issue i'm wanting to address is, when I enable this check box:
if (convert2PDFBox.Checked)
Microsoft.Office.Interop.Word.Application officeApp = new Microsoft.Office.Interop.Word.Application();
officeApp.Documents.Open(outputFileName);
outputFileType = ".pdf";
officeApp.ActiveDocument.SaveAs(outputFileName + outputFileType, WdSaveFormat.wdFormatPDF);
officeApp.Quit();
I want the program to solely create a PDF of the combined folder and not 2 seperate .doc and .PDF files, which it currently does. Since the MsWord.save function is called separately and is essential to the overall function of my program, I was wondering is there a possibility of deleting the initially combined file once conversion of the PDF takes place? e.g. "combinedDocument".Delete - Essentially allowing the copy to take place however not presenting the user with the initial .doc - only the .PDF
Though the issue is small, I would love to get it addressed and welcome any suggestions or advice with this manner. I can also provide any additional information if needed, thank you.
tl;dr - merging program creates an amalgamated Word .doc, which i want to change solely to a PDF when a checkbox is enabled instead of creating a .doc and PDF.
I finally resolved my issue - What I decided to do was manipulate my existing MsWord.cs and create a separate PDF.cs call for my main form:
Rather than save the Word .doc when being merged, I instead used: wordApplication.ActiveDocument.SaveAs(outputFile, Word.WdSaveFormat.wdFormatPDF);
which saved the merged content thus far as a .pdf
This however presented errors with Microsoft Word as I was then prompted to 'Save File As' due to the merged file never actually being saved in a .Doc / .Docx format
I then altered the closing statement of the call,
// Close Word application
wordApplication.Quit(
false, // save changes
By setting the 'Save Changes' setting to False, it removed the 'Save As' prompt which allowed the Word doc. to be dismissed without needing to be saved, thus leaving only the initial PDF created. I then applied the two separate File type calls to each checkbox presented, which allowed the user to enable the outcome format of the merged files.
Thank you for the suggestions regarding the issue.

Inserting word content into a VSTO document level customization

I have a VSTO document level customization that performs specific functionality when opened from within our application. Basically, we open normal documents from inside of our application and I copy the content from the normal docx file into the VSTO document file which is stored inside of our database.
var app = new Microsoft.Office.Interop.Word.Application();
var docs = app.Documents;
var vstoDoc = docs.Open(vstoDocPath);
var doc = docs.Open(currentDocPath);
doc.Range().Copy();
vstoDoc.Range().PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);
Everything works great, however using the above code leaves out certain formatting related to the document. The code below fixes these issues, but there will most likely be more issues that I come across, as I come across them I could address them one by one ...
for (int i = 0; i < doc.Sections.Count; i++)
{
var footerFont = doc.Sections[i + 1].Footers.GetEnumerator();
var headerFont = doc.Sections[i + 1].Headers.GetEnumerator();
var footNoteFont = doc.Footnotes.GetEnumerator();
foreach (HeaderFooter foot in vstoDoc.Sections[i + 1].Footers)
{
footerFont.MoveNext();
foot.Range.Font.Name = ((HeaderFooter)footerFont.Current).Range.Font.Name;
}
foreach (HeaderFooter head in vstoDoc.Sections[i + 1].Headers)
{
headerFont.MoveNext();
head.Range.Font.Name = ((HeaderFooter)headerFont.Current).Range.Font.Name;
}
foreach (Footnote footNote in vstoDoc.Footnotes)
{
footNoteFont.MoveNext();
footNote.Range.Font.Name = ((Footnote)footNoteFont.Current).Range.Font.Name;
}
}
I need a fool proof safe way of copying the content of one docx file to another docx file while preserving formatting and eliminating the risk of corrupting the document. I've tried to use reflection to set the properties of the two documents to one another, the code does start to look a bit ugly and I always worry that certain properties that I'm setting may have undesirable side effects. I've also tried zipping and unzipping the docx files, editing the xml manually and then rezipping afterwards, this hasn't worked too well, I've ended up corrupting a few of the documents during this process.
If anyone has dealt with a similar issue in the past, please could you point me in the right direction.
Thank you for your time
This code copies and keeps source formatting.
bookmark.Range.Copy();
Document newDocument = WordInstance.Documents.Add();
newDocument.Activate();
newDocument.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
There is one more elegant way to manage it based upon
Globals.ThisAddIn.Application.ActiveDocument.Range().ImportFragment(filePath);
or you can do the following
Globals.ThisAddIn.Application.Selection.Range.ImportFragment(filePath);
in order to obtain current range where filePath is a path to the document you are copping from.

Print multiple reports in a single PDF file

hi i need some help in pdf generation in crystal reports.The Scenario is ,the user can select multiple values from the grid view for which pdf files are generated on clicking a print button.As of now if the user selects 2 details and click print button 2 pdf files are created .But I need to change the functionality in such a way that the report of records selected by user should be saved in a single pdf file irrespective of the number of records .
the code am currently using is
rprt.SetDataSource(rptDataSet);
rprt.ExportToDisk(ExportFormatType.PortableDocFormat, filePath);
DiskFileDestinationOptions dfdo = ExportOptions.CreateDiskFileDestinationOptions();
ExportOptions eo = new ExportOptions();
eo.ExportFormatType = ExportFormatType.PortableDocFormat;
eo.ExportDestinationType = ExportDestinationType.DiskFile;
dfdo.DiskFileName = filePath;
eo.ExportDestinationOptions = dfdo;
rprt.Export(eo);
I think you have two options (maybe more):
Modify the crystal report slightly by adding a new grouping on your "primary key". Then you can just pass the dataset for all highlighted records and one pdf will be created
Export each pdf separately then "stuff" them together
Systems I use take the first approach- i think it's more efficient.
EDIT As requested- i've attached a sample invoice report which is used for printing batches of invoices. Group 2 is on {LT_INVOICE.TRANSACTIONID} which will be unique for each invoice.

Categories