Opening an ascii file

If you are a VB developer and have questions about using our products from VB, here is the place to post them.
Post Reply
jfulford
Posts: 4
Joined: Thu Apr 03 2003

Opening an ascii file

Post by jfulford »

I'm testing your Converter to use in a product I'm developing for a lab that needs to convert lots of .doc nad .txt files to .pdf format and then combine them all into one large final report in .pdf format.

How do I take an ascii text file an convert it to a pdf file? Can you give me some sample code to try, so I can see if your control will do the job?

Thanks,
Jeff Fulford
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello Jeff,

Our PDF Converter works as any normal printer, the difference is that our driver is for a virtual printer not a physical one.

To convert the text file to pdf you will need to print it to that printer.

For sample applications please download any of our technical notes from: http://www.amyuni.com/en/support/technotes.html

In these samples (TN03, TN05, TN06,...) you will get a sample code on converting a Word document to pdf and concatenating multiple pdf files.

Also you can use our BatchConvert function to convert a bunch of files in a certain directory to pdf. For more details about this function please check our Developers' manual "Common Driver Interface 210.pdf".

Hope this helps.
jfulford
Posts: 4
Joined: Thu Apr 03 2003

Post by jfulford »

Hello,

I've looked through the Technical Notes and found nothing that explains how to print out a .txt file to the AmyUni printer. Unless I missed it, none of your technical notes explain or give examples of printing ASCII (.txt) files out to the Amyuni virtual printer and saving it as a pdf file.

I also tried to use a work around using the MS Word Object Model to load a text file but am having a similar problem using Word's PrintOut method to print the document to the AmyUni printer. I'm getting an error message saying, "Word cannot print due to a problem with the current printer setup." TN5 Shows how to do it in Microsoft Access using Access' DoCMD method. But how do you print .doc and .txt files to the Amyuni virtual printer it using Word?

Can someone please explain or post an example of how to print ASCII files and Word's .doc files? If I can't find clearer help, I'll have to go with another 3rd party control.

Thanks,

Jeff Fulford
jfulford
Posts: 4
Joined: Thu Apr 03 2003

Post by jfulford »

Here's my code for importing a .txt file into MS Word, since I'm not sure how to use Notepad or WordPad to programatically open and Print a file to the AmyUni printer object.

Case ".TXT"
Dim WordApp As New Word.Application
Dim Docs As Word.Documents
Dim aDoc As Word.Document
Set Docs = WordApp.Documents
Set aDoc = Docs.Open(Filename:=sFilename, ConfirmConversions:=False, ReadOnly:=True, Format:=wdOpenFormatText)
aDoc.PageSetup.LeftMargin = InchesToPoints(0.5)
aDoc.PageSetup.RightMargin = InchesToPoints(0.25)
aDoc.PageSetup.TopMargin = InchesToPoints(0.25)
aDoc.PageSetup.BottomMargin = InchesToPoints(0.25)
aDoc.PageSetup.VerticalAlignment = wdAlignVerticalCenter

pdfPrinter.DefaultFileName = sFile
pdfPrinter.FileNameOptionsEx = &H1 + &H2
WordApp.ActivePrinter = "AMYUNI PDF Converter"
'Activate the AmyUni Print driver
pdfPrinter.EnablePrinter "AMYUNI PDF Converter", _
"07EFCDAB010001000A8E993212686EF251F0149882C22720A96D46AA632D046DD64229B0989A28FC47CFD1981295249B80961849D9B54CE17181F18E7A5188ABCF2DB572E6215AD457D388DDDD5019DC852B3012034FFC48E6A6F468C7C7796CAB886B74F6202026"

WordApp.PrintOut False 'Sends the text file to the PDF driver to be printed out as a PDF file '<--------- Error 5142 occurs here

Call UpdateChecklistStatus(True)

Case Else
MsgBox "This File Type hasn't been coded yet", vbInformation + vbOKOnly, "Error Opening File"
' Unload Me
Resume Next
End Select

Private Sub pdfPrinter_EnabledPre()

pdfPrinter.EnablePrinter "AMYUNI PDF Converter", _ "07EFCDAB010001000A8E993212686EF251F0149882C22720A96D46AA632D046DD64229B0989A28FC47CFD1981295249B80961849D9B54CE17181F18E7A5188ABCF2DB572E6215AD457D388DDDD5019DC852B3012034FFC48E6A6F468C7C7796CAB886B74F6202026"

End Sub

Can you tell me what I'm doing wrong?

Thanks,
Jeff Fulford
jfulford
Posts: 4
Joined: Thu Apr 03 2003

Post by jfulford »

Oops, I mistyped the company argument of the EnablePrinter method. It is actually
pdfPrinter.EnablePrinter "Developer Evaluation Version", _ "07EFCDAB010001000A8E993212686EF251F0149882C22720A96D46AA632D046DD64229B0989A28FC47CFD1981295249B80961849D9B54CE17181F18E7A5188ABCF2DB572E6215AD457D388DDDD5019DC852B3012034FFC48E6A6F468C7C7796CAB886B74F6202026

Can anyone tell me what I'm doing wrong?

Jeff Fulford
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello Jeff,

The activation code you are using is wrong. Please use the following activation code instead:

License To:
Developer Evaluation Version

Activation code:
07EFCDAB0100010030228813C3F9EB6744EF908EB7275546887F264955D0A813F95EFA67E58E0105400829B1B20D2AFA80BA86A0B0D61B657484D98BF592DE13F69BF7D9F6908FE3F4EBAB3B0AB2358ACB5ED028E12FC8849576BB4F387A6FD0DDA4943D4D4EFBB687ECA0CD

Please double check that no extra space is added to the code when copying and pasting it.

Concerning conversion of txt files. I only know how to open a document in Word and print it to the PDF Printer programatically. This is also explained in some of our technical notes.

If you are still facing problems, please send an e-mail to our Support Department support@amyuni.com they will try to help you even if you didn't license the product yet.

Best Regards.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello Jeff,

The activation code you are using is wrong. Please use the following activation code instead:

License To:
Developer Evaluation Version

Activation code:
07EFCDAB0100010030228813C3F9EB6744EF908EB7275546887F264955D0A813F95EFA67E58E0105400829B1B20D2AFA80BA86A0B0D61B657484D98BF592DE13F69BF7D9F6908FE3F4EBAB3B0AB2358ACB5ED028E12FC8849576BB4F387A6FD0DDA4943D4D4EFBB687ECA0CD

Please double check that no extra space is added to the code when copying and pasting it.

Concerning conversion of txt files. I only know how to open a document in Word and print it to the PDF Printer programatically. This is also explained in some of our technical notes.

If you are still facing problems, please send an e-mail to our Support Department support@amyuni.com they will try to help you even if you didn't license the product yet.

Best Regards.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello Jeff,

The activation code you are using is wrong. Please use the following activation code instead:

License To:
Developer Evaluation Version

Activation code:
07EFCDAB0100010030228813C3F9EB6744EF908EB7275546887F264955D0A813F95EFA67E58E0105400829B1B20D2AFA80BA86A0B0D61B657484D98BF592DE13F69BF7D9F6908FE3F4EBAB3B0AB2358ACB5ED028E12FC8849576BB4F387A6FD0DDA4943D4D4EFBB687ECA0CD

Please double check that no extra space is added to the code when copying and pasting it.

Concerning conversion of txt files. I only know how to open a document in Word and print it to the PDF Printer programatically. This is also explained in some of our technical notes.

If you are still facing problems, please send an e-mail to our Support Department support@amyuni.com they will try to help you even if you didn't license the product yet.

Best Regards.
Post Reply