Stitching PDF documents together

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Support Staff, moderators

Post Reply
Joby
User
Posts: 11
Joined: Fri Feb 11, 2005 12:41 am

Stitching PDF documents together

Post by Joby » Tue Mar 29, 2005 8:40 am

Individual pdf documents are generated by our application. Say after five documents have been generated, we need to stitch the five pdf documents into a single e-book with book marks associated with each document. I dont find any leads on how to do this.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Tue Mar 29, 2005 8:57 am

Hi,

You dont say which dev tools you use - but there are several demo apps showing how to do this using the xcpro30.dll library functions.

There is an entire topic in the XCPRO30.CHM help file under the heading 'Merge documents'

Also for VB for example there is a demo app in the installation folder

C:\Program Files\Tracker Software\PDF-XChange PRO 3 SDK\Examples\SDKExamples\VBExamples\PDFXCPro

assuming you accepted the defaults.

There are also demo apps for C/C++/C#/Delphi/Clarion etc.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Joby
User
Posts: 11
Joined: Fri Feb 11, 2005 12:41 am

Post by Joby » Wed Mar 30, 2005 11:44 am

We are using PDFSDKPRO3.
I have a existing pdf document, I need to open that document for manipulations. I dont see any API's for opening an existing document.

For reading a document, the help says I should have the PDF object previously created by the PDFXCp_InitEx. which we dont have.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Thu Mar 31, 2005 6:18 am

Please see the Help file XCPRO30.CHM and the examples for PDF-Tools SDK - of which there are many.

Depending on the Dev Tools you use (i.e. VB/C++/Delphi/Clarion/C# etc) there are demo's showing how to merge files.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Joby
User
Posts: 11
Joined: Fri Feb 11, 2005 12:41 am

Post by Joby » Thu Mar 31, 2005 2:02 pm

Thank You, Found the code for merging.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Thu Mar 31, 2005 6:28 pm

Pleasure - pleased all is well ;)
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Joby
User
Posts: 11
Joined: Fri Feb 11, 2005 12:41 am

Post by Joby » Fri Apr 01, 2005 2:30 pm

A e-book needs to be created with 5 pdfs. Need to add a single level bookmark to each pdf added to the book. Each pdf is a single page.

Each time a pdf is added, AddBooKMark function is called to add the bookmark.

Right now I am able to merge the 5 pdfs into a single e-book. But I am Not able to add (single level )bookmarks for the 5 pdfs.

In PDFXCp_AddOutlineItem() function what should be given as input to ParentID argument.

Code: Select all

long CPDFWriter::AddBookMark(const CString& strBookMark,int nPage, long lPrevID)
{
	PDF	doc1;
	doc1 = PDFXCp_Init();	
USES_CONVERSION;
	PDFXCp_SetFileName(doc1, (LPSTR)(T2A(m_strPDFName)));
	HRESULT hr = PDFXCp_ReadDocument(doc1);
	long lRetId = 0;
	PDF_Outline_Item2 *pbookMark = new PDF_Outline_Item2;
	strcpy(pbookMark->Title, T2A(strBookMark));
	pbookMark->GotoPage = nPage;
	pbookMark->DestProperty.DestE = DE_FIT;
	hr = PDFXCp_AddOutlineItem doc1,0,lPrevID,&lRetId,pbookMark);
		PDFXCp_Close(doc1);		
	return lRetId;	
}

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Mon Apr 04, 2005 9:44 am

Hi,

can you be a little more detailed in your description of why you have a problem please.

Have you looked at the demo app's for this ?
What is your development Tool (i.e. VB/C# etc)

Please post sample code or a simple application and also any PDF files generated - also please zip any files posted.

thanks
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Joby
User
Posts: 11
Joined: Fri Feb 11, 2005 12:41 am

Post by Joby » Mon Apr 04, 2005 1:58 pm

Development tool : VC++

Each time a PDF is generated, it needs to be merged with another pdf and a book mark needs to be added. Currently the merge is happening properly, but the bookmark is not getting added.

For adding abookmark, I get the title string, the page number and the previousID. Initially lPrevID =0.
The first bookmark gets added properly, for the second book mark, it returns an error saying the value of one of the argument is out of range.
I am returning lRetId and for the next time this is sent as input tp lPrevID
Have attached the pdf with the problem.

Code: Select all

long CPDFWriter::AddBookMark(const CString& strBookMark,int nPage, long lPrevID)
{
	HRESULT hr;
	PDF	doc1;
	doc1 = PDFXCp_Init();	
	USES_CONVERSION;

	PDFXCp_SetFileName(doc1, (LPSTR)(T2A(m_strPDFName)));
	hr = PDFXCp_ReadDocument(doc1);
	if (IS_DS_FAILED(hr))
	{
		PDFXCp_Close(doc1);		
		return 0;
	}
	
	long lRetId = 0;
	PDF_Outline_Item2 *pbookMark = new PDF_Outline_Item2;
	strcpy(pbookMark->Title, T2A(strBookMark));
	pbookMark->GotoPage = nPage;
	pbookMark->DestProperty.DestE = DE_FIT;

	hr = PDFXCp_AddOutlineItem(doc1,0,lPrevID,&lRetId,pbookMark);
	delete pbookMark;
	if (IS_DS_FAILED(hr))
	{
		PDFXCp_Close(doc1);		
		return 0;
	}
	PDFXCp_WriteDocument(doc1, (LPSTR)(T2A(m_strPDFName)));
	PDFXCp_Close(doc1);		
	return lRetId;	
}
Last edited by Joby on Tue Apr 05, 2005 10:48 am, edited 1 time in total.

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Mon Apr 04, 2005 3:36 pm

Thanks Will ask our VC++ guy to look at and respond.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Joby
User
Posts: 11
Joined: Fri Feb 11, 2005 12:41 am

Post by Joby » Tue Apr 05, 2005 7:55 am

Function call

//Set the pdf name to which the other pdf needs to be added
m_pdfWriter.SetPdfPath(m_strCurrentFileName);

//Adddocument function is called, and the path of the pdf to be added to m_strCurrentFileName is given
m_pdfWriter.AddDocument(strTempPdfPath);

//After adding the document we call AddBookMark, giving the string, page number and the previousID as inputs.
lbookMarkID = m_pdfWriter.AddBookMark(strBookMark,nPageNum,lbookMarkID);

lbookMarkID is a static variable, holds the value returned by AddBookMark. Initialized to 0 initially.

The PDFXCp_AddOutlineItem() function fails saying the value is not in range, when AddBookmark() function is called for the second time. I verified the value of PrevID and it was same as the value returned by the function the first time.

Code: Select all

void CPDFWriter::AddDocument(const CString& strFileName)
{
	HRESULT hr;

	USES_CONVERSION;

	PDF	doc1;
	PDF	doc2;
	
	doc1 = PDFXCp_Init();	
	doc2 = PDFXCp_Init();	
	
	PDFXCp_SetFileName(doc1, (LPSTR)(T2A(m_strPDFName)));
	PDFXCp_SetFileName(doc2, (LPSTR)(T2A(strFileName)));
	
	hr = PDFXCp_ReadDocument(doc1);
	if (IS_DS_FAILED(hr))
	{
		PDFXCp_Close(doc1);
		PDFXCp_Close(doc2);
		return;
	}

	hr = PDFXCp_ReadDocument(doc2);
	if (IS_DS_FAILED(hr))
	{
		PDFXCp_Close(doc1);
		PDFXCp_Close(doc2);
		return;
	}
	
	hr = PDFXCp_Merge(doc1, doc2);
	if (IS_DS_FAILED(hr))
	{		
		PDFXCp_Close(doc1);
		PDFXCp_Close(doc2);
		return;
	}
	hr = PDFXCp_WriteDocument(doc1, (LPSTR)(T2A(m_strPDFName)));

	PDFXCp_Close(doc1);
	PDFXCp_Close(doc2);
}

void CPDFWriter::SetPdfPath(const CString &strPDFPath)
{
  m_strPDFName = strPDFPath;
}

long CPDFWriter::AddBookMark(const CString& strBookMark,int nPage, long lPrevID)
{
	HRESULT hr;
	PDF	doc1;
	doc1 = PDFXCp_Init();	
	USES_CONVERSION;

	PDFXCp_SetFileName(doc1, (LPSTR)(T2A(m_strPDFName)));
	hr = PDFXCp_ReadDocument(doc1);
	if (IS_DS_FAILED(hr))
	{
		PDFXCp_Close(doc1);		
		return 0;
	}

	long lRetId = 0;
	PDF_Outline_Item2 IbookMark;
	strcpy(IbookMark.Title, T2A(strBookMark));
	IbookMark.GotoPage = nPage;
	IbookMark.DestProperty.DestE = DE_FIT;
	hr = PDFXCp_AddOutlineItem(doc1,0,lPrevID,&lRetId,&IbookMark);

	if (IS_DS_FAILED(hr))
	{
		PDFXCp_Close(doc1);		
		return 0;
	}
	PDFXCp_WriteDocument(doc1, (LPSTR)(T2A(m_strPDFName)));
	PDFXCp_Close(doc1);		
	return lRetId;	
}


John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Tue Apr 05, 2005 2:32 pm

Hi Please see the example attached - this uses :

'PDFXCp_GetOutlines' and 'PDFXCp_SetOutlines'

which is a more efficient and flexible means to do as you require.

You will of course need to amend to suit your own needs specifically.
Attachments
Outlines.zip
Bookmarks example.
(3.69 KiB) Downloaded 97 times
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Post Reply