I’m trying without luck to get Stamping to work in C#.
Can someone please post an example piece of code.
Thanks
I’m trying without luck to get Stamping to work in C#.
Can someone please post an example piece of code.
Thanks
Hi,
while we don’t have an example for stamping directly, feel free to post your code here or send it to support(at)pdfforge(dot)org and we will help you get it working.
Best regards,
Robin
I have a “CoverPage.pdf” file that I created in Word (save as PDF) that is blank. I’m trying to open that file and add a stamp to it… the text is unimportant at this stage, just getting something written to is my goal here.
Any help would be greatly appreciated.
Here is my code.
private void CreateCoverPage(string outputLocation, string FileName)
{
// we have a default cover page that we will use and add text too.
// taht will then be added as the first page of a document.
string CoverPageTemplate = "C:\\PERMIS\\ImportFiles\\PERMISCoverPage.pdf";
string CoverPage = outputLocation + FileName.Replace("pdf", "") + "_cover.pdf";
// The job queue is the object used to convert the print job
var jobQueue = new Queue();
// the PDFCreatorOBJ is teh object used to Initate the Print.
PdfCreatorObj pdfPrinter = new PdfCreatorObj();
// start the queue listener
jobQueue.Initialize();
// print the PDF to the PDFCreator Printer.
pdfPrinter.AddFileToQueue(CoverPageTemplate);
// Now lets grab all the stuff in the printer QUEUE.
if (!jobQueue.WaitForJob(10))
{
MessageBox.Show("The job didn't arrive within 10 seconds");
}
else
{
var printJob = jobQueue.NextJob;
// set soem values for the TIF Image.
// this will be converted to a MultiPage Tiff Image.
printJob.SetProfileByGuid("DefaultGuid");
printJob.SetProfileSetting("OpenViewer", "true");
// lets add the "stamp" or cover page text to this pdf document.
// I’ve tried every combination I can think of nothing works.
//printJob.SetProfileSetting(“Stamping.Enabled”, “true”);
//printJob.SetProfileSetting(“Stamping.FontSize”, “10.0”);
//printJob.SetProfileSetting(“Stamping.Color”, “#FF0000”);
// printJob.SetProfileSetting(“Stamping.StampText”, “HELLO this is a test”);
//printJob.SetProfileSetting(“Stamping.PostScriptFontName”, “Arial Black”);
printJob.SetProfileSetting("OutputFormat", "Pdf");
// COnvert the PDF to TIFF
printJob.ConvertTo(CoverPage);
if (!printJob.IsFinished || !printJob.IsSuccessful)
{
MessageBox.Show("Could not convert: ");
}
}
jobQueue.ReleaseCom();
jobQueue = null;
pdfPrinter = null;
}
Hi,
according to the documentaion, only .PS files can be added with AddFileToQueue, which could be the cause of the problem.
“void AddFileToQueue(string path)
Summary: Adds a file directly to the queue without
the need of printing. Currently, only .PS files can be added directly,
in future COM Interface versions this might change.
path: The path to the file which should be added.”
You will need to use:
"void PrintFile(string filePath)
Summary: Executes print command on the file specified by the parameter filePath.
filePath: The path to the file which should be printed.
Note
If it is necessary to change the default printer and the
PDFCreator default printer setting in the application settings at the
general tab is set to “ask”, this method will not print your file. Be aware that the default value is “ask”.
Instead use the method named PrintFileSwitchingPrinters described below."
or print the file to any PDFCreator printer directly from native C# code.
Best regards,
Robin