C# Console Application to Generate PDF

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

C# Console Application to Generate PDF

Postby ptah101 » Wed May 18, 2016 8:50 am

Good day

I am new to VPE and Dycodoc and have been tasked with generating a PDF report on the fly using a console application that reads the information from a database. Most code samples I have seen are C# windows forms with dialog boxes.
Initially I tried the code below and got the error message: The type 'VPECTRLLib.VPEClass' has no constructors defined
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var vpeClass = new VPEClass();
const string vpeFile = @"C:\Reports\XYZ\Dycodoc\helloWorld.vpe";
const string template = @"C:\Reports\XYZ\Dycodoc\helloWorld.tpl";
vpeClass.OpenDoc();
vpeClass.License("-------------", "*****************");
var letter = vpeClass.LoadTemplate(template);
letter.SetFieldAsString("ltr", "User_name", "Peter");
letter.SetFieldAsString("ltr", "Some_name", "My Other Name");
vpeClass.DumpTemplate(letter);
if (File.Exists(vpeFile))
File.Delete(vpeFile);
vpeClass.WriteDoc(vpeFile);
vpeClass.CloseDoc();


I then tried using the code from one example but got the runtime error:

System.DllNotFoundException: Unable to load DLL 'vpec3271.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at IDEALSoftware.VpeCommunity.VPEDLL.VpeOpenDocFile(IntPtr hWndParent, String file_name, String title, Int32 flags)
at IDEALSoftware.VpeCommunity.VpeControl.OpenDoc()
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
the code follows. kindly assist as


// The Standard Edition is delivered with all example images as BMP's,
// because it is not able to read JPG, TIF, PNG, etc.
const string wood = "C:\\Program Files\\VPE_C64.710\\images\\wood.bmp";
const string sand = "C:\\Program Files\\VPE_C64.710\\images\\sand.bmp";
const string bau = "C:\\Program Files\\VPE_C64.710\\images\\bau.bmp";
const string silence = "C:\\Program Files\\VPE_C64.710\\images\\silence.bmp";
const string vpelogo = "C:\\Program Files\\VPE_C64.710\\images\\vpelogo.bmp";

var welcome = new VpeControl();
MessageBox.Show("This demo shows images in true-color, which might not look that good in other color resolutions.");
welcome.OpenDoc();
welcome.DevJobName = "Welcome";
welcome.PreviewDoc(-1, 0, 0, 0, PreviewState.Maximized);
welcome.OpenProgressBar();

// Set PenSize = 0 to avoid frames drawn around the images:
welcome.NoPen();
welcome.Picture(0, 0, 19, 13.5, wood);
welcome.PenSize = 0.03;
if (welcome.Edition >= Edition.Standard)
welcome.Print(0.5, 8, "[N 'Times New Roman' S 32 I U Rot 2700]The Story");
welcome.StatusProgress = 16;

welcome.Picture(1, 1, welcome.nFree, welcome.nFree, sand);
welcome.Print(1.2, 0.5, "['Times New Roman' S 12]Most of the time, I walk around like that.");
welcome.StatusProgress = 33;

welcome.Picture(10, 3.5, welcome.nFree, welcome.nFree, bau);
welcome.Print(10.2, 3, "My tools and components look like this.");
welcome.StatusProgress = 50;

welcome.Picture(2.5, 7.5, welcome.nFree, welcome.nFree, silence);
welcome.Write(welcome.nLeft, welcome.nTop, welcome.nRight, welcome.nBottom, " Yes, I wish I could be there...\nEverything would be so easy.");
welcome.Write(11, 11, -6.5, welcome.nFree, "[N 'Arial' S 10 C White]Well, we can't solve all of your problems, but in case of printing and on-screen presentations... (please turn the page)");
welcome.StatusProgress = 66;

welcome.PageBreak();
welcome.NoPen();
welcome.Picture(0, 0, 19, 17.5, wood);
welcome.PenSize = 0.03;
welcome.Write(0, 1, 19, welcome.nFree, "['Times New Roman' FontSize 36 Italic Underline Center]Welcome to a New Software:");
welcome.StatusProgress = 83;
welcome.Picture(3.5, 3, welcome.nFree, welcome.nFree, vpelogo);
welcome.StatusProgress = 100;
welcome.CloseProgressBar();

ExportDocument("Welcome.pdf", welcome);

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ptah101
 
Posts: 2
Joined: Wed May 18, 2016 8:19 am

Re: C# Console Application to Generate PDF

Postby IDEAL Software Support » Wed May 18, 2016 2:36 pm

We don't know what VPECTRLLib is, nor what VPEClass is. These types are not defined by VPE. It seems you are using namespaces / classes developed in-house.
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 12 guests