We're sorry Aspose doesn't work properply without JavaScript enabled.

# Aspose.words(to use in MsAccess 2003 project)

Hello,

We have bought Aspose.words to convert some of our word document to PDF doc in our MS-Access 2003 Project. I have spent several hours in the your website but could not go through.

I can easily write code & make it work in a .Net application but Im struggling a lot to use the Aspose.words in a MsAccess 2003 application.I posted few queries before but all the replies I got from Aspose support team were just the Web Links.I have gone through all the Links in your website several times.I dont want any links now but all I want is if you can ask one of your Developers to send a MSAccess 2003 Project which should consume Aspose.words and convert a word doc to PDF.

I very much appreciate your help.

Many Thanks,
Bala.

Hi Bala,

Please accpet my apologies for late response.

https://docs.aspose.com/words/net/supported-platforms/#com

Please register Aspose.Words for .NET with COM Interop and use following code snippet to achive your requirements. Hope this helps you. Please let us know if you have any more queries.

Dim helper
Set helper = CreateObject("Aspose.Words.ComHelper")
Dim doc
Set doc = helper.Open("d:\in.docx")
doc.Save ("d:\out.pdf")


Hi Tahir,

Many thanks for your reply.Is there an example to set page size for PDF using com ?

My MSaccess Application sends out this converted PDF to a webservice which only accepts PDF’s with paper size A4. What are the COM objects I need to use for this?

Thank you very much Tahir.

Cheers,
Bala.

Hi Bala,

Thanks for your inquiry. Please use the following code snippet to set the page size to A4. Please read the PaperSize enumerations from here:
https://reference.aspose.com/words/net/aspose.words/papersize/

Dim helper
helper = CreateObject("Aspose.Words.ComHelper")
Dim doc
doc = helper.Open("d:\in.doc")
'doc.FirstSection.PageSetup.PaperSize = 1
Dim i
For i = 0 To doc.Sections.Count - 1
doc.Sections.Item(i).PageSetup.PaperSize = 1
Next
doc.Save("d:\out.pdf")


Hi Tahir,

I guess this would be the last one.

The last bit that needs doing now is to delete the PDF document after creation.
The true purpose of converting a word doc to PDF is one of our clients webservice accepts only PDF documents. So after sending it through the webservice I want to delete the PDF document. Is there any doc.delete() method that I can use to delete it?

Cheers,
Bala.

Hi Bala,

Thanks for your inquiry. First of all please note that Aspose.Words for .NET is a class library that enables your applications to perform a great range of document processing tasks. With Aspose.Words you can generate, modify, convert, render and print documents without utilizing Microsoft Word®. For more information, please go through the documentation below:
https://docs.aspose.com/words/net/product-overview/

The Document.Save(String) method save the file to disk. To delete a file from disk, you can use VBA Kill function as shown in following code snippet.

Dim helper
helper = CreateObject("Aspose.Words.ComHelper")
Dim doc
doc = helper.Open("d:\in.doc")
Dim i
For i = 0 To doc.Sections.Count - 1
doc.Sections.Item(i).PageSetup.PaperSize = 1
Next
doc.Save("d:\out.pdf")
'…
Kill ("d:\out.pdf")


Hello,

I also wanted to check if I can merge two PDF documents using the Aspose.words

Please let me know the possibility of that.

Many Thanks,
Bala.

Hi Bala,

Thanks for your inquiry. Aspose.Words does not merge Pdf document. However, you can merge Pdf files by using Aspose.Pdf component. Please post your query at Aspose.Pdf forum.

Please note that Aspose.Words tries to mimic the same behaviour as MS Word do. You can not load Pdf file into MS Word and join the Pdf documents.

You can merge MS Word document by using Aspose.Words and convert the final document into Pdf. Please read following documentation link for your kind reference.
https://docs.aspose.com/words/net/insert-and-append-documents/

Please check the code example shared at this forum link to merge two MS Word documents. Hope this helps you.

Hello Tahir,

I will start the ball rolling in our company meeting to purchase Aspose.pdf. We have already purchased Aspose.word.

We also have another module which needs word doc merging. It depends on the user to select any number of word docs and we want aspose.word to merge it all in to one word document. Any new document that is merged has to start from in a new page.

For example: 1st word doc: 1.5 pages (abc1.doc)
2nd word doc: 3 pages (def2.doc)
3rd word doc: 2.5 pages (ghi3.doc)

If you merge the above three documents in to one word doc(jkl4.doc) then it should have 8 pages because each document as it gets merged should start from a new page.

Please explain with program code explain how I can achieve this using COM

Cheers,
Bala.

Hi Bala,

Thanks for your inquiry. Please use the following code snippet to merge two documents with page break at the end of first document. Hope this helps you. Please let us know if you have any more queries.

Dim comHelper
Set comHelper = CreateObject("Aspose.Words.ComHelper")
Dim builder
Set builder = CreateObject("Aspose.Words.Documentbuilder")
'open destination and source documents
Dim dstDoc
Set dstDoc = comHelper.Open("d:\dst.docx")
Dim srcDoc
Set srcDoc = comHelper.Open("d:\src.docx")
builder.Document = dstDoc
builder.MoveToDocumentEnd
builder.InsertBreak (1) 'BreakType_PageBreak
'Append source document to destination
Dim dstSection
Dim i
For i = 0 To srcDoc.Sections.Count - 1
Set dstSection = dstDoc.ImportNode_2(srcDoc.Sections.Item(i), True, 1)
dstDoc.AppendChild (dstSection)
Next
dstDoc.Save ("d:\out.docx")


Hello Tahir,

Many thanks for this.I just need one last bit to the above.
I want the first 10 lines of the page 1 of the pdf document’s(out.docx) to be left blank(only page 1). Because some other service in our application will paste our client’s postal address to this blank portion of page 1. Is this possible? Can you please amend your code to fit this requirement of us.

Cheers,
Bala.

Hi Bala,

Thanks for your inquiry. In this case, you can use Documentbuilder.MoveToDocumentStart method to moves the cursor to the beginning of the document and insert Paragraph or Line Breaks.

Dim comHelper
Set comHelper = CreateObject("Aspose.Words.ComHelper")
Dim builder
Set builder = CreateObject("Aspose.Words.Documentbuilder")
'open destination and source documents
Dim dstDoc
Set dstDoc = comHelper.Open("d:\dst.docx")
Dim srcDoc
Set srcDoc = comHelper.Open("d:\src.docx")
builder.Document = dstDoc
builder.MoveToDocumentEnd
builder.InsertBreak (1) 'BreakType_PageBreak
'Append source document to destination
Dim dstSection
Dim i
For i = 0 To srcDoc.Sections.Count - 1
Set dstSection = dstDoc.ImportNode_2(srcDoc.Sections.Item(i), True, 1)
dstDoc.AppendChild (dstSection)
Next
builder.MoveToDocumentStart
builder.InsertBreak (0) '0- ParagraphBreak, 8- LineBreak
builder.InsertBreak (0)
builder.InsertBreak (0)
builder.InsertBreak (0)
builder.InsertBreak (0)

dstDoc.Save ("d:\out.pdf")


Hi Tahir,

Thanks for this. I faced two problems when I tried to use this piece of code.

Problem 1:
builder.MoveToDocumentStart actually moves the cursor to the header of page 1.
So when I insert break the header of page1 moves down. I dont want white space before the header. I only need white spaces (10 lines) after the header.

Problem 2:
Thanks for sending the code to merge both the documents.It works well except the header & footer of source document appears in the destination doc as well.

Many Thanks,
Bala.

Hi Bala,

Thanks for your inquiry. The DocumentBuilder.MoveToDocumentStart method moves the cursor to the beginning of the document. The DocumentBuilder.MoveToHeaderFooter moves the cursor to the beginning of a header or footer in the current section.

Could you please attach your input Word documents here for testing? I will investigate the issue on my side and provide you more information.

True If this header or footer is linked to the corresponding header or footer in the previous section.

Dim dstSection
Dim i
For i = 0 To srcDoc.Sections.Count - 1
Set dstSection = dstDoc.ImportNode_2(srcDoc.Sections.Item(i), True, 1)
dstDoc.AppendChild (dstSection)
Next


Hello Tahir,

Many thanks for this.
To simplify this can we have a blank first page.
The source document should have its first page as blank.This first page should be free from headers and footers.From page 2 of the source doc is the original source document. And then the source document should be merged with the destination document.

For example if a source document has 3 pages and the destination document has 5 pages. The final document should have 9 pages.

Page 1= blank page without headers & footer of source document.
Pages 2,3,4 = source document,
Pages 5,6,7,8,9 = destination document (without headers & footer of source document.)

Please let me know how to achieve this.

Cheers,
Bala.

Hi Bala,

Thanks for your inquiry. In this case, you can use Documentbuilder.MoveToDocumentStart method to moves the cursor to the beginning of the document and insert SectionBreakNewPage (its value is 5). After inserting section break, copy the HeaderFooter from first section of document into second section as shown in following code snippet. Hope this helps you.

Dim comHelper
Set comHelper = CreateObject("Aspose.Words.ComHelper")
Dim builder
Set builder = CreateObject("Aspose.Words.Documentbuilder")
'open destination and source documents
Dim dstDoc
Set dstDoc = comHelper.Open("d:\dst.docx")
Dim srcDoc
Set srcDoc = comHelper.Open("d:\src.docx")
builder.Document = dstDoc
builder.MoveToDocumentEnd
builder.InsertBreak (1) 'BreakType_PageBreak
'Append source document to destination
Dim dstSection
Dim i
For i = 0 To srcDoc.Sections.Count - 1
Set dstSection = dstDoc.ImportNode_2(srcDoc.Sections.Item(i), True, 1)
dstDoc.AppendChild (dstSection)
Next
builder.MoveToDocumentStart
builder.InsertBreak (5) '5 section break new page
Dim SecondSection
Set SecondSection = dstDoc.Sections.Item(1)
dstDoc.Save ("d:\out.docx")


Hi Tahir,

Very few times I get object reference error in any of these lines. 60% of the times it works fine. I get error in these two lines. My assumption is , If a document is there without headers and footers it throws error but I’m not quite sure. Have you got any idea?

Set newHeaderFooter = HeaderPrimary.Clone(True)


or

dstSection.HeadersFooters.Item(0).IsLinkedToPrevious = False


Cheers,
Bala.

Hi Bala,

Thanks for your inquiry. Yes, you are right. In this case, you need to check HeaderPrimary either it is NULL or not. If a section have not any header/footer, you need to add header/footer before working with header/footer.

In your case, please put following code inside IF statement and check either newHeaderFooter variable is Set or not.

Dim newHeaderFooter


Hello Tahir,

I know this is a very old post, but we are trying to review some code here.
I was trying to merge 3 or 4 word documents in to single PDF Document using the code you helped me with, but I got an error in this line

SecondSection.HeadersFooters.Add(newHeaderFooter)


The error read something like this,