Watermark on any Navision Report

gvolkov
Member Posts: 196
Normally, everyone whould think that its impossible to use Watermarks on Navision reports, however.... i thought i would share this with everyone. If you need to insert a watermark on any report without messing with PCL or PS code on your printer, here is what i have done. Oh and watermark is a variable.... so you can make it dynamic. I my case its field 50000 on Sales Header - "Order Type". So anytime you print a document it inserts Order Type accross the document. Check it out...
1. install PdfCreator
2. install adobe reader 8.0
3. Create this codeunit:
makepdf(rSpecifier : Code[10];OrderType : Code[10]).
pass these variables.
rspecifier is number of sales order
ordertype is field 50000 on salesheader
ordertype can be anything you want used as a watermark.
5. Make appropriate changes in the code to print your report number and make sure you have write permissions to FileDirectory and FileName
Just a note: portion of this code was taken from a previous post, talking about printing PDF files from Navision. I just extended it to Auto-Insert the watermark, and to Auto-Print it on your default printer.
1. install PdfCreator
2. install adobe reader 8.0
3. Create this codeunit:
OBJECT Codeunit 50003 WaterMark { OBJECT-PROPERTIES { Date=06/14/07; Time=[ 3:32:01 PM]; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN END; } CODE { VAR FileDirectory@1000000012 : Text[100]; FileName@1000000011 : Text[100]; ReportID@1000000010 : Integer; Object@1000000009 : Record 2000000001; PDFCreator@1000000008 : Automation "{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613} 4.1:{3A619AE4-50EC-46C8-B19E-BE8F50DD2F22}:'PDFCreator'.clsPDFCreator" WITHEVENTS; PDFCreatorOption@1000000007 : Automation "{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613} 4.1:{F8F15298-30FD-427C-BDFA-55E9AB615632}:'PDFCreator'.clsPDFCreatorOptions"; PDFCreatorError@1000000006 : Automation "{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613} 4.1:{082391C9-8188-4364-B4FD-66A1524B2097}:'PDFCreator'.clsPDFCreatorError"; DefaultPrinter@1000000005 : Text[200]; Window@1000000004 : Dialog; WindowisOpen@1000000003 : Boolean; FileDialog@1000000002 : Codeunit 412; watermark@1000000001 : Text[30]; adobe@1000000000 : Automation "{E64169B3-3592-47D2-816E-602C5C13F328} 1.1:{72498821-3203-101B-B02E-04021C009402}:'Adobe Acrobat 8.0 Type Library'.AcroAVDoc"; SalesHeader@1000000013 : Record 36; PROCEDURE makepdf@1000000000(rSpecifier@1000000000 : Code[10];OrderType@1000000001 : Code[10]); BEGIN FileDirectory := 'C:\'; FileName := 'pdf_file.pdf'; findsalesheader(rSpecifier); IF ISCLEAR(PDFCreator) THEN CREATE(PDFCreator); IF ISCLEAR(PDFCreatorError) THEN CREATE(PDFCreatorError); PDFCreatorError := PDFCreator.cError; IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description); Window.OPEN('processing'); WindowisOpen := TRUE; IF FileName = '' THEN ERROR('Please specify what the file should be saved as'); //Object.GET(Object.Type::Report,'',ReportID); PDFCreatorOption := PDFCreator.cOptions; PDFCreatorOption.UseAutosave := 1; PDFCreatorOption.UseAutosaveDirectory := 1; PDFCreatorOption.AutosaveDirectory := FileDirectory; PDFCreatorOption.AutosaveFormat := 0; //PDF file, you can also save in other formats PDFCreatorOption.AutosaveFilename := FileName; PDFCreatorOption.StampFontname := 'Arial'; PDFCreatorOption.StampFontsize := 150; PDFCreatorOption.StampUseOutlineFont := 1; PDFCreatorOption.StampOutlineFontthickness := 2; PDFCreatorOption.StampString := OrderType; PDFCreator.cOptions := PDFCreatorOption; PDFCreator.cClearCache(); DefaultPrinter := PDFCreator.cDefaultPrinter; PDFCreator.cDefaultPrinter := 'PDFCreator'; PDFCreator.cPrinterStop := FALSE; //REPORT.RUNMODAL(ReportID,FALSE,TRUE); REPORT.RUNMODAL(50020,FALSE,TRUE,SalesHeader); END; PROCEDURE printpdf@1000000001(); BEGIN IF ISCLEAR(adobe) THEN CREATE(adobe); adobe.Open(FileDirectory + FileName,''); adobe.PrintPages(0,999,3,0,0); adobe.Close(0); CLEAR(adobe); CLEAR(PDFCreator); CLEAR(PDFCreatorError); END; PROCEDURE findsalesheader@1000000002(rSpecifier@1000000000 : Code[10]); BEGIN SalesHeader.RESET; SalesHeader.SETRANGE(SalesHeader."Document Type",SalesHeader."Document Type"::Order); SalesHeader.SETRANGE(SalesHeader."No.",rSpecifier); END; EVENT PDFCreator@1000000008::eReady@1(); BEGIN PDFCreator.cPrinterStop := TRUE; PDFCreator.cDefaultPrinter := DefaultPrinter; PDFCreator.cClose(); IF WindowisOpen THEN Window.CLOSE; WindowisOpen := FALSE; printpdf; END; EVENT PDFCreator@1000000008::eError@2(); BEGIN ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description); END; BEGIN END. } }4. call this function from PRINT button on say.. sales order.
makepdf(rSpecifier : Code[10];OrderType : Code[10]).
pass these variables.
rspecifier is number of sales order
ordertype is field 50000 on salesheader
ordertype can be anything you want used as a watermark.
5. Make appropriate changes in the code to print your report number and make sure you have write permissions to FileDirectory and FileName
Just a note: portion of this code was taken from a previous post, talking about printing PDF files from Navision. I just extended it to Auto-Insert the watermark, and to Auto-Print it on your default printer.
Microsoft Certified Technology Specialist
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com
0
Comments
-
[Topic moved from Navision forum to Navision Tips & Tricks forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I have copied this code in a text format.
changed it's extension to .fob
imported it in navision
now when i am trying to compile the code,it is giving an error--"could not load the selected type library".I have installed the PDF creator(Also verified its usage by converting reports in pdf ).
i have also activated the parameters on the functions in this code unit.
And the cursor points to the position where it is written
("ERROR('Status: Error: ' + PDFCreatorError.Description); ").
And it is at the end of the codeunit.
what to do now.0 -
Probably step#4 is not clear to me.
Explain it in detail.
Thanx in advance0 -
Please make sure you are installing the right PDFCreator from http://sourceforge.net/projects/pdfcreator/
I have seen a couple different ones. This one is free, open source. Let me know if thats what you have.Microsoft Certified Technology Specialist
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com0 -
gregoryvolkov@gmail.com wrote:Please make sure you are installing the right PDFCreator from http://sourceforge.net/projects/pdfcreator/
I have seen a couple different ones. This one is free, open source. Let me know if thats what you have.
i have downloaded the PDF Creator from the same link but even then it's not working---the watermark thing.0 -
I have tried to replicate your issue, but it compiled just fine. Only thing i can think of is version 0.9.3
Make sure you have right Automation libraries setup.
PDFCreator Automation 'PDFCreator'.clsPDFCreator
PDFCreatorOption Automation 'PDFCreator'.clsPDFCreatorOptions
PDFCreatorError Automation 'PDFCreator'.clsPDFCreatorError
adobe Automation 'Adobe Acrobat 8.0 Type Library'.AcroAVDocMicrosoft Certified Technology Specialist
Microsoft Certified Business Management Solutions Professional
Microsoft Certified Business Management Solutions Specialist
http://www.navisiontech.com0 -
Hi gvolkov
Pls Provide the Report 50020 to work Watermark
KiranHi0 -
Somehow the code looks familier. 8)0
-
Hi all, i'm trying to implement watermark on my report using this method.
I followed all the steps and called makepdf function from a print button with all the parameters but it just show me a processing window and nothing else. So i added the printpdf function after the makepdf and i get an error 'cannot create an instance of automation server. Check the automation server is correctly installed and registered'. The debugger stops on create(adobe) in printpdf function. But i have adobe reader 9.0 installed.
Thanks for any tip in the right direction0 -
You need to install PDFCreator not Adobe.0
-
you will need to select the automation subtype which is newer in your version. Design the object and change the global variable.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions