Creating and concatinating using existing pdfs (using the Streams)

Hi,

We are currentlly using the word docs as templates and over the runtime we are getting the memory streams using the aspose.words and creating the combined pdf.

Sample code is :

private MemoryStream ConcatenateDocs(MemoryStream inDocMS, Document inDoc, string sender)

{

//Response.Write("In Concat Docs: " + DateTime.Now.ToString() + "\n ");

MemoryStream inDocMS1 = new MemoryStream();

inDoc.Save(inDocMS1, SaveFormat.AsposePdf);

Pdf inPdf = new Pdf();

inPdf.BindXML(inDocMS1, null);

inPdf.IsImagesInXmlDeleteNeeded = true;

inPdf.IsTruetypeFontMapCached = true;

inPdf.TruetypeFontMapPath = System.IO.Path.GetTempPath();

MemoryStream inDocMS2 = new MemoryStream();

inPdf.Save(inDocMS2);

if (sender == "visit" || sender == "list")

{

inDocMS2 = RemoveFirstPage(inDocMS2);

}

PdfFileEditor inEditor = new PdfFileEditor();

inEditor.Concatenate(inDocMS, inDocMS2, inDocMS);

inDocMS1.Close();

inDocMS2.Close();

//Response.Write("Out Concat Docs: " + DateTime.Now.ToString() + "\n ");

return inDocMS;

}

Now we are evaluating the latest version of aspose and planing to get rid of word docs as templates and planing to have the pdf as templates.

We want to use 4 or 5 pdf templates and runtime we want to combine them and want to save it as a single pdf file.

Over the runtime we need the following:

1. replace formfieds

2. import data from datatable.

3. include some static data (exists in a pdf templates)

Can you please help me in this so that we can plan to purchase the latest version of aspose also suggest us do we need to purchase the whole suite or indivisuals.

Thanks,

Sheshi

Email:SSheri@carescout.com

Hi Sheshi,

Thank you very much for considering Aspose.

-Can you please clarify a little bit what you mean by ‘replace form fields’? Do you want to fill the form fields? Or, would you like to remove the form fields and just keep the field’s data on the PDF? Please elaborate.

-You can import data from a data table into a PDF form using AutoFiller.ImportDataTable method. You can also import and export data between a data table and a database using ImportIntoDatabase and ExportFromDatabase methods.

-I’m afraid, I couldn’t understand your third requirement. Can you please explain this requirement a little bit?

-You can purchase either individual component or a suite; both options are available. However if you need further assistance regarding your buying decision i.e. individual versus suite and licensing etc. you can post your questions in Aspose.Purchase forums and our team will help you. You can also find details regarding purchase policies on this link.

Please share the required information, so we could help you out.
Regards,




Hi,

Herewith I'm attaching two pdfs(templates). one is student.pdf and other one is Students List.pdf.

I need to create a new pdf file in which first page will have the content from studnet.pdf with filling the formfeilds and then create the second page using the content from students list.pdf after that bind an xml table to the second page and import the data to that table from the database.

Please let me know if you need any calrification.

Thanks,

Sheshi

Hi Sheshi,

As I understand your requirement, you want to concatenate Student.pdf with StudentList.pdf file and then fill data in the StudentList.Pdf form. If that is correct, this is how you can do this:

- use ConcatenateForms method to concatenate Student.pdf and StudentList.Pdf files
- Now, you can import data to the form from an XML file using ImportXML method. Alternatively, you can convert XML data to data table using ConvertToDataTable and then import that data table into the PDF form using ImportDataTable method.

I hope this helps. Please try this at your end and if you find any issues, please do let us know.
Regards,

Hi,

Thanks for your reply.

Following code I have taken as from your aspose sample code.

The below code will create a new pdf from the scratch and binds with the xml structure and then imports the data.

The help that I need here is I need a sample code that creates the pdf from existing file(.pdf) and bind the xml file and imports tht data from the data table.

Please provide me with the related sample codes or pointers on this..

Pdf pdf = new Pdf();

pdf.IsTruetypeFontMapCached = false;

string xmlFile = path + "\\Xml\\Catalog.xml";

pdf.BindXML(xmlFile, null);

Table beveragesTable1 = (Table)section2.Paragraphs["BeverageTable1"];

this.oleDbSelectCommand1.CommandText = queryString + "1)) ORDER BY Products.ProductName;";

dataTable1 = new DataTable();

this.oleDbDataAdapter1.Fill(dataTable1);

FillTable(beveragesTable1,dataTable1);

Hi Sheshi,

Aspose.Pdf.Kit allows you to either concatenate existing PDF files or append a file to an other PDF. You can also insert a page from one PDF into another one. Can you please explain what you mean when you say you would like to create a new PDF from an existing PDF? Which of the above options would you like to use? Please share your thoughts so we could provide you a sample accordingly.

We’re looking forward to help you out.
Regards,

Hi,

Sorry for confusing you.

I have a template which will have our company standard header and footer I wanted to create the copy of that template(I don't want to modify the template) and then want to bind the xml after that I want to import the data from the datatable.

Thanks for your help.

Hi Sheshi,

If you have a look at the ImportXml method (used to import data into a PDF form from an XML file), and AutoFiller Class’ ImportDataTable method (used to import data into PDF form from a data table/database), you’ll see both of these methods in fact, don’t change the template PDF - rather save the output file using the template PDF and filling the data into the template. So, the input file is intact.

For example, if you a template.pdf as an input pdf template and you fill it using ImportXml method, you can save it as output1.pdf, and then you can use this output1.pdf as an input for ImportDataTable and save the output file as output2.pdf. Now, in the final output2.pdf file you’ll have the data imported from the XML and the database and your input template.pdf file will not be changed at all.

I hope this helps. If it still doesn’t satisfy your requirement then please do share with us and we’ll be glad to help you out.

Regards,

Hi,

Could plsssssssssss share us some sample code or give us any link that will have the code for the same that you suggested?

Thanks,

Sheshi

Hi Sheshi,

Please find code snippet below for the scenario discussed above:

Step 1. Import data into template.pdf from XML

        //Assign an input and output pdf file.
Form form = new Form(“template.pdf”, “output1.pdf”);

//Open an existed xml file.
System.IO.FileStream xmlInputStream = new FileStream(“datafile.xml”, FileMode.Open);

//Import the xml’s content into the pdf file.
form.ImportXml(xmlOutputStream);

//Save the output file.
form.Save();

//Close the output Xml stream.
XmlInputStream.Close();



Step2. Import data into output1.pdf from datatable/database



    
//import data from a database
OleDbCommand mQueryCommand;
OleDbDataAdapter mDbDataAdapter;
OleDbConnection mDbConnection;

//Construct the data table.
DataTable mDataTable = new DataTable(“MailMerge”);
DataColumnCollection columns = mDataTable.Columns;
columns.Add(“CompanyName”,typeof(string));
columns.Add(“ContactName”,typeof(string));
columns.Add(“Address”,typeof(string));
columns.Add(“PostalCode”,typeof(string));
columns.Add(“City”,typeof(string));
columns.Add(“Country”,typeof(string));
columns.Add(“Heading”,typeof(string));


//Connect to the database source and query the data.
mDbConnection = new OleDbConnection();
mDbConnection.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” +
DbPath + “NorthWind.mdb”;
mQueryCommand = new OleDbCommand();
mQueryCommand.Connection = mDbConnection;
mDbConnection.Open();


mQueryCommand.CommandText = “select CompanyName, ContactName, Address, PostalCode, City, Country from Customers;”;
mDbDataAdapter = new OleDbDataAdapter(mQueryCommand);

mDbDataAdapter.Fill(mDataTable);

for (int i = 0; i<mDataTable.Rows.Count;i++)
{
mDataTable.Rows[i][mDataTable.Columns.Count - 1] = "Dear " + mDataTable.Rows[i][0].ToString() + “,”;
System.Console.WriteLine(“postalCode:” + mDataTable.Rows[i][3].ToString());
System.Console.WriteLine(“Heading:” + mDataTable.Rows[i][mDataTable.Columns.Count - 1].ToString());
}

mDbDataAdapter.Dispose();
mDbConnection.Close();


//now fill data into output1.pdf from the datatable
AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = “output1.pdf”;
autoFiller.OutputFileName =
output2.pdf”;

autoFiller.ImportDataTable(mDataTable);
autoFiller.Save();

Please note that the column names in the XML file and data table match with the field names in the template.pdf.

I hope this helps. Please try it at your end, if you still find any confusion or questions, please do let us know.
Regards,

Hi,

Thanks for your help.

But the sample code that you have provided is not working for the following xml :

<?xml version="1.0" encoding="utf-8"?>

<Pdf xmlns="Aspose.Pdf" Title="Catalog" Author="Aspose Support" Producer="Aspose Pty Ltd" Creator="Aspose.Pdf.Demos" Subject="Northwind" Keywords="Pdf Aspose.Pdf Northwind">

<Section PageMarginLeft='50' PageMarginRight='50' ID='section2'>

<Footer>

<Graph Width="470" Height="20">

<Rectangle Position="0 0 470 15" Color='gray 204' FillColor='gray 204' IsFilled='true'/>

<Note Position='150 5' Color='rgb 0 0 160'>NorthWind Traders - Fall Catalog</Note>

</Graph>

<Text Alignment="center">

<Segment IsSymbolReplaceable="true" Color='rgb 0 0 160'>

Page $p</Segment>

</Text>

</Footer>

<Text Alignment= "left" FontName='Times-BoldItalic' FontSize='14' Color='rgb 0 0 160' MarginLeft='20'

MarginRight='100' MarginTop='20'>

<Segment>

Providers List

</Segment>

</Text>

<Table ID='ProvidersList' MarginLeft='20' MarginTop='20'

ColumnWidths="170 90 110 90">

<Border>

<Bottom Color='gray 204' />

</Border>

<Row>

<Cell BackgroundColor='gray 204' PaddingTop='2' PaddingBottom='2'>

<Text>

<Segment FontName='Times-Bold' FontSize='10' Color='rgb 0 0 160'>

Name and Contact Information

</Segment>

</Text>

</Cell>

<Cell BackgroundColor='gray 204' PaddingTop='2' PaddingBottom='2'>

<Text>

<Segment FontName='Times-Bold' FontSize='10' Color='rgb 0 0 160' Alignment='center'>

CareScout Proprietary Quality Ratings*

</Segment>

</Text>

</Cell>

<Cell BackgroundColor='gray 204' PaddingTop='2' PaddingBottom='2'>

<Text>

<Segment FontName='Times-Bold' FontSize='10' Color='rgb 0 0 160'>

Bed Availability Indicator

</Segment>

</Text>

</Cell>

</Row>

</Table>

</Section>

</Pdf>

the code that you have provided is working only for formfields.

Finally what I need is: I need to import the above xml into pdf and then import the data from datatable to the above xml (table)

Once again I thank you for your help.

Thanks,

Sheshi.

Hi Sheshi,

I think, now I’m a little clear about your requirement after looking at the sample you shared in your last post. In fact, you’re trying to create a new PDF file from an XML template using Aspose.Pdf and then trying to fill the table with some data. Is that right? Actually, you’re not using Aspose.Pdf.Kit to fill the form fields. Am I right?

Please share if I have understood your requirement clearly, so we could move forward with the requirement.

We’re sorry for the inconvenience.
Regards,

Hi,

Yes, I need to create the pdf (new pdf content -- Header and footer should be loaded from another pdf template) to import the data from .net datatable.

Please let me know if you need any clarifications.

Thanks,

Sheshi

Hi Sheshi,

I would like to inform you that if you’re interested to create a PDF from scratch then you’ll have to use Aspose.Pdf. For that matter, please post your question in the Aspose.Pdf forums, so the related team would be able to help you out.

If you have any questions, regarding Aspose.Pdf.Kit please post in this forum.

We’re sorry for any inconvenience.
Regards,