掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
MFCを使ってPDFファイルにJPEG画像を組み込むには? (ID:51745)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
// PnPdf.cpp : インプリメンテーション ファイル // #include "stdafx.h" #include "PnPdf.h" #include <fcntl.h> #include <io.h> #include <sys/stat.h> #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPnPdf CPnTiffItem::CPnTiffItem() { compress = 5; fillorder = 1; m_dat = NULL; } CPnTiffItem::~CPnTiffItem() { if ( m_dat != NULL ) { delete m_dat; m_dat = NULL; } } CPnTiff::CPnTiff() { m_cfname = _T(""); fp = -1; m_ntcnt = 0; m_ncid = 0; m_njp = 0; } CPnTiff::~CPnTiff() { } /* int PdfSubInt(int *oi,char *iss,int spos,int inbf) { int rc; if ( inbf == 0 ) { rc = PNetSubInt(oi,iss,spos); } else { rc = PNetSubIntn(oi,iss,spos); } return(rc); } int PdfSubShort(int *oi,char *iss,int spos,int inbf) { int rc; if ( inbf == 0 ) { rc = PNetSubShort(oi,iss,spos); } else { rc = PNetSubShortn(oi,iss,spos); } return(rc); } */ int CPnTiff::OpenFile(LPCSTR fname) { CPnTiffItem *tItem; char fname1[250],buf[10]; int i,stop,rc,pos,rpos,rpos1,tagn,id,inbf; inbf = 0; m_ntcnt = 0; rpos = 8; m_nts = 0; strcpy(fname1,fname); fp = _open(fname,_O_RDONLY|_O_BINARY); if ( fp < 0 ) { char dv[10],fpath[200],ftitle[100],ext[10]; _splitpath(fname,dv,fpath,ftitle,ext); if ( stricmp(ext,".img")==0 ) { sprintf(fname1,"%s%s%s.DOC",dv,fpath,ftitle); fp = _open(fname1,_O_RDONLY|_O_BINARY); if ( fp > -1 ) { _read(fp,fpath,12); PNetSubInt(&m_nts,fpath,0); m_nts += 12; } } } if ( fp > -1 ) { _lseek(fp,m_nts,SEEK_SET); _read(fp,buf,2); if ( strncmp(buf,"MM",2) == 0 ) { inbf = 1; } m_cfname = fname1; if ( m_njp == 0 ) { for ( stop=0;stop==0; ) { rc = _lseek(fp,rpos+m_nts,SEEK_SET); if ( (rpos+m_nts) != rc ) stop = 1; else { _lseek(fp,rpos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&tagn,buf,0,inbf); _lseek(fp,rpos+2+tagn*12+m_nts,SEEK_SET); rc = _read(fp,buf,4); if ( rc < 4 ) stop=1; else { PdfSubInt(&rpos1,buf,0,inbf); if ( rpos1 < 9 ) stop=1; tItem = new CPnTiffItem; for ( i=0;i<tagn;i++ ) { pos = rpos+2+i*12; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&id,buf,0,inbf); switch ( id ) { case 256: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->w,buf,0,inbf); break; case 257: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->h,buf,0,inbf); break; case 279: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->size,buf,0,inbf); break; case 273: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->pos,buf,0,inbf); break; case 259: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&tItem->compress,buf,0,inbf); break; case 266: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&tItem->fillorder,buf,0,inbf); break; } } tItem->no = m_ntcnt; m_titem.AddTail(tItem); rpos = rpos1; m_ntcnt++; } } } } else { for ( stop=0;stop==0; ) { rc = _lseek(fp,rpos+m_nts,SEEK_SET); if ( (rpos+m_nts) != rc ) stop = 1; else { _lseek(fp,rpos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&tagn,buf,0,inbf); _lseek(fp,rpos+2+tagn*12+m_nts,SEEK_SET); rc = _read(fp,buf,4); if ( rc < 4 ) stop=1; else { PdfSubInt(&rpos1,buf,0,inbf); if ( rpos1 < 9 ) stop=1; tItem = new CPnTiffItem; for ( i=0;i<tagn;i++ ) { pos = rpos+2+i*12; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&id,buf,0,inbf); switch ( id ) { case 256: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->w,buf,0,inbf); break; case 257: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->h,buf,0,inbf); break; case 279: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->size,buf,0,inbf); break; case 273: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,4); PdfSubInt(&tItem->pos,buf,0,inbf); break; case 259: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&tItem->compress,buf,0,inbf); break; case 266: pos+=8; _lseek(fp,pos+m_nts,SEEK_SET); _read(fp,buf,2); PdfSubShort(&tItem->fillorder,buf,0,inbf); break; } } tItem->no = m_ntcnt; m_titem.AddTail(tItem); rpos += 260; // rpos = rpos1; m_ntcnt++; } } } } return(0); } else { return(-1); } } void CPnTiff::CloseFile() { CPnTiffItem *tItem; POSITION pos; pos = m_titem.GetHeadPosition(); while ( pos != NULL ) { tItem = m_titem.GetNext(pos); if ( tItem != NULL ) { delete tItem; } } m_titem.RemoveAll(); if ( fp > -1 ) { _close(fp); } } CPnTiffItem *CPnTiff::GetTiffItem(int no) { CPnTiffItem *tItem; POSITION pos; pos = m_titem.GetHeadPosition(); while ( pos != NULL ) { tItem = m_titem.GetNext(pos); if ( tItem != NULL ) { if ( tItem->no == no ) { return(tItem); } } } return(NULL); } char *CPnTiff::GetTiffData(CPnTiffItem *tItem) { char wmsg[10],*ret; int i; ret = new char[tItem->size]; _lseek(fp,tItem->pos+m_nts,SEEK_SET); _read(fp,ret,tItem->size); if ( tItem->fillorder == 2 ) { for ( i=0;i<tItem->size;i++ ) { wmsg[0] = ret[i]; wmsg[1] = 0; if ( bmc_qus(wmsg,0) == 1 ) bmc_set(wmsg,15); if ( bmc_qus(wmsg,1) == 1 ) bmc_set(wmsg,14); if ( bmc_qus(wmsg,2) == 1 ) bmc_set(wmsg,13); if ( bmc_qus(wmsg,3) == 1 ) bmc_set(wmsg,12); if ( bmc_qus(wmsg,4) == 1 ) bmc_set(wmsg,11); if ( bmc_qus(wmsg,5) == 1 ) bmc_set(wmsg,10); if ( bmc_qus(wmsg,6) == 1 ) bmc_set(wmsg,9); if ( bmc_qus(wmsg,7) == 1 ) bmc_set(wmsg,8); ret[i] = wmsg[1]; } tItem->fillorder = 1; } return(ret); } CPnObj::CPnObj() { no = 0; type = 0; p1 = 0; p2 = 0; p3 = 0; p4 = 0; p5 = 0; p6 = 0; dat = _T(""); s1 = _T(""); s2 = _T(""); s3 = _T(""); s4 = _T(""); s5 = _T(""); s6 = _T(""); int i; for ( i=0;i<10;i++ ) { xy[i] = 0; } } CPnObj::~CPnObj() { } CPnPdf::CPnPdf() { m_cfname = _T(""); A4w = 595; A4h = 842; m_nobjcnt = 0; m_nfontcount = 0; m_nimgcount = 0; } CPnPdf::~CPnPdf() { } int CPnPdf::OpenFile(LPCSTR fname) { CPnObj *obj; m_cfname = fname; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 0; m_obj.AddTail(obj); obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 1; m_obj.AddTail(obj); return(0); } void CPnPdf::CloseFile(int fp) { CPnObj *obj; POSITION pos; CString txt,txt1; char *add; int len,alen; txt = MakePdf(); /* add = NULL; alen = 0; len = txt.GetLength(); if ( len < 10000 ) { alen = 10000 - len; add = (char *)malloc(alen+1); memset(add,' ',alen); *(add+alen) = 0; txt += add; free(add); } */ if ( fp == -1 ) { fp = _open(m_cfname,_O_BINARY|_O_CREAT|_O_TRUNC|_O_RDWR,_S_IREAD|_S_IWRITE); if ( fp > -1 ) { _write(fp,(LPCSTR)txt,txt.GetLength()); _close(fp); } } else { len = txt.GetLength(); _write(fp,(char *)&len,sizeof(int)); _write(fp,(LPCSTR)txt,txt.GetLength()); /* if ( len < 10000 ) { add = (char *)malloc(10000); memset(add,0x0a,10000); memcpy(add,(LPCSTR)txt,len); len = 10000; _write(fp,(char *)&len,sizeof(int)); _write(fp,add,len); free(add); } else { _write(fp,(char *)&len,sizeof(int)); _write(fp,(LPCSTR)txt,txt.GetLength()); } */ } pos = m_obj.GetHeadPosition(); while ( pos != NULL ) { obj = m_obj.GetNext(pos); if ( obj != NULL ) { delete obj; } } m_obj.RemoveAll(); } CPnObj *CPnPdf::GetObjByType(int type) { CPnObj *obj; POSITION pos; pos = m_obj.GetHeadPosition(); while ( pos != NULL ) { obj = m_obj.GetNext(pos); if ( obj != NULL ) { if ( obj->type == type ) { return(obj); } } } return(NULL); } void CPnPdf::SetPdfInfo(LPCSTR Keywords,LPCSTR Subject,LPCSTR Title,LPCSTR Creator,LPCSTR Author) { CPnObj *obj; SYSTEMTIME stime; CString datetime; GetSystemTime(&stime); datetime.Format("%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d", stime.wYear,stime.wMonth,stime.wDay, stime.wHour,stime.wMinute,stime.wSecond); obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 2; obj->s1 = Keywords; obj->s2 = Subject; obj->s3 = Title; obj->s4 = Creator; obj->s5 = Author; obj->s6 = datetime; m_obj.AddTail(obj); } void CPnPdf::BeginPdfPage(int w,int h) { CPnObj *obj; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 3; obj->p1 = w; obj->p2 = h; m_obj.AddTail(obj); } void CPnPdf::EndPdfPage() { CPnObj *obj; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 13; m_obj.AddTail(obj); } int CPnPdf::CreatePdfFont(LPCSTR font,int type,LPCSTR enc) { CPnObj *obj; int nfcount; nfcount = m_nfontcount; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 4; obj->p1 = m_nfontcount++; obj->p2 = type; obj->s1 = font; obj->s2 = enc; m_obj.AddTail(obj); if ( nfcount == 0 ) { obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 5; obj->s1.Format("%d",nfcount); m_obj.AddTail(obj); } else { CString cmsg; obj = GetObjByType(5); cmsg.Format(",%d",nfcount); obj->s1 += cmsg; } return(nfcount); } CString ConvSpcialChar(LPCSTR txt) { CString ret; char wmsg[10]; int i,len; ret = _T(""); len = strlen(txt); for ( i=0;i<len;i++ ) { if ( (*(txt+i) == '(')||(*(txt+i) == ')') ) { ret += "\\"; } wmsg[0] = *(txt+i); wmsg[1] = 0; ret += wmsg; } return(ret); } void CPnPdf::ShowPdfTextBox(LPCSTR txt,int x,int y,int n1,int n2, LPCSTR wpos,LPCSTR n3,int font,int size) { CPnObj *obj; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 10; obj->dat = ConvSpcialChar(txt); obj->p1 = x; obj->p2 = y; obj->p3 = n1; obj->p4 = n2; obj->p5 = font; obj->p6 = size; obj->s1 = wpos; obj->s2 = n3; m_obj.AddTail(obj); } void CPnPdf::ShowPdfDrawBox(int x,int y,int w,int h,int th) { CPnObj *obj; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 14; obj->xy[0] = x; obj->xy[1] = y; obj->xy[2] = x+w; obj->xy[3] = y; obj->xy[4] = x+w; obj->xy[5] = y+h; obj->xy[6] = x; obj->xy[7] = y+h; obj->xy[8] = x; obj->xy[9] = y; obj->p1 = th; obj->p2 = 5; m_obj.AddTail(obj); } void CPnPdf::ShowPdfDrawBmp(LPCSTR img,int imgs,int iw,int ih,int x,int y,int w,int h,int th) { CPnObj *obj; obj = new CPnObj; obj->no = ++m_nobjcnt; obj->dat = CString(img,imgs); obj->type = 15; obj->xy[0] = iw; obj->xy[1] = ih; obj->xy[2] = x; obj->xy[3] = y; obj->xy[4] = w; obj->xy[5] = h; obj->p1 = th; obj->p2 = 5; m_obj.AddTail(obj); } int CPnPdf::CheckBaseFont(LPCSTR face) { if ( strcmp(face,"Times-Roman")==0 ) { return(0); } return(1); } CString CPnPdf::GetBaseFont(int objno,LPCSTR face,LPCSTR enc,int type) { CString ret; ret.Format("%d 0 obj\n" "<<\n" "/Type /Font\n" "/Subtype /CIDFontType2\n" "/BaseFont /#82l#82r#83S#83V#83b#83N\n" "/WinCharSet 128\n" "/FontDescriptor %d 0 R\n" "/CIDSystemInfo\n" "<<\n" "/Registry(Adobe)\n" "/Ordering(Japan1)\n" "/Supplement 2\n" ">>\n" "/DW 1000\n" "/W [\n" "231 389 500\n" "631 631 500\n" "]\n" ">>\n" "endobj\n",objno,objno+1); return(ret); } CString CPnPdf::GetFontName(int objno,LPCSTR face,LPCSTR enc,int type) { CString ret; ret.Format("%d 0 obj\n" "<<\n" "/Type /FontDescriptor\n" "/FontName /#82l#82r#83S#83V#83b#83N\n" "/Flags 7\n" "/FontBBox [ -100 -141 1100 1000 ]\n" "/MissingWidth 500\n" "/StemV 91\n" "/StemH 91\n" "/ItalicAngle 0\n" "/CapHeight 859\n" "/XHeight 430\n" "/Ascent 859\n" "/Descent -141\n" "/Leading 0\n" "/MaxWidth 1000\n" "/AvgWidth 500\n" "/Style\n" "<< /Panose <000000400000000000000000> >>\n" ">>\n" "endobj\n",objno); return(ret); } void CPnPdf::ShowPdfImageBox(LPCSTR img,int imgw,int imgh,int imgs, int swx,int swy,int sww,int swh,int flg) { CPnObj *obj; int isno,skh,skw; if ( imgw * swh > imgh * sww ) { skh = imgh * sww / imgw; skw = sww; } else { skh = swh; skw = imgw * swh / imgh; } obj = new CPnObj; obj->no = ++m_nobjcnt; isno = obj->no; obj->dat = CString(img,imgs); obj->type = 11; obj->p1 = imgw; obj->p2 = imgh; obj->p3 = imgs; obj->p4 = m_nimgcount; m_obj.AddTail(obj); obj = new CPnObj; obj->no = ++m_nobjcnt; obj->type = 12; obj->p1 = swx; obj->p2 = swy; obj->p3 = skw; obj->p4 = skh; obj->p5 = flg; obj->p6 = m_nimgcount; m_obj.AddTail(obj); m_nimgcount++; } CString CPnPdf::FindFontResouce(int fno) { CPnObj *obj; POSITION pos; CString res; res = _T(""); pos = m_obj.GetHeadPosition(); while ( pos != NULL ) { obj = m_obj.GetNext(pos); if ( obj != NULL ) { if ( obj->type == 4 ) { if ( obj->p1 == fno ) { res.Format("/F%d %d 0 R\n",obj->p1,obj->no); pos = NULL; } } } } return(res); } unsigned char idbitc[] = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 }; int bmc_iqus(char *ibit,int qus_no) { unsigned char *bit; int byte; int bits; bit = (unsigned char *)ibit; byte = (int)(qus_no / 8); bits = (int)(qus_no % 8); if ((*(bit + byte) & idbitc[bits])==idbitc[bits]) { return(1); } else { return(0); } } CString CPnPdf::MakePdf() { CPnObj *obj,*pobj; POSITION pos; CString ret,cmsg,objs,txt,gra,tres,ires; CString kids; int objno,objlen; int resouceno,xrpos; int hh; int objpos[30000],i,j; int contents[30000],ci; int page,ofs; ofs = 0; ret = _T(""); obj = GetObjByType(3); if ( obj == NULL ) return(ret); hh = obj->p2; // Init Parameter objno = 4; for ( i=0;i<30000;i++ ) { objpos[i] = 0; contents[i] = 0; } page = 0; ci = 0; kids = _T(""); // Header ret = _T("%PDF-1.3\n"); // Struct pos = m_obj.GetHeadPosition(); while ( pos != NULL ) { obj = m_obj.GetNext(pos); if ( obj != NULL ) { if ( obj->type == 3 ) { pobj = obj; txt = _T(""); gra = _T(""); tres = _T(""); ires = _T(""); pobj->no = objno++; } else if ( obj->type == 4 ) { // SetFontSource obj->no = objno; objpos[objno] = ret.GetLength(); objs.Format("%d 0 obj\n",objno++); objs += _T("<</Type/Font\n"); cmsg.Format("/Subtype/Type%d\n",obj->p2); objs += cmsg; cmsg.Format("/Encoding/%s\n",obj->s2); objs += cmsg; cmsg.Format("/BaseFont/%s\n",obj->s1); objs += cmsg; if ( CheckBaseFont(obj->s1) == 1 ) { cmsg.Format("/DescendantFonts [ %d 0 R ]\n",objno); objs += cmsg; } objs += _T(">>\nendobj\n"); ret += objs; if ( CheckBaseFont(obj->s1) == 1 ) { objpos[objno] = ret.GetLength(); objs = GetBaseFont(objno++,obj->s1,obj->s2,obj->p2); ret += objs; objpos[objno] = ret.GetLength(); objs = GetFontName(objno++,obj->s1,obj->s2,obj->p2); ret += objs; } cmsg.Format("/F%d %d 0 R\n",obj->p1,obj->no); tres += cmsg; } else if ( obj->type == 11 ) { // SetImageSource cmsg.Format("/I%d %d 0 R\n",obj->p4,objno); //obj->no); ires += cmsg; objpos[objno] = ret.GetLength(); obj->no = objno; cmsg.Format("%d 0 obj\n" "<</Type/XObject\n" "/Subtype/Image\n" "/Width %d\n" "/Height %d\n" "/BitsPerComponent 1\n" "/ColorSpace/DeviceGray\n" "/Filter[/CCITTFaxDecode]\n" "/DecodeParms[<</Columns %d/Rows %d/K -1>>]\n" "/Length %d\n>>\nstream\n", objno,obj->p1,obj->p2,obj->p1,obj->p2,obj->p3); ret += cmsg; ret += obj->dat; ret += "endstream\nendobj\n"; objno++; } else if ( obj->type == 12 ) { // ShowImageBox objs = _T(""); objs += "q\n"; cmsg.Format("%d 0 0 %d %d %d cm\n",obj->p3,obj->p4,obj->p1,hh - obj->p2 - obj->p4); objs += cmsg; cmsg.Format("/I%d Do\n",obj->p6); objs += cmsg; objs += "Q\n"; objlen = objs.GetLength(); objpos[objno] = ret.GetLength(); contents[ci++] = objno; cmsg.Format("%d 0 obj\n<<\n/Length %d\n>>\n",objno,objlen); cmsg += "stream\n"; ret += cmsg; ret += objs; ret += "endstream\n"; ret += "endobj\n"; objno++; } else if ( obj->type == 14 ) { if ( gra == "" ) { gra.Format("%d w\n",obj->p1); } for ( i=0;i<obj->p2;i++ ) { if ( i == 0 ) { cmsg.Format("%d %d m\n",obj->xy[i*2],hh-obj->xy[i*2+1]); } else { cmsg.Format("%d %d l\n",obj->xy[i*2],hh-obj->xy[i*2+1]); } gra += cmsg; } gra += _T("S\n"); } else if ( obj->type == 15 ) { if ( gra == "" ) { gra.Format("%d w\n",obj->p1); } for ( i=0;i<obj->xy[1];i++ ) { for ( j=0;j<obj->xy[0];j++ ) { if ( bmc_iqus((char *)(LPCSTR)obj->dat,i*obj->xy[0]+j) == 1 ) { cmsg.Format("%d %d m\n",obj->xy[2]+j*obj->xy[4]/obj->xy[0],hh-obj->xy[3]-i*obj->xy[5]/obj->xy[1]-5); gra += cmsg; cmsg.Format("%d %d l\n",obj->xy[2]+j*obj->xy[4]/obj->xy[0],hh-obj->xy[3]-i*obj->xy[5]/obj->xy[1]-5); gra += cmsg; } } } gra += _T("S\n"); } else if ( obj->type == 10 ) { // ShowTextBox if ( txt == "" ) { txt.Format("/F%d %d Tf\n",obj->p5,obj->p6); ofs = obj->p6; } else { if ( ofs != obj->p6 ) { cmsg.Format("/F%d %d Tf\n",obj->p5,obj->p6); txt += cmsg; ofs = obj->p6; } } cmsg.Format("1 0 0 1 %d %d Tm\n",obj->p1,hh - obj->p2 - obj->p6); txt += cmsg; txt += "("; txt += obj->dat; txt += ")Tj\n"; if ( tres == "" ) { tres = FindFontResouce(obj->p5); } } else if ( obj->type == 13 ) { // Out Text Struct if ( txt != "" ) { objs = _T(""); objs += "BT\n"; objs += txt; objs += "ET\n"; objlen = objs.GetLength(); objpos[objno] = ret.GetLength(); contents[ci++] = objno; cmsg.Format("%d 0 obj\n<<\n/Length %d\n>>\n",objno,objlen); cmsg += "stream\n"; ret += cmsg; ret += objs; ret += "endstream\n"; ret += "endobj\n"; objno++; } if ( gra != "" ) { objlen = gra.GetLength(); objpos[objno] = ret.GetLength(); contents[ci++] = objno; cmsg.Format("%d 0 obj\n<<\n/Length %d\n>>\n",objno,objlen); cmsg += "stream\n"; ret += cmsg; ret += gra; ret += "endstream\nendobj\n"; objno++; } // Make Page Resouce objpos[objno] = ret.GetLength(); resouceno = objno; cmsg.Format("%d 0 obj\n",objno++); objs = cmsg; objs += _T("<</ProcSet[/PDF"); if ( ires != "" ) { objs += _T("/ImageB"); } if ( tres != "" ) { objs += _T("/Text"); } objs += _T("]\n"); if ( tres != "" ) { objs += _T("/Font<<\n"); objs += tres; objs += _T(">>\n"); } if ( ires != "" ) { objs += _T("/XObject<<\n"); objs += ires; objs += _T(">>\n"); } objs += _T(">>\nendobj\n"); ret += objs; objs = _T(""); objpos[pobj->no] = ret.GetLength(); cmsg.Format("%d 0 R ",pobj->no); kids += cmsg; page++; cmsg.Format("%d 0 obj\n<<\n/Type/Page\n",pobj->no); objs += cmsg; objs += _T("/Parent 1 0 R\n"); cmsg.Format("/Resources %d 0 R\n",resouceno); objs += cmsg; cmsg.Format("/MediaBox[0 0 %d %d]\n",pobj->p1,pobj->p2); objs += cmsg; cmsg.Format("/Contents["); objs += cmsg; for ( i=0;i<ci;i++ ) { cmsg.Format("%d 0 R ",contents[i]); objs += cmsg; } cmsg.Format("]\n>>\nendobj\n"); objs += cmsg; ret += objs; ci = 0; } } } // Page Data pos = m_obj.GetHeadPosition(); while ( pos != NULL ) { obj = m_obj.GetNext(pos); if ( obj != NULL ) { if ( obj->type == 0 ) { objpos[1] = ret.GetLength(); objs = _T("1 0 obj\n<<\n/Type/Pages\n"); cmsg.Format("/Count %d\n",page); objs += cmsg; cmsg.Format("/Kids[%s]\n>>\nendobj\n",kids); objs += cmsg; ret += objs; } else if ( obj->type == 1 ) { objpos[2] = ret.GetLength(); objs = _T("2 0 obj\n<<\n/Type/Catalog\n"); objs += _T("/Pages 1 0 R\n"); objs += _T(">>\nendobj\n"); ret += objs; } else if ( obj->type == 2 ) { objpos[3] = ret.GetLength(); objs = _T("3 0 obj\n<<\n"); cmsg.Format("/Keywords (%s)\n",obj->s1); objs += cmsg; cmsg.Format("/Subject (%s)\n",obj->s2); objs += cmsg; cmsg.Format("/Title (%s)\n",obj->s3); objs += cmsg; cmsg.Format("/Creator (%s)\n",obj->s4); objs += cmsg; cmsg.Format("/Author (%s)\n",obj->s5); objs += cmsg; cmsg.Format("/CreationDate (D:%s)\n",obj->s6); objs += cmsg; objs += "/Producer ()\n"; objs += ">>\nendobj\n"; ret += objs; } } } xrpos = ret.GetLength(); objs.Format("xref\n0 %d\n",objno); objs += _T("0000000000 65535 f \n"); for ( i=1;i<objno;i++ ) { cmsg.Format("%10.10d 00000 n \n",objpos[i]); objs += cmsg; } cmsg.Format("trailer\n<</Size %d\n/Info 3 0 R\n/Root 2 0 R\n>>\n",objno); objs += cmsg; cmsg.Format("startxref\n%d\n",xrpos); objs += cmsg; ret += objs; ret += _T("%%EOF\n"); return(ret); }
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.