MFC Scribble - SDK sample

Download Sample
Download size: 69.1KB
[Format: ZIP]
Note: To be able to use the samples you must install novaPDF SDK as samples work only with it. Download it here: nova PDF SDK.

The MFC Scribble sample extends the standard MFC Scribble sample with the generation of PDF files using novaPDF. It demonstrates how to integrate novaPDF SDK in a document/view MFC architecture:


Source Code Snippets

1. Register novaPDF Printer event
#define PROFILE_NAME      L"MFCScribble Profile"
#define PDF_FILE_NAME     L"MFCScribble.pdf"
#define PROFILE_IS_PUBLIC 0 

// This message is sent when the PDF file is finished and saved on the harddisk
const UINT  wm_Nova_FileSaved = RegisterWindowMessageW( MSG_NOVAPDF2_FILESAVED );
BEGIN_MESSAGE_MAP(CScribbleView, CScrollView)
//{{AFX_MSG_MAP(CScribbleView)
//...
//}}AFX_MSG_MAP
//...
ON_REGISTERED_MESSAGE(wm_Nova_FileSaved, OnNovaPDFFileSaved)
END_MESSAGE_MAP()

 

2. Initialize INovaPDFOptions
CScribbleView::CScribbleView()
{
//...
HRESULT hr = CoInitialize(NULL);
//...
//create novaPDFOptions object
hr = CoCreateInstance(__uuidof(NovaPdfOptions), NULL, CLSCTX_INPROC_SERVER, __uuidof(INovaPdfOptions), (LPVOID*) &m_pNova);
//...
//initialize novaPDFOptions object with desired printer name
// if you have an application license for novaPDF SDK,
// pass both the registration name and the license key to the Initialize() function
// m_pNova->Initialize(L"novaPDF Pro v5", L"<registration name>", L"<license key>");
m_pNova->Initialize(L"novaPDF Pro v5", L"", L"", L"");
}

3. Release INovaPDFOptions 

CScribbleView::~CScribbleView()
{
//release novaPDFOptions object
if (m_pNova){
  m_pNova->Release();
}
CoUninitialize();
} 

4. Set novaPDF Printer Options
BOOL CScribbleView::OnPreparePrinting(CPrintInfo* pInfo)
{
//set novaPDF default printer
if (m_pNova){
  m_pNova->SetDefaultPrinter(); 

  // create a temporary profile for the current print job,
  // in order to not modify the default profile settings
  m_pNova->AddProfile(PROFILE_NAME, PROFILE_IS_PUBLIC);
  // set PDF document Title
  m_pNova->SetOptionString(NOVAPDF_INFO_TITLE, L"MFC Scribble Sample", PROFILE_NAME, PROFILE_IS_PUBLIC);
  // set resulting file name
  m_pNova->SetOptionString(NOVAPDF_SAVE_FOLDER, L"", PROFILE_NAME, PROFILE_IS_PUBLIC);
  m_pNova->SetOptionString(NOVAPDF_SAVE_FILE, PDF_FILE_NAME, PROFILE_NAME, PROFILE_IS_PUBLIC);
  //do not show prompt dialog
  m_pNova->SetOptionLong(NOVAPDF_SAVE_PROMPT, 0, PROFILE_NAME, PROFILE_IS_PUBLIC);
  //if file exists, override
  m_pNova->SetOptionLong(NOVAPDF_SAVE_CONFLICT_STRATEGY, FILE_CONFLICT_STRATEGY_OVERWRITE, PROFILE_NAME, PROFILE_IS_PUBLIC); 

  // set active profile
  m_pNova->GetActiveProfile(&m_wsDefaultProfile, &m_nActiveProfilePublic);
  m_pNova->SetActiveProfile(PROFILE_NAME, PROFILE_IS_PUBLIC); 

  //register window to receive messages from novaPDF printer
  m_pNova->RegisterEventWindow((LONG)m_hWnd);
}
//...
}

5. Restore options when printing finished
void CScribbleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
if (m_pNova) {
  //unregister events
  m_pNova->UnRegisterEventWindow();
  //restore default profile
  m_pNova->SetActiveProfile(m_wsDefaultProfile, &m_nActiveProfilePublic);
  m_pNova->DeleteProfile(PROFILE_NAME, PROFILE_IS_PUBLIC);
  CoTaskMemFree(m_wsDefaultProfile);
  //restore default printer
  m_pNova->RestoreDefaultPrinter();
}
} 

6. novaPDF Printer message handler
LRESULT CScribbleView::OnNovaPDFFileSaved(WPARAM, LPARAM)
{
//PDF is saved, so just show a message that the conversion to PDF was successful
MessageBox(L"PDF file was saved successfully", L"novaPrint");
return 0;
}

© 2002-2008 Softland. All Rights Reserved.
PDF Creator novaPDF
Create PDF for your paperless office
home Home   contact usContact us   partnershipsPartnerships   bookmarkBookmark   Site updated: 28-August-2008
Downloads Download Now

Download, install and use novaPDF. Latest version: 5.5 build 271

Download PDF creator
promotionsSpecial Offers

Current discounts:
- up to 25% for Desktop Editions
- up to 25% for Server Editions
- 20% Academic Discount
- up to 16% for Developer Tools

buyBuy Now
Professional edition $39.95
(Save $10)
Standard edition $29.95
(Save $10)
Lite edition $19.95
(Save $5)
Buy Now
newsLatest News

novaPDF 5.5 released
August 28, 2008

What’s new (read more):
 » Added Import/Export profiles option
 » Added external function exit code to cancel print job in novaPDF OEM
 » Added "/RegisterWin32COM" install parameter for silent installers
 » Added "/DoNotAskReason" command line parameter for silent uninstalling
 » Added new large printing forms (A0)
 » Added Norwegian and Turkish interface languages

sdkDeveloper Tools

novaPDF SDK is a software development toolkit that can be used by software developers and programmers to add the ability to create PDF files in their applications.
novaPDF OEM is a PDF solution that programmers can use to generate PDF files that will be post-processed by their applications. […]

Reviews & User QuotesPDF Creator Reviews
"novaPDF is a really neat tool. Basically, it’s a PDF printer driver that prints to a PDF file instead of paper.
See more reviews about nova PDF
[…] novaPDF is a great product that works without forcing the user to configure anything. The convenience alone is worth the money." […]
Jason Pullara, Editor
Currently supported languagesLanguages

News:
- Norwegian language added.

Help us translate novaPDF and we will give you licenses for novaPDF Professional and mention you on the Languages page. […]

awardsAwards

novaPDF received the Editor’s Pick from Soft32, a major download site:

PDF creator reviews

See the Awards page for more ratings.

NewsletterKnowledgebase articles

Latest articles on how to:
 » Create PDF files
 » Convert JPG to PDF
 » Convert Powerpoint to PDF
 » Convert Publisher to PDF
 » Convert web pages to PDF
Full article list in the knowledgebase.