Pechkin converting webpage to pdf c# gives empty pdf. - c#

I am exploring Pechkin to convert webpage to PDF. I have used article: http://ourcodeworld.com/articles/read/366/how-to-generate-a-pdf-from-html-using-wkhtmltopdf-with-c-in-winforms
Ref: How to use wkhtmltopdf.exe in ASP.net
When i try to convert using html string, it works !
byte[] pdfContent = new SimplePechkin(new GlobalConfig()).Convert("<html><body><h1>Hello world!</h1></body></html>");
However when I follow "Generate PDF from a Website" section, I get empty pdf.
configuration.SetCreateExternalLinks(false)
.SetFallbackEncoding(Encoding.ASCII)
.SetLoadImages(true)
.SetPageUri("http://ourcodeworld.com");
Has anyone encountered same issue? Appreciate all help/suggestions.

Try to use
https://github.com/tuespetre/TuesPechkin
var document = new HtmlToPdfDocument
{
GlobalSettings =
{
ProduceOutline = true,
DocumentTitle = "Pretty Websites",
PaperSize = PaperKind.A4, // Implicit conversion to PechkinPaperSize
Margins =
{
All = 1.375,
Unit = Unit.Centimeters
}
},
Objects = {
new ObjectSettings { HtmlText = "<h1>Pretty Websites</h1><p>This might take a bit to convert!</p>" },
new ObjectSettings { PageUrl = "www.google.com" },
new ObjectSettings { PageUrl = "www.microsoft.com" },
new ObjectSettings { PageUrl = "www.github.com" }
}
};
var tempFolderDeployment = new TempFolderDeployment();
var win32EmbeddedDeployment = new Win32EmbeddedDeployment(tempFolderDeployment);
var remotingToolset = new RemotingToolset<PdfToolset>(win32EmbeddedDeployment);
var converter = ThreadSafeConverter(remotingToolset);
byte[] pdfBuf = converter.Convert(document);
// Very important - overwise cpu will grow !!!
remotingToolset.Unload();
Edit
If someone else use this- please read my post here- very important!
https://stackoverflow.com/a/62428122/4836581
If you get errors use this link that help me-
TuesPechkin unable to load DLL 'wkhtmltox.dll'
Found it thanks to-
https://stackoverflow.com/a/26993484/4836581

Related

Get text from PDF with broken encoding using iText7

I'm trying to extract text from PDF using the following method:
public static string GetRectangleText(string pdfPath, int pageId, float[] rectangleDimensions)
{
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(pdfPath)))
{
var page = pdfDoc.GetPage(pageId);
iText.Kernel.Geom.Rectangle rect = new iText.Kernel.Geom.Rectangle(rectangleDimensions[0], rectangleDimensions[1], rectangleDimensions[2], rectangleDimensions[3]);
var filter = new IEventFilter[1];
filter[0] = new TextRegionEventFilter(rect);
var filteredTextEventListener = new FilteredTextEventListener(new LocationTextExtractionStrategy(), filter);
var result = PdfTextExtractor.GetTextFromPage(page, filteredTextEventListener);
return result;
}
}
While it works fine for most documents, several PDFs which would seem to have their encoding broken, return strings like ǪȃǷǻȁǭǵǶǬdzȇǹǺǸǶǰǺǭdzȄǹǺǪǨ ,668(')25&216758&7,21 what should in fact be ВЫПУЩЕНО ДЛЯ СТРОИТЕЛЬСТВА / ISSUED FOR CONSTRUCTION
I wonder if some kind of specific LocationTextExtractionStrategy would help?

Write Text file with tab-delimited in Asp.Net Core 2.2

Hi do you have any guides, work aid or step by step how to export to text with tab delimited. Im using Asp.Net Core 2.2 MVC EF. I want to export a list from my table.. I want to have a button where the user click in this DownloadFile Action will trigger.
public IActionResult DownloadFile()
{
var payments = new List<BdoPE>
{
new BdoPE
{
DocDateInDoc = "01/01/2019",
DocType = "DZ",
CompanyCode = "3000",
PosDateInDoc = "01/01/2019",
FiscalPeriod = "01",
CurrentKey = "PHP",
RefDocNum = "Over-The-Counter",
DocHeadT = "BDO",
PosKeyInNextLine = "40",
AccMatNextLine = "11231131",
AmountDocCur = "0000000010050",
ValDate = "01/01/2019",
AssignNum = "EEA",
ItemText = "1000136212 ",
PosKeyInNextLine2 = "15",
AccMatNextLine2 = "0115027FF",
AmountDocCur2 = "0000000010050",
BaseDateDueCal = "01/01/2019",
ItemText2 = "1000136212"
},
};
// I want this part to let the user select where they want to save the text file.
using (var writer = new StreamWriter("path\\to\\file.txt")) // not static location like this one.
using (var csv = new CsvWriter(writer))
{
csv.WriteHeader<BdoPE>();
csv.WriteRecord(payments);
}
// where should i put the delimiter part?
return;
}
You will need to setup the CsvWriter with a Configuration.
Thus, your code needs only a slight change:
[...]
var configuration = new CsvHelper.Configuration.Configuration();
configuration.Delimiter = '\t';
using (var csv = new CsvWriter(writer, configuration))
{
csv.WriteHeader<BdoPE>();
csv.WriteRecord(payments);
}
[...]
I use the code below to set the Delimiter using CsvHelper.
var config = new CsvConfiguration(CultureInfo.CurrentCulture)
{
Delimiter = "\t"
};

Filtering by .docx in ios document picker

What is the Uniform Type Identifer to provide to a UIDocumentMenuViewController to allow a user to select *.docx files?
The documentation in System-Declared Uniform Type Identifiers does not list a public UTType that allows filtering by .docx. An identifier exists for a standard *.doc file but not *.docx, is there instead an alternate UTType?
This is my current code:
var allowedDocumentTypes = new string[] {
UTType.RTF,
UTType.Text,
UTType.PDF,
UTType.UTF8PlainText,
UTType.RTFD,
UTType.UTF16ExternalPlainText,
UTType.UTF16PlainText,
UTType.UTF8PlainText,
UTType.FlatRTFD,
"com.microsoft.word.doc",
"com.microsoft.word.docx" // An attempt to include docx filtering.
};
var pickerMenu = new UIDocumentMenuViewController(allowedDocumentTypes, UIDocumentPickerMode.Open);
pickerMenu.DidPickDocumentPicker += (sender, args) =>
{
args.DocumentPicker.DidPickDocument += (sndr, pArgs) =>
{
var securityEnabled = pArgs.Url.StartAccessingSecurityScopedResource();
FileInfo fi = new FileInfo(pArgs.Url.Path);
var result = new SelectFileResult();
result.FilePath = fi.FullName;
result.FileName = fi.Name;
NSUrlRequest urlReq = NSUrlRequest.FromUrl(pArgs.Url);
NSUrlResponse response;
NSError error;;
var data = NSUrlConnection.SendSynchronousRequest(urlReq, out response, out error);
result.MimeType = response.MimeType;
Action onFileConsumeDone = () =>
{
pArgs.Url.StopAccessingSecurityScopedResource();
};
onFileSelected(result, onFileConsumeDone);
};
// Display the document picker
AppDelegate.TopViewController.PresentViewController(args.DocumentPicker, true, null);
};
pickerMenu.ModalPresentationStyle = UIModalPresentationStyle.Popover;
AppDelegate.TopViewController.PresentViewController(pickerMenu, true, null);
I had a shot in the dark and included the identifier com.microsoft.word.docx but it does not trigger filtering by docx.
My current solution is C# but objective-c and swift solutions accepted.
Try org.openxmlformats.wordprocessingml.document
Try
let supportedTypes: [UTType] = [UTType.content]

NetSuite SuiteTalk: Search Filter with Custom Field Type

I am pulling my hair out on this one. I am attempting to filter a saved search with a custom field of type SearchColumnSelectCustomField (see XML of record below).
How do I convert this type properly, or what am I doing wrong here?
I'm not sure what I'm missing, but the error I always eventually hit is:
"Cannot implicitly convert type
'NetSuite.com.netsuite.na1.webservices.SearchColumnSelectCustomField'
to 'NetSuite.com.netsuite.na1.webservices.SearchCustomField'
"
TransactionSearchAdvanced transSearchAdv = new TransactionSearchAdvanced
{
savedSearchScriptId = "customsearch_mycustomsearch"
};
SearchColumnSelectCustomField cwoNumField = new SearchColumnSelectCustomField();
cwoNumField.internalId = "custbody_consolidatedworkorder";
transSearchAdv.criteria = new TransactionSearch
{
basic = new TransactionSearchBasic
{
//Error Here, on cwoNumField
customFieldList = new SearchCustomField[]{ cwoNumField }
}
};
XML of search results, without filter criteria added:
<tranSales:basic xmlns:platformCommon="urn:common_2014_1.platform.webservices.netsuite.com">
<platformCommon:appliedToTransaction>
<platformCore:searchValue internalId="442671"/>
<platformCore:customLabel>SO #</platformCore:customLabel>
</platformCommon:appliedToTransaction>
<platformCommon:item>
<platformCore:searchValue internalId="315838"/>
</platformCommon:item>
<platformCommon:quantity>
<platformCore:searchValue>11.0</platformCore:searchValue>
</platformCommon:quantity>
<platformCommon:status>
<platformCore:searchValue>pendingBuild</platformCore:searchValue>
</platformCommon:status>
<platformCommon:transactionNumber>
<platformCore:searchValue>204</platformCore:searchValue>
<platformCore:customLabel>WO #</platformCore:customLabel>
</platformCommon:transactionNumber>
<platformCommon:customFieldList>
<platformCore:customField xsi:type="platformCore:SearchColumnBooleanCustomField" scriptId="custbody_buildcomplete" internalId="501">
<platformCore:searchValue>false</platformCore:searchValue>
</platformCore:customField>
/*********** field in question here *************/
<platformCore:customField xsi:type="platformCore:SearchColumnSelectCustomField" scriptId="custbody_consolidatedworkorder" internalId="500">
<platformCore:searchValue typeId="85" internalId="24"/>
<platformCore:customLabel>CWO #</platformCore:customLabel>
</platformCore:customField>
</platformCommon:customFieldList>
</tranSales:basic>
I'm not sure WHY, but this is the answer. Can someone explain why a SearchColumnSelectCustomField field is searched via SearchMultiSelectCustomField ?
TransactionSearchAdvanced transSearchAdv = new TransactionSearchAdvanced
{
savedSearchScriptId = "customsearch_woconsolidationsublist"
};
SearchMultiSelectCustomField cwoNumField = new SearchMultiSelectCustomField();
cwoNumField.scriptId = "custbody_consolidatedworkorder";
cwoNumField.#operator = SearchMultiSelectFieldOperator.anyOf;
cwoNumField.operatorSpecified = true;
cwoNumField.searchValue = new ListOrRecordRef[] { new ListOrRecordRef {internalId = "36"} };
transSearchAdv.criteria = new TransactionSearch
{
basic = new customFieldList = new SearchCustomField[] { cwoNumField }
}
};

Open XML SDK: How to get a valid Word document for WordprocessingDocument.Open

For unit testing purposes, I would like to generate some sample data to be stored as a stream in the dataToImport variable in the following statement:
WordprocessingDocument.Open(dataToImport, false);
Does anyone know how to create a decent set of sample data?
You could potentially use something like the following:
using (WordprocessingDocument wpd = WordprocessingDocument.Open(filename, false)
{
wpd.MainDocumentPart.Document.Body.Append(GenerateParagraph(...text ...);
}
private Paragraph GenerateParagraph(string input)
{
Paragraph paragraph1 = new Paragraph();
Run run1 = new Run();
Break break1 = new Break() { Type = BreakValues.Page };
Text txt = new Text() { Space = SpaceProcessingModeValues.Preserve };
txt.Text = input;
run1.Append(break1);
run1.Append(txt);
paragraph1.Append(run1);
return paragraph1;
}
The value of the ...text... itself could come from any file using FileInputStream objects.
Hope it helps!

Categories

Resources