Hi PoDoFo devs! I'm using Ubuntu Bionic 18.04 and a shipped version of PoDoFo which is 0.9.5-9. I use FormTest.cpp to update the existing PDF document with just a single text field (please find it attached, it's name.pdf). I modified FormTest so it updates all the text fields to "xxx". FormTest is able to update the document and save it as name-edit.pdf. However, the text field in name-edit.pdf is still empty. If I click on it, a lineedit with "xxx" appears. But if it loses the focus, it reverts to an empty text again. Could you please help me with the issue?
-- Dmitry
/*************************************************************************** * Copyright (C) 2007 by Dominik Seichter * * domseich...@web.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "podofo.h" #include <iostream> #include <cstdio> using namespace PoDoFo; void FillTextField( PdfTextField & rField ) { const char* pszCur = rField.GetText().GetString(); std::cout << " Current value:" << (pszCur ? pszCur : "") << std::endl; std::string value("xxx"); rField.SetText( value ); } void FillListField( PdfListField & rField ) { const char* pszCur = ( rField.GetSelectedItem() == -1 ? NULL : rField.GetItemDisplayText( rField.GetSelectedItem() ).GetString() ); std::cout << " Current value:" << (pszCur ? pszCur : "") << std::endl; std::cout << " Values:" << std::endl; for( int i=0;i<static_cast<int>(rField.GetItemCount());i++ ) { pszCur = rField.GetItemDisplayText( i ).GetString(); std::cout << " " << i << " " << (pszCur ? pszCur : "") << std::endl; } int nValue; std::cout << " Enter index of new value:" << std::endl; std::cin >> nValue; if( nValue >= 0 && nValue < static_cast<int>(rField.GetItemCount()) ) rField.SetSelectedItem( nValue ); } void FillForm( const char* pszFilename, const char* pszOutput ) { PdfMemDocument doc( pszFilename ); PdfPage* pPage; int nPageCount = doc.GetPageCount(); int nFieldCount; for( int i=0;i<nPageCount;i++ ) { pPage = doc.GetPage( i ); nFieldCount = pPage->GetNumFields(); std::cout << "Page " << i + 1 << " contains " << nFieldCount << " fields." << std::endl; for( int n=0;n<nFieldCount;n++ ) { PdfField field = pPage->GetField( n ); EPdfField eType = field.GetType(); std::cout << " Field: " << field.GetFieldName().GetString() << std::endl; std::cout << " Type : "; switch( eType ) { case ePdfField_PushButton: std::cout << "PushButton" << std::endl; break; case ePdfField_CheckBox: std::cout << "CheckBox" << std::endl; break; case ePdfField_RadioButton: std::cout << "RadioButton" << std::endl; break; case ePdfField_TextField: { std::cout << "TextField" << std::endl; PdfTextField text( field ); FillTextField( text ); break; } case ePdfField_ComboBox: { std::cout << "ComboBox" << std::endl; PdfListField lst( field ); FillListField( lst ); break; } case ePdfField_ListBox: { std::cout << "ListBox" << std::endl; PdfListField lst( field ); FillListField( lst ); break; } case ePdfField_Signature: std::cout << "Signature" << std::endl; break; case ePdfField_Unknown: default: std::cout << "Unknown" << std::endl; break; } std::cout << std::endl; } } doc.Write( pszOutput ); } int main( int argc, char* argv[] ) { if( argc != 3 ) { printf("Usage: FormTest [output_filename]\n"); printf(" - Create a new example PDF form\n"); printf(" Formtest [input_filename] [output_filename]\n"); printf(" - Fill out an existing form and save it to a PDF file\n"); return 0; } FillForm( argv[1], argv[2] ); return 0; }
name-edit.pdf
Description: Adobe PDF document
name.pdf
Description: Adobe PDF document
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users